Fix AssemblyCleanup running when not all class cleanups might have finished#7173
Merged
Youssef1313 merged 7 commits intomainfrom Jan 12, 2026
Merged
Fix AssemblyCleanup running when not all class cleanups might have finished#7173Youssef1313 merged 7 commits intomainfrom
Youssef1313 merged 7 commits intomainfrom
Conversation
nohwnd
reviewed
Jan 8, 2026
src/Adapter/MSTestAdapter.PlatformServices/Execution/UnitTestRunner.cs
Outdated
Show resolved
Hide resolved
test/IntegrationTests/MSTest.Acceptance.IntegrationTests/AssemblyCleanupTests.cs
Show resolved
Hide resolved
nohwnd
reviewed
Jan 12, 2026
src/Adapter/MSTestAdapter.PlatformServices/Execution/UnitTestRunner.cs
Outdated
Show resolved
Hide resolved
nohwnd
reviewed
Jan 12, 2026
…unner.cs Co-authored-by: Jakub Jareš <me@jakubjares.com>
nohwnd
approved these changes
Jan 12, 2026
Contributor
There was a problem hiding this comment.
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 |
test/IntegrationTests/MSTest.Acceptance.IntegrationTests/AssemblyCleanupTests.cs
Show resolved
Hide resolved
test/IntegrationTests/MSTest.Acceptance.IntegrationTests/AssemblyCleanupTests.cs
Show resolved
Hide resolved
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.