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

Notification

Icon
Error

Isolated attribute not always respected
GreenMoose
#1 Posted : Tuesday, April 18, 2017 10:19:54 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 6/17/2012(UTC)
Posts: 507

Thanks: 145 times
Was thanked: 66 time(s) in 64 post(s)
[v3.7.0.4]
I use IsolatedAttribute on fixture level to ensure my tests are all running inside same process (I use a login routine once during setup, which I don't want to redo more than once for all tests), but it seems every other run it runs the 2 tests in 2 different projects?

Repro:
Quote:

[TestFixture]
[Isolated]
internal class FooFixture
{
private static int _foo;
private static readonly object _fooLock=new object();

[SetUp]
public void FooFixtureSetUp()
{
lock (_fooLock)
{
if (_foo == 0)
_foo = 1;
else
Assert.Fail("Foo was 1.");
}
}
[Test]
public void Test1()
{
}[Test]
public void Test2()
{
}
}


Pin Test1 and Test2, hide all other tests, select "run all tests visible here" command. For me every other time there is 1 red and 1 green test (expected), and every other run 2 green (not expected). I notice that when I get the unexpected result NCrunch starts 2 TestHost test runners simultaneously.

Bonus question: Can I somehow keep this "isolated" test runner active, so I can reuse it if running tests with "run covering tests in existing project" ?

Thanks.

*Edit: This was probably wrong approach overall, I changed this to use a local cookies cache instead so it doesn't matter which test runner is used.
Remco
#2 Posted : Wednesday, April 19, 2017 11:30:00 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)
Hi, thanks for posting.

The Isolated attribute basically marks a test or fixture as being run in isolation. When this is applied to a fixture, tests within the fixture are considered to be 'Isolated by fixture', which means that they CAN be run in the same process, but there is no code that explicitly requires them to do so. This means that if you have two tests isolated under the same fixture, you can be sure that they will always be run in isolation, but they may still run in different processes.

I think what you're after here is an 'Atomic' fixture rather than an isolated one. 'Atomic' fixtures are flagged so that all tests within the fixture must be run together and cannot be separated. This is quite an important concept internally for NCrunch, as certain situations (such as execution of MSpec tests) do require it. There have always been plans for NCrunch.Framework.AtomicAttribute so that users would have the capability to mark these out where they're needed. So far, I just haven't quite gotten around to implementing it yet. I think it's a useful concept and it would cleanly handle situations like the one you've just described.
1 user thanked Remco for this useful post.
GreenMoose on 4/20/2017(UTC)
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.029 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download