It seems that NCrunch runs unit tests on an STA thread by default. This causes unit test failures where the code under test (or the unit test code for that matter) relies on WaitAll().
Is there a way to configure the threading model used for test threads?
Thanks
James.
Remco NCrunch Developer
#1419
12 Mar 2012 20:28 UTC
Hi James,
The behaviour for this is likely to be test runner specific, as test runners will often implement different behaviour in this area underneath NCrunch's integration points. Which framework are you having problems with?
One way that comes to my mind would be to spawn your own thread inside the test and specifically flag it as MTA. Though I would also prefer to fix this properly..
Cheers,
Remco
The behaviour for this is likely to be test runner specific, as test runners will often implement different behaviour in this area underneath NCrunch's integration points. Which framework are you having problems with?
One way that comes to my mind would be to spawn your own thread inside the test and specifically flag it as MTA. Though I would also prefer to fix this properly..
Cheers,
Remco
The tests are written against NUnit. The tests pass when run from the NUnit UI, Resharper and NUnit console.
Remco NCrunch Developer
#1421
12 Mar 2012 21:23 UTC
Thanks, I'll do some further testing around here and will see if I can get it sorted for the next release.
Here's a repo, in case it helps. This test will fail in NCrunch, but works elsewhere (eg. Resharper, other continuous testing tools):
[Test]
public void TryWaitAll()
{
Func<TimeSpan, ManualResetEvent> runThread = t =>
{
var mre = new ManualResetEvent(false);
var thread = new Thread(() =>
{
Thread.Sleep(t);
mre.Set();
});
thread.Start();
return mre;
};
WaitHandle.WaitAll(
new WaitHandle[]
{
runThread(TimeSpan.FromSeconds(1)),
runThread(TimeSpan.FromSeconds(2)),
});
}
Edited 15 Mar 2012 09:51 UTC
Post a reply
Log in to reply.