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

Notification

Icon
Error

static variables inside classes
tofutim
#1 Posted : Monday, August 27, 2012 6:05:25 PM(UTC)
Rank: Member

Groups: Registered
Joined: 8/27/2012(UTC)
Posts: 19
Location: California

Thanks: 2 times
Was thanked: 2 time(s) in 2 post(s)
Hi, I recently ran into an issue using NCrunch where static variables for the class are shared across multiple tests when running in parallel - even tests that are in different files.

For example, I have a class with

public static bool logFile

When the application starts, it is supposed to assign the logFile, and this is shared across all class instances. However, if I have two tests running, even with different logFile names, the logFile will be assigned by just one of the tests.

Is there anyway to compartmentalize the tests so that static is not shared? How do others handle this?
Remco
#2 Posted : Monday, August 27, 2012 9:04:21 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,987

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
Hi, thanks for posting!

NCrunch will never, ever, ever run multiple tests in parallel within the same execution process. It really is physically impossible with the current design. Based on your description, I think it could be worth checking the following:

- Make sure that the log file name is completely different (i.e. randomly generated) for every test that is executed. It isn't enough to use a sequence counter in generating the file name - try using a Guid or something you can be sure will be 100% unique per test run.
- Make sure that the static variable causing the problem is not somehow sequence dependent, and that it is being definitively assigned at the beginning of the execution of each individual test.
- Make sure you don't have background threads that may be manipulating or making use of the static variable. An example of this could be a test that kicks off a thread to do some work which continues to happen after the test has finished execution on the primary thread - as this could cause the background thread to clash with any tests that are subsequently running later in the test run.

I hope this helps!


Cheers,

Remco
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.030 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download