-
Notifications
You must be signed in to change notification settings - Fork 761
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test logs get mixed across test cases #2377
Comments
why was this issue closed? was it fixed? |
@drvic10k Why do you say it was closed? It's active now, and the history on the issue doesn't suggest it was ever closed. Perhaps you were confused by the link from a closed issue that appears in this issue's history? |
@AArnott you are right, that is indeed a label from the linked issue |
Hi @AArnott, |
None that I've heard of. |
Ok, thank you. |
This bug comes because we resolve class constructor arguments once per class, so there is a shared instance of the test output helper being used for all tests in the same class: xunit/src/xunit.execution/Sdk/Frameworks/Runners/XunitTestClassRunner.cs Lines 226 to 230 in e022e5c
It gets emptied and reset between tests: xunit/src/xunit.execution/Sdk/Frameworks/Runners/XunitTestRunner.cs Lines 64 to 73 in e022e5c
By using it outside of its intended scope, you're writing to another test, since we're reusing the instance. What would you prefer be done here @AArnott?
|
I should point out that in v3 this is already fixed and it takes the "ignore" stance. |
No dispose messages anywhere (this is your test project, updated to v3) Recording.2024-06-16.150259.mp4 |
The "ignore" behavior is available in To be clear, your call to logger.WriteLine() will now be throwing, but since nobody is observing the task you spun off, the exception will be ignored (and the test will continue to pass): Recording.2024-06-16.163019.mp4 |
Great. Matching behavior between v2 and v3 seems like goodness. Between silently failing and throwing, I'd prefer throwing so that the problem will usually be discoverable sooner than when we have some other test failure and we have to search the logs only to find that they're incomplete. |
I'll add a new issue to make sure all the runners are subscribed to |
Description
dotnet test
(and Test Explorer in VS) both collect messages logged by tests to the wrong tests.I am using xunit's
ITestOutputHelper
to log messages, and yet these messages which are meant to be collected under "Standard Output" on a per-test basis are getting mixed up, which makes analyzing test failures very difficult or impossible.It seems to depend on logging taking place after the test class's DisposeAsync method completes, such that test 1 is actually logging after it allegedly finished, thus overlapping into test 2's time slice.
That said, since concurrent test execution is supported, it seems that logging is already distinguishable between concurrent tests. So why do the logs get mixed up when one test logs after its disposal?
The tested product may have async shutdown behavior that the test's DisposeAsync method cannot wait on, which is why logging happens beyond the DisposeAsync method. But I would like to capture such logs (if the test runner is still running) and associate them with the right test.
We decided this is an xunit bug rather than in the VSTest platform because we found evidence that the corruption happens within
![image](https://user-images.githubusercontent.com/3548/132761719-190b4882-95de-4367-9340-981d62fe53ba.png)
Xunit.Sdk.TestOutputHelper
, and by the time the xunit.runner.visualstudio library hands off to the VS Test platform with the test result, the corruption has already occurred.Steps to reproduce
Take this minimal repro:
TestProject1.zip
Open the
console.trx
file in VS.Go through each of the 5 tests to look at their logged messages.
Each message is prefixed with a unique test ID (and elapsed time) to record which test invocation it came from.
Expected behavior
Each of the tests have their own logged messages. This would manifest as each message starting with the same number as every other line.
Actual behavior
I see some test logs include multiple of these unique ID prefixes:
![image](https://user-images.githubusercontent.com/3548/132740977-bceeb69f-0bbf-4067-a7b1-39c4b1e9eb51.png)
It also reproduces when tests are run in Test Explorer:
![image](https://user-images.githubusercontent.com/3548/132741020-25a90aef-2e2f-47ea-9467-887a90d2c878.png)
Diagnostic logs
logs.zip
Environment
Windows
.NET SDK 5.0.400
The text was updated successfully, but these errors were encountered: