Fix concurrent modification in MetricsCollection#15581
Merged
nohwnd merged 2 commits intomicrosoft:mainfrom Mar 26, 2026
Merged
Fix concurrent modification in MetricsCollection#15581nohwnd merged 2 commits intomicrosoft:mainfrom
nohwnd merged 2 commits intomicrosoft:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses concurrency issues in telemetry metrics collection by switching to a thread-safe dictionary implementation, and also disables the EnableShutdownAfterTestRun API (marking it obsolete with a compile-time error) and removes its remaining usage/tests.
Changes:
- Replace
DictionarywithConcurrentDictionaryinMetricsCollectionto prevent concurrent modification exceptions. - Mark
EnableShutdownAfterTestRunas[Obsolete(..., error: true)]across the interface and implementations, and stop reading it during runs. - Remove unit tests and code paths that depended on
EnableShutdownAfterTestRun.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Adapter/FrameworkHandleTests.cs | Removes tests covering EnableShutdownAfterTestRun (now made obsolete with error). |
| src/Microsoft.TestPlatform.ObjectModel/Adapter/Interfaces/IFrameworkHandle.cs | Marks EnableShutdownAfterTestRun obsolete (error) at the public interface level. |
| src/Microsoft.TestPlatform.CrossPlatEngine/Execution/BaseRunTests.cs | Removes runtime read of EnableShutdownAfterTestRun during test execution. |
| src/Microsoft.TestPlatform.CrossPlatEngine/Adapter/FrameworkHandle.cs | Marks the EnableShutdownAfterTestRun implementation obsolete (error). |
| src/Microsoft.TestPlatform.Common/Telemetry/MetricsCollection.cs | Switches internal storage to ConcurrentDictionary for thread-safe metric writes. |
| src/Microsoft.TestPlatform.Common/ExtensionDecorators/SerialTestRunDecoratorFrameworkHandle.cs | Marks decorator property EnableShutdownAfterTestRun obsolete (error). |
| src/Microsoft.TestPlatform.Common/ExtensionDecorators/SerialTestRunDecorator.cs | Marks decorator property EnableShutdownAfterTestRun obsolete (error). |
src/Microsoft.TestPlatform.ObjectModel/Adapter/Interfaces/IFrameworkHandle.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.TestPlatform.ObjectModel/Adapter/Interfaces/IFrameworkHandle.cs
Show resolved
Hide resolved
…ent modification MetricsCollection.Add is called from multiple threads during parallel test execution with data collectors. Using Dictionary causes InvalidOperationException when concurrent updates corrupt the state. Added regression test that exercises concurrent Add from 10 threads. Closes microsoft#15579 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
ConcurrentDictionary is not a subclass of Dictionary, so Moq's It.Is<Dictionary<...>> type check fails. Use IDictionary<...> which matches both Dictionary and ConcurrentDictionary. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Member
Author
|
FAils on hangdump flakiness and the issue with default diag |
This was referenced Mar 27, 2026
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.
Use \ConcurrentDictionary\ instead of \Dictionary\ in \MetricsCollection\ to prevent \InvalidOperationException\ when metrics are added concurrently during parallel test execution with data collectors.
Closes #15579
Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com