VS UnitTest - thread was aborted

I have a Unit test suite in parallel (this is important, it works fine if tests are run single-threaded), which makes WebClient calls to load a resource that takes 30 seconds to return in succession, and this will cause Unit Test to force quit with one of the following two messages:

The topic is interrupted.

The user domain in which the thread was running was unloaded.

I tried to set the [Timeout] attribute, various app.config settings, including even creating an EventWaitHandle to wait for a Unit Test stream in a WebClient stream, with no luck. I checked the test timeout settings in the Test Settings section, and it is set to the default value of 30 minutes.


Edit 2:

As @peer pointed out, this is a known bug in the VS.Net test platform: http://connect.microsoft.com/VisualStudio/feedback/details/587390/threadabortexception-when-running-two-tests-in-parallel-one-taking -40-seconds

Edit:

Here is the simplest scenario that will reproduce the problem. Can you do these unit tests, and if so, how? These tests must be run in parallel! Launch a new Visual Studio Unit Test project and use the following settings and test method code. When you start, make sure that they actually work in parallel (i.e. you need a processor with several cores and check that they work at the same time. I found that to start them in parallel, I have to apply all the settings, then close the project and again open it before the parallelization procedure is applied).

Local.testsettings (add parallelTestCount="#" , whatever applies to your processor):

 <Description>These are default test settings for a local test run.</Description> <Deployment enabled="false" /> <Execution parallelTestCount="4"> <TestTypeSpecific /> <AgentRule name="Execution Agents"> </AgentRule> </Execution> 

TraceAndTestImpact.testsettings (comment out DataCollectors ):

 <Description>These are test settings for Trace and Test Impact.</Description> <Execution parallelTestCount="0"> <TestTypeSpecific /> <AgentRule name="Execution Agents"> <!--<DataCollectors> <DataCollector uri="datacollector://microsoft/SystemInfo/1.0" assemblyQualifiedName="Microsoft.VisualStudio.TestTools.DataCollection.SystemInfo.SystemInfoDataCollector, Microsoft.VisualStudio.TestTools.DataCollection.SystemInfo, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" friendlyName="System Information"> </DataCollector> <DataCollector uri="datacollector://microsoft/HttpProxy/1.0" assemblyQualifiedName="Microsoft.VisualStudio.TraceCollector.HttpProxyCollector, Microsoft.VisualStudio.TraceCollector, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" friendlyName="ASP.NET Client Proxy for IntelliTrace and Test Impact"> </DataCollector> <DataCollector uri="datacollector://microsoft/TestImpact/1.0" assemblyQualifiedName="Microsoft.VisualStudio.TraceCollector.TestImpactDataCollector, Microsoft.VisualStudio.TraceCollector, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" friendlyName="Test Impact"> </DataCollector> <DataCollector uri="datacollector://microsoft/TraceDebugger/1.0" assemblyQualifiedName="Microsoft.VisualStudio.TraceCollector.TraceDebuggerDataCollector, Microsoft.VisualStudio.TraceCollector, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" friendlyName="IntelliTrace"> </DataCollector> </DataCollectors>--> </AgentRule> </Execution> 

UnitTest1.cs (first unit test, sleeps 35 seconds):

 [TestMethod] public void TestMethod1() { Thread.Sleep(35000); // in default unit test settings, this line will never be reached Console.WriteLine("TestMethod1"); } 

UnitTest2.cs (second unit test, sleeps 35 seconds):

 [TestMethod] public void TestMethod2() { Thread.Sleep(35000); // in default unit test settings, this line will never be reached Console.WriteLine("TestMethod2"); } 

If you have the correct parallelization set up, you will find that both tests fail, with ThreadAbortException , with one of the two messages presented at the top. How can I say that these methods work longer than 30 seconds?

+6
source share
3 answers

You should go to the menu: Test โ†’ Edit Test Setting โ†’ current test config

Go to the tab: Testing timeouts

Change the timeout at any time.

+3
source

Perhaps your test settings are configured with a timeout?

enter image description here

+1
source

I also got this with a multithreaded test.

The test passed to approval before work on the task was completed. The approval failed, and test posting interrupted the task.

I added a wait loop until the task is complete and everything works like a charm.

-Chris

0
source

Source: https://habr.com/ru/post/891741/


All Articles