Build/Test Issues

DomainUnload is not fired/class finalizers not executed on test runner host exit

Started by liudas on 5,089 views

Hi,
I need to execute clean up code to free external resources after all test are executed. NCrunch handles AssemblyInitialize/AssemblyCleanup differently from mstest runner. As advised in Test Runner Re-use documentation part I introduced bool flag to avoid multiple long running Initialization calls. When test host exits (or is killed) no AppDomain.CurrentDomain.DomainUnload and AppDomain.CurrentDomain.ProcessExit events are fired nor class Finalizers are executed.
Hi, thanks for posting!

NCrunch doesn't have a mechanism for executing clean up code on termination of a test runner process, for the simple reason that no cleanup scenario can ever be 100% reliable in a way that NCrunch can control. There are many situations that can result in test runner processes being suddenly terminated - ranging from those caused by code under test (i.e. stack overflows, out of memory exceptions) through to external factors (i.e. interference from other processes/applications). While such situations are rare when tests are deliberately executed serially with other test runners, the high level of concurrency and continuous execution performed by NCrunch make such scenarios much more likely.

To execute cleanup code using NCrunch, you will need to use try/finally structures around the tests involved. Depending on the nature of the resources involved, you may also be able to look into other options such as structuring tests to clean up when they begin executing (i.e. mopping up after the last test run).

Post a reply

Log in to reply.