-
Notifications
You must be signed in to change notification settings - Fork 291
Fix AssemblyCleanup running when not all class cleanups might have finished #7173
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
Conversation
nohwnd
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comments in code.
src/Adapter/MSTestAdapter.PlatformServices/Execution/UnitTestRunner.cs
Outdated
Show resolved
Hide resolved
test/IntegrationTests/MSTest.Acceptance.IntegrationTests/AssemblyCleanupTests.cs
Show resolved
Hide resolved
src/Adapter/MSTestAdapter.PlatformServices/Execution/UnitTestRunner.cs
Outdated
Show resolved
Hide resolved
…unner.cs Co-authored-by: Jakub Jareš <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes issue #7120 where AssemblyCleanup could run prematurely before all class cleanups had completed in parallel test execution scenarios. The fix introduces a two-stage completion tracking mechanism: marking individual tests as complete, and separately marking entire test classes as complete only after their cleanup methods finish.
Changes:
- Introduced
MarkClassCompletemethod to track when a test class has finished all cleanups - Modified
MarkTestCompleteto only indicate when the last test in a class completes, not trigger cleanup - Updated
RunClassCleanupAsyncto remove cleanup manager logic and focus on executing cleanup - Ensured assembly cleanup runs only after all classes are marked complete
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| ClassCleanupManager.cs | Added MarkClassComplete method and refactored MarkTestComplete to return isLastTestInClass flag; removed cleanup execution logic |
| TestClassInfo.cs | Simplified RunClassCleanupAsync signature by removing ClassCleanupManager and TestMethodInfo parameters and associated logic |
| UnitTestRunner.cs | Updated to call MarkClassComplete after class cleanup finishes; checks ShouldRunEndOfAssemblyCleanup before running assembly cleanup |
| UnitTestRunnerTests.cs | Refactored tests to create UnitTestRunner instances per test instead of sharing a field; added helper method CreateUnitTestRunner |
| ClassCleanupManagerTests.cs | Updated test to use new MarkClassComplete API and removed dependency on TestMethodInfo |
| AssemblyCleanupTests.cs | Added new integration test verifying assembly cleanup waits for parallel class cleanups with sleep delays |
Fixes #7120
After every test method completes, we marked it as completed.
Then after every class cleanup, we called
RunAssemblyCleanupIfNeededAsync, which will check if all tests have been executed, and runs assembly cleanup. This is wrong because all tests could have been executed, but there are remaining class cleanups running in parallel.This PR updates the logic so we have the concept of "marking test as completed" and "marking test class as completed". Previously we only had the former concept.