-
Notifications
You must be signed in to change notification settings - Fork 264
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
tests fail intermittently when run in parallell #1053
Comments
FWIW the same behaviour can be reproduced on a 2.2.9 preview version:
|
A work-around for the issue seems to be to force the initialization of the unprotected collection before tests start running in parallell: https://github.com/krijohan/BugRepro1/pull/1/files#diff-1fb3d50c7b48fae266c651acc227133823af0bf272f14ab3a601dd68121dd84aR12 |
krijohan
added a commit
to krijohan/testfx
that referenced
this issue
Mar 17, 2022
Address thread-safety issue microsoft#1053 by initializing the static field StackTraceHelper.typesToBeExcluded statically instead of on demand.
Haplois
pushed a commit
that referenced
this issue
Apr 21, 2022
Address thread-safety issue #1053 by initializing the static field StackTraceHelper.typesToBeExcluded statically instead of on demand.
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
Description
When running
dotnet test
in a project with[assembly: Parallelize(Workers = 4, Scope = ExecutionScope.ClassLevel)]
, you will occasionally get unwarranted test failures from InvalidOperationException / "Collection was modified; enumeration operation may not execute". This makes the feature of running tests in parallell not very useful, unless you are willing to accept flaky tests.While not clear from the stack trace in the resulting test failure, debugging indicates that the exception originates from https://github.com/microsoft/testfx/blob/rel/2.2.8/src/Adapter/MSTest.CoreAdapter/Execution/StackTraceHelper.cs#L239, where there is a
foreach
on astatic List<string>
member.Steps to reproduce
dotnet test
over and over again until it fails, e.g. by running the included script repro.ps1 in powershell. On my laptop this takes about 5 minutes.Expected behavior
dotnet test
never fails (as the included test cases are always passed or skipped)Actual behavior
Eventually, one of the skipped test cases will fail with
The error message hides the real issue. Attaching a debugger to
dotnet test
and adding a breakpoint on InvalidOperationException , the below stack trace suggests the exception originates from https://github.com/microsoft/testfx/blob/rel/2.2.8/src/Adapter/MSTest.CoreAdapter/Execution/StackTraceHelper.cs#L239, where there is aforeach
on astatic List<string>
member.Debugger stack trace:
Environment
https://github.com/krijohan/BugRepro1/blob/main/BugRepro1/BugRepro1.csproj
My laptop runs Windows 11 Pro Version 21H2.
The text was updated successfully, but these errors were encountered: