What causes vstest to hang after executing all tests successfully

963 views Asked by At

We are using the Visual Studio test framework and C# to write unit tests, and we recently ran into a problem where vstest.console.exe sometimes hangs after executing all the tests. All tests pass, but then vstest.console.exe just sits there forever waiting for something, instead of exiting.

This is likely related to recent changes where we started using a third party library. When running the tests in debug, we can see that multiple threads created by that library are still hanging around after all tests have already passed.

To understand the problem better, I tried to reproduce the issue as shown in the test code below. However, it seems that vstest.console.exe is perfectly happy to exit after completing a test like this. It doesn't seem to care about any "wild" threads that are still running. So my question is this: what is causing vstest to wait or not wait for threads after executing all tests? In other words, how should I modify the test below to make vstest hang after completing it?

[TestMethod]
public void FreezeVSTest()
{
    var thread = new Thread(
        new ThreadStart(
            delegate
            {
                while (true)
                {
                    Thread.Sleep(1);
                }
            }));
    thread.Start();
}

(Note that I'm not asking how to make the test hang, I know that adding a thread.Join() would achieve that. The question is about vstest itself hanging after the test passes.)

0

There are 0 answers