Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Is out of process nature of run failing my test?
sammicrosoft
#1 Posted : Thursday, March 24, 2016 10:48:37 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 3/24/2016(UTC)
Posts: 2
Location: United States of America

Hi,

After installing NCrunch, bunch of my existing MSTest tests failed. Upon investigation, I found most of the test failed as the value of Thread.CurrentPrincipal.Identity.Name in the below product code is getting set to empty whereas it is set to correct value in domain\alias format when run under MSTest. As the default value for ownerAlias is empty, username becomes empty and hit the exception in the next line.

var username = String.IsNullOrWhiteSpace(ownerAlias) ? Thread.CurrentPrincipal.Identity.Name : ownerAlias;
var xx = Thread.CurrentPrincipal.Identity.Name; // This is to verify the value
ExceptionUtility.ThrowIfArgumentNullOrEmpty(username, "Could not find current username.");



Wondering, if this is because NCrunch uses its own process to run the test, so doesn't have a valid CurrentPrincipal value!

I have tried changing the property "Engine hosting strategy = HostInsideIDE (the default was x64SatelliteProcess)" under configuration with no success.

Has anyone encountered similar issue before and any suggestion on how to tackle this?

Appreciate your help.
Remco
#2 Posted : Friday, March 25, 2016 12:20:36 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,161

Thanks: 964 times
Was thanked: 1296 time(s) in 1202 post(s)
Hi, thanks for sharing this issue.

NCrunch's support for MSTest is emulated (not integrated), so it's basically running the tests using it's own adapter. Through trial and error, the adapter has become quite closely aligned with the normal runtime behaviour of MSTest. But there are still edge cases where we have differences.

My guess would be that in this specific case, MSTest is deliberately setting the CurrentPrincipal on the thread, or it is otherwise being set indirectly by the framework.

I would need to investigate in detail before I could tell you whether it's possible for NCrunch to implement this kind of behaviour, but for the time being I would recommend finding an abstraction or hook-point that will let you work without it. Perhaps setting the property deliberately inside an AssemblyInitialize could do the trick? (assuming you have access to do this) - NCrunch will run AssemblyInitialize on the same thread as it runs the test.
sammicrosoft
#3 Posted : Friday, March 25, 2016 1:36:25 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 3/24/2016(UTC)
Posts: 2
Location: United States of America

Thanks Remco. To be specific, our unit tests are written in Visual Studio UnitTesting framework. The test that is failing due to the reason stated before is part of product code, not test code. The same test passes when running from Visual Studio or MSTest. Sorry for not being clear. Thread.CurrentPrincipal should be set automatically for the current user context ((- BROKEN LINK -). So, I was wondering if the code, when run under NCrunch behaves differently from how it supposed to be.
Remco
#4 Posted : Friday, March 25, 2016 12:12:44 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,161

Thanks: 964 times
Was thanked: 1296 time(s) in 1202 post(s)
Sorry, I don't think I explained this very well.

MSTest is doing something that sets this property on the current thread by default. This is either done deliberately in MSTest, or somehow indirectly.

NCrunch doesn't actually run MSTest. It uses a custom built adapter designed to behave as close as possible to MSTest. NCrunch's adapter does not contain any code to deliberately set this property in the same way as MSTest. If the behaviour of MSTest is clear in this case and I can find a way to feasibly reproduce it in NCrunch, I will. Until then, as the property is being used by your production code, I suggest setting it deliberately to the expected value inside your test code. This should allow your production code to work around NCrunch's compatibility hole.
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.032 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download