This is a migrated thread and some comments may be shown as answers.

Testing MVC Controller hangs in HierarchicalTestFrameworkContextResolver.CreateAttributeMatcher.AnonymousMethod__26

11 Answers 111 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Bill
Top achievements
Rank 1
Bill asked on 24 Jul 2014, 01:20 PM
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]  

11 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 24 Jul 2014, 02:45 PM
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.

 
0
Bill
Top achievements
Rank 1
answered on 24 Jul 2014, 04:19 PM
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
0
Bill
Top achievements
Rank 1
answered on 24 Jul 2014, 04:23 PM
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
0
Stefan
Telerik team
answered on 28 Jul 2014, 03:32 PM
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.

 
0
Bill
Top achievements
Rank 1
answered on 31 Jul 2014, 05:57 PM
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
0
Stefan
Telerik team
answered on 01 Aug 2014, 06:37 AM

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.

 
0
Bill
Top achievements
Rank 1
answered on 01 Aug 2014, 01:41 PM
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);
0
Bill
Top achievements
Rank 1
answered on 01 Aug 2014, 02:05 PM
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!



0
Stefan
Telerik team
answered on 04 Aug 2014, 06:51 AM
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.

 
0
Bill
Top achievements
Rank 1
answered on 05 Aug 2014, 01:57 PM
Hello Stefan,

Send me an email address to send the profile.

bill
0
Stefan
Telerik team
answered on 06 Aug 2014, 06:55 AM
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.

 
Tags
General Discussions
Asked by
Bill
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Bill
Top achievements
Rank 1
Share this question
or