There is a lot of information on how to unit test threaded code but not on spawning threads inside a unit test method to test synchronization mechanisms.
[TestMethod]
public void TestDiscountThreading() {
Thread[] threads = new Thread[50];
for (int i = 0; i < threads.Length; i++) {
threads[i] = new Thread(PriceThread);
threads[i].Start();
}
for (int i = 0; i < threads.Length; i++)
threads[i].Join();
}
I want to stresstest if synchronization in the code inside PriceThread is implemented correctly but every single time the method runs I get the error "The agent process was stopped while the test was running". Is it even possible to spawn threads inside unit tests or what can be wrong here?
Im using Visual Studio 2010 with the shipped unit testing framework