Testing MVC Controller hangs in HierarchicalTestFrameworkContextResolver.CreateAttributeMatcher.AnonymousMethod__26

12 posts, 0 answers
  1. Bill
    Bill avatar
    13 posts
    Member since:
    Apr 2014

    Posted 24 Jul 2014 Link to this post

    I'm using JustMock to mock out the HttpContext when testing an ASP.Net MVC  controller, below are snapshots of  the stack when I pause the execution:


     Telerik.JustMock.dll!Telerik.JustMock.Core.Context.HierarchicalTestFrameworkContextResolver.CreateAttributeMatcher.AnonymousMethod__26 Normal
      [External Code]  
      XXXXXXXX.Web.Application.dll!XXXXXXXX.Web.Application.Controllers.TransportController.Index() Line 44  
      XXXXXXXX.Tests.dll!XXXXXXTests.Transport.TransportControllerTests.IndexPageTest() Line 36  
      [External Code]  

    Telerik.JustMock.dll!Telerik.JustMock.Core.Context.HierarchicalTestFrameworkContextResolver.FindTestMethod Normal
      [External Code]  
    XXXXXXXX.Web.Application.dll!XXXXXXXX.Web.Application.Controllers.TransportController.Index() Line 44  
      XXXXXXXX.Tests.dll!XXXXXXXX.Tests.Transport.TransportControllerTests.IndexPageTest() Line 36  
      [External Code]  
  2. Stefan
    Admin
    Stefan avatar
    198 posts

    Posted 24 Jul 2014 Link to this post

    Hi Bill,

    Could you double-check that the test really hangs and is not just running excessively slowly? Please, check the CPU usage of the test runner while the test is running and get back to me.

    If the test is maxing the CPU, then it's just running slowly, but should eventually finish. It is also possible that the particular set of arrangements you've made could be causing the to run in an endless loop. A minimal repro project would be really helpful to determine whether that's the case.

    Either way, given these stack traces, I think it's impossible for the test runner to just hang there.

    Regards,
    Stefan
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. DevCraft R3 2016 release webinar banner
  4. Bill
    Bill avatar
    13 posts
    Member since:
    Apr 2014

    Posted 24 Jul 2014 in reply to Stefan Link to this post

    Hi Stefan,

    First thanks for the quick response. Secondly you are right, it's just slow. It took 23 minutes for the test to run, that's unacceptable. If I can find the time, I try to hobble together a minimal repro project to see if there are similar performance issues.

    thanks.
    bill
  5. Bill
    Bill avatar
    13 posts
    Member since:
    Apr 2014

    Posted 24 Jul 2014 in reply to Stefan Link to this post

    Hi Stefan,

    First thanks for the quick response.

    Secondly, you're correct the process was just running slow, very slow. It took 23 minutes to run one test against a MVC Controller method, this is unacceptable. If I get the bandwidth, I'll try to cobble together a minimal reproduction project to see if it suffers similar performance woes.

    Thanks

    bill
  6. Stefan
    Admin
    Stefan avatar
    198 posts

    Posted 28 Jul 2014 Link to this post

    Hi Bill,

    Keep us posted with the performance results of your tests. Normally, the JustMock profiler slows down test execution by a factor of approximately 2.5x

    Regards,
    Stefan
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  7. Bill
    Bill avatar
    13 posts
    Member since:
    Apr 2014

    Posted 31 Jul 2014 in reply to Stefan Link to this post

    Hello Stefan,

    I ran the test under JustTrace for about an hour, if I'm reading the profiler correctly, the test is spending a large amount of time in ProfilerInterceptor.Interrcept when called by Linq.Queryable.Count, does that sound right? I've  attached a screen shot.

    -bill
  8. Stefan
    Admin
    Stefan avatar
    198 posts

    Posted 01 Aug 2014 Link to this post

    Hello Bill,

    It appears that your test intercepts some very common method (47k intercepted invocations).

    The number of calls to Count() and to Intercept() is disproportionate. It appears that a method in between the two visible calls is the culprit. Unfilter the Queryable.Count() node and check which is the call just before the Intercept call.

    Regards,

    Stefan
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  9. Bill
    Bill avatar
    13 posts
    Member since:
    Apr 2014

    Posted 01 Aug 2014 Link to this post

    Hi Stefan,

    Here is my Mock setup, is there a way to control what's Intercepted? 

    Mock.SetupStatic(typeof(UserProfileProvider), StaticConstructor.Mocked);
    var userProfile = Mock.Create<Aramark.ISIS.Web.Application.Core.Providers.UserProfileProvider>();
    Mock.Arrange(() => userProfile.Metrics).Returns(MetricProfiles());
    Mock.Arrange(() => UserProfileProvider.GetUserProfile(Arg.IsAny<string>())).Returns((string x) => userProfile);

    var httpResponse = Mock.Create<HttpResponse>();
    var httpRequest = Mock.Create<HttpRequest>(Constructor.Mocked);
    httpContext = Mock.Create<HttpContext>(Constructor.Mocked);
    var contextCache = Mock.Create<System.Web.Caching.Cache>(Constructor.Mocked);

    var httpResponseBase = Mock.Create<HttpResponseBase>();
    var httpRequestBase = Mock.Create<HttpRequestBase>(Constructor.Mocked);
    httpContextBase = Mock.Create<HttpContextBase>(Constructor.Mocked);

    var user = Mock.Create<IPrincipal>();
    var identity = Mock.Create<IIdentity>();

    Mock.Arrange(() => contextCache.Get(Arg.IsAny<string>())).Returns((string x) => null);

    Mock.Arrange(() => httpRequest.IsAuthenticated).Returns(true);
    Mock.Arrange(() => httpContext.Request).Returns(httpRequest);
    Mock.Arrange(() => httpContext.Response).Returns(httpResponse);
    Mock.Arrange(() => httpContext.Cache).Returns(contextCache);
    Mock.Arrange(() => httpContext.User).Returns(user);
    Mock.Arrange(() => user.Identity).Returns(identity);
    Mock.Arrange(() => identity.IsAuthenticated).Returns(true);
    Mock.Arrange(() => identity.Name).Returns("csc");

    Mock.Arrange(() => HttpContext.Current).Returns(httpContext);

    Mock.Arrange(() => httpRequestBase.IsAuthenticated).Returns(true);
    Mock.Arrange(() => httpContextBase.Request).Returns(httpRequestBase);
    Mock.Arrange(() => httpContextBase.Response).Returns(httpResponseBase);
    Mock.Arrange(() => httpContextBase.User).Returns(user);
  10. Bill
    Bill avatar
    13 posts
    Member since:
    Apr 2014

    Posted 01 Aug 2014 in reply to Bill Link to this post

    W00T!

    I think the problem is solved! I added "Behavior.Loose" as a parameter to all the Mock.Create calls and now the test runs in 4 secs!



  11. Stefan
    Admin
    Stefan avatar
    198 posts

    Posted 04 Aug 2014 Link to this post

    Hello Bill,

    I'm glad that you've got the issue resolved. Still, for further reference I'd like to ask you to have a look at the profile that you took a few days ago and show me which is the method being intercepted so many times and in what context. It will further help us fine tune the interception process. If it is OK with you, I would like to ask you to send us the profile so that we can also investigate the underlying issue on our side. It is completely unexpected that the default RecursiveLoose behavior is penalizing the runtime performance so much.

    Thank you for your time.

    Regards,
    Stefan
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  12. Bill
    Bill avatar
    13 posts
    Member since:
    Apr 2014

    Posted 05 Aug 2014 in reply to Stefan Link to this post

    Hello Stefan,

    Send me an email address to send the profile.

    bill
  13. Stefan
    Admin
    Stefan avatar
    198 posts

    Posted 06 Aug 2014 Link to this post

    Hello Bill,

    Please attach the profile to the ticket. That should be the easiest method for you. If that doesn't work then send the profile to JustMockPublicFeedback@telerik.com

    Regards,
    Stefan
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful Butt services to develop web, hybrid and native mobile apps.

     
Back to Top
DevCraft R3 2016 release webinar banner