Build/Test Issues

Issues with NUnit async tests and SerialAttribute

Started by chillitom on 5,803 views

Hi There,

Seeing strange behaviour and think it can only be explained by NUnit async tests not obeying the Serial attribute (Both class and methods marked with the attribute).

Could someone outline the intended behaviour in this case? My expectation is that the task should run to completion before another begins.

Thanks, T.
Hi, thanks for sharing this issue.

NUnit itself handles this under the hood (NCrunch doesn't call into the tests directly), but my understanding is that an async test should always be run to completion before the next one starts.

Note that this doesn't necessarily provide cover for other threads that are kicked off during the test run. If you have a test (async or otherwise) that launches another task and then returns before this task is complete, neither NCrunch or NUnit will know about the background thread in order to wait for it. This thread can then freely interfere with subsequent test runs in the process.

If adjusting your code to cater for such a scenario is too difficult (i.e. you can't get access to the Task management from the test code), using the IsolatedAttribute would probably solve this for you as NCrunch would just clean up the process and avoid re-using it. There will be some loss of performance involved in re-spawning the process after the test completes.
Quick follow-up to say that Isolated worked as you suggested and led us to find an error in our code. Thanks for your help.

Post a reply

Log in to reply.