You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Some unit tests have the test host crash when run on a Linux machine, but not on Windows
Steps to reproduce
On a Debian 10 machine (also reproduced in WSL or with the Docker file supplied in the same repo as below):
git clone https://github.com/odalet/mstest-test
cd mstest-test
dotnet test MSTestTest.sln
Expected behavior
The test should 'gracefully' fail
Actual behavior
When on Linux, the test has the host process crash with this message:
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
The active test run was aborted. Reason: Test host process crashed : Unhandled exception. System.Exception: TEST
at MSTestTest.UnitTests.<>c__DisplayClass0_0.<Repro>b__0() in /root/mstest-test/UnitTests.cs:line 20
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location where exception was thrown ---
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
Test Run Aborted.
But running the same test on Windows produces the expected result:
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
Failed Repro [24 ms]
Error Message:
Assert.IsTrue failed.
Stack Trace:
at MSTestTest.UnitTests.Repro() in C:\work\repositories\_odalet\mstest-test\UnitTests.cs:line 31
It's obviously wrong but models what I suppose happens in my real unit tests. What has the test host crash is, I think, the fact that the thread keeps running after the test method ends, then throws, and this exception is not caught by the Linux version of the test engine.
At first I thought this bug was v2.2-specific because on my CI (that builds using a Debian based docker), reverting to v2.1.2 has my tests pass...
But then, with the simple repro I crafted, I consistently crash on Linux, be it with v2.2 or v2.1 of MSTest nugets.
I suppose that different versions incur different timings and that may explain why, in my real tests, the race condition that crashes in v2.2 simply does not occur in v2.1
Environment
Debian 10
Installed .NET SDK: 5.0.301 (but also has .NET Core 3.1 runtime)
but also reproduced in a container using mcr.microsoft.com/dotnet/sdk:3.1.410-buster
MSTest: 2.2.5-preview-20210605-01 (but also reproduced with v2.1.2)
The text was updated successfully, but these errors were encountered:
Thanks for reporting this issue and sorry it took so much time to review it!
Your reproducer is not totally right and currently it's working mainly because the lambda is not yet triggered by the time you reach the assertion on Windows while it is on Linux.. By updating the repro as such:
Thanks for your reply. Indeed, with your repro I end up with a similar crash in Linux and Windows (at least this is consistent!)
I updated my repro repo with your version of the test and also upgraded nugets to the current latest versions. That is:
Description
Some unit tests have the test host crash when run on a Linux machine, but not on Windows
Steps to reproduce
Expected behavior
Actual behavior
Remarks
I reproduced the issue with this code:
It's obviously wrong but models what I suppose happens in my real unit tests. What has the test host crash is, I think, the fact that the thread keeps running after the test method ends, then throws, and this exception is not caught by the Linux version of the test engine.
Environment
The text was updated successfully, but these errors were encountered: