Repository navigation
[ResourceLock] Replace [DoNotParallelize] with [ResourceLock] in MSBuildCompatibilityHelperTests - #11808
Merged
Amaury Levé (Evangelink) merged 1 commit intoOct 8, 2026
Conversation
…yHelperTests MSBuildCompatibilityHelperTests mutates MSBuildCompatibilityHelper's process-wide static caches (s_msBuildVersion, s_supportsMultiline, s_supportsTerminalLoggerWithExtendedMessages) via reflection and through its public API. No other test class in the assembly calls MSBuildCompatibilityHelper, so a class-level [ResourceLock] on a dedicated const key fully covers the resource while letting this class run concurrently with the rest of the assembly instead of being deferred to the sequential tail by the previous [DoNotParallelize]. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The lock covers the shared-cache tests while preserving concurrency with unrelated tests.
0 open findings
What changed in this PR
Narrows synchronization in the MSBuild unit tests so unrelated tests can run concurrently while shared caches remain protected.
Changes:
- Replaces class-level
[DoNotParallelize]with[ResourceLock]. - Adds a named lock key and documents its coverage.
| File | Description |
|---|---|
| test/UnitTests/Microsoft.Testing.Platform.MSBuild.UnitTests/MSBuildCompatibilityHelperTests.cs | Uses a dedicated resource lock to serialize cache-accessing tests. |
🧠 Review effort: Balanced
Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.
Amaury Levé (Evangelink)
marked this pull request as ready for review
October 8, 2026 07:18
Amaury Levé (Evangelink)
approved these changes
Oct 8, 2026
Amaury Levé (Evangelink)
merged commit Oct 8, 2026
3c59d77
into
microsoft:main
11 of 12 checks passed
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.
Replaces the class-level
[DoNotParallelize]onMSBuildCompatibilityHelperTests(intest/UnitTests/Microsoft.Testing.Platform.MSBuild.UnitTests, which already runs with[assembly: Parallelize(Scope = ExecutionScope.MethodLevel, Workers = 0)]) with a class-level[ResourceLock]on a dedicated custom key.Current parallelization scope.
Microsoft.Testing.Platform.MSBuild.UnitTestsis already opted intoMethodLevelparallelism viaProgram.cs. The[DoNotParallelize]onMSBuildCompatibilityHelperTestspreviously pulled every test in the class out of the parallel set into the sequential tail.Shared resource.
MSBuildCompatibilityHelper's three process-wide static caches:s_msBuildVersion,s_supportsMultiline,s_supportsTerminalLoggerWithExtendedMessages(src/Platform/Microsoft.Testing.Platform.MSBuild/Tasks/MSBuildCompatibilityHelper.cs).Resource coverage matrix:
MSBuildCompatibilityHelperstatic cachesMSBuildCompatibilityHelperTests: 2 callSupportsMultiLine()/SupportsTerminalLoggerWithExtendedMessages()directly (lazily populating the caches), 2 use theWithMSBuildVersionhelper which replaces the backing fields via reflection, 2 callTryWriteExtendedMessage()(one viaWithMSBuildVersion)InvokeTestingPlatformTask.HandleRequestAsync(src/Platform/Microsoft.Testing.Platform.MSBuild/Tasks/InvokeTestingPlatformTask.Execution.cs) callsSupportsMultiLine(),SupportsTerminalLoggerWithExtendedMessages(), andTryWriteExtendedMessage()MSBuildCompatibilityHelpercall sites: the only references outside the production file are the 6 tests insideMSBuildCompatibilityHelperTests.csitself.InvokeTestingPlatformTaskTests.csandMSBuildTests.csin the same assembly instantiate other MSBuild tasks (InvokeTestingPlatformTaskis only ever constructed, never drivingHandleRequestAsync's named-pipe request handling;TestingPlatformEntryPointTask/ConfigurationFileTaskare unrelated types) and never reachMSBuildCompatibilityHelper[ResourceLock(MSBuildCompatibilityHelperCacheResource)], whereMSBuildCompatibilityHelperCacheResourceis a newprivate const stringon the test class, per the repo convention of never using a bare string literal keyBecause no other concurrently-runnable test in the assembly reaches
MSBuildCompatibilityHelper, the class-level lock is both necessary (the 6 tests mutate/read a shared static cache and must not interleave with each other) and sufficient (nothing else in the assembly can observe or race on that cache) — while being strictly narrower than the previous assembly-tail[DoNotParallelize]deferral, since the class can now run concurrently with the rest of the assembly instead of being pulled into the sequential phase.Why not eliminate the shared state instead? The caches are internal implementation details of
MSBuildCompatibilityHelper(a productioninternal static class); rewriting it to avoid static caching is out of scope for this bounded refactoring, and[ResourceLock]is the documented fix for exactly this "process-global state that must be coordinated" category per the shared parallel-safety-audit guidance (category A).Validation:
bash ./build.sh -projects $(pwd)/test/UnitTests/Microsoft.Testing.Platform.MSBuild.UnitTests/Microsoft.Testing.Platform.MSBuild.UnitTests.csproj— build succeeded (0 errors).PATH="$PWD/.dotnet:$PATH" dotnet exec artifacts/bin/Microsoft.Testing.Platform.MSBuild.UnitTests/Debug/net9.0/Microsoft.Testing.Platform.MSBuild.UnitTests.dll --filter "FullyQualifiedName~MSBuildCompatibilityHelperTests"— 10/10 passed, run 3 times in a row to check for new flakiness from the removed[DoNotParallelize], no failures.PATH="$PWD/.dotnet:$PATH" dotnet exec artifacts/bin/Microsoft.Testing.Platform.MSBuild.UnitTests/Debug/net9.0/Microsoft.Testing.Platform.MSBuild.UnitTests.dll(full assembly,MethodLevel/4 workers) — 229 passed, 1 skipped (pre-existing, OS-specific, unrelated to this change), 0 failed.Declaration-reconciliation self-review (category C): the lock's key is private to this test class (not reused elsewhere), so no key-mismatch/near-miss risk; the lock covers every production reader/writer of the resource (not just the one API the changed test calls); the sole observers in the assembly are the 6 tests on this class, all now under the same lock, so there is no concurrent interleaving that can race on the caches with the replacement declaration in place.
No assembly-level
[Parallelize]/[DoNotParallelize],MSTestParallelizeScope/MSTestParallelizeWorkers,.runsettings, ortestconfig.jsonparallelization settings were added or changed — only the class-level attribute onMSBuildCompatibilityHelperTests.gh-aw-workflow-id: resource-lock-refactoring
Warning
Firewall blocked 74 domains
The following domains were blocked by the firewall during workflow execution:
0t3vsblobprodcus362.vsblob.vsassets.io11vvsblobprodcus336.vsblob.vsassets.io1k9vsblobprodcus379.vsblob.vsassets.io1s1vsblobprodcus386.vsblob.vsassets.io37bvsblobprodcus311.vsblob.vsassets.io37cvsblobprodcus359.vsblob.vsassets.io4m6vsblobprodcus384.vsblob.vsassets.io4vyvsblobprodcus361.vsblob.vsassets.io4zjvsblobprodcus390.vsblob.vsassets.io51yvsblobprodcus36.vsblob.vsassets.io5dkvsblobprodcus355.vsblob.vsassets.io5rqvsblobprodcus385.vsblob.vsassets.io7k6vsblobprodcus337.vsblob.vsassets.io7tjvsblobprodcus341.vsblob.vsassets.io80zvsblobprodcus35.vsblob.vsassets.io8xbvsblobprodcus382.vsblob.vsassets.io96bvsblobprodcus338.vsblob.vsassets.ioajhvsblobprodcus363.vsblob.vsassets.iobcnvsblobprodcus378.vsblob.vsassets.iobuilds.dotnet.microsoft.comc78vsblobprodcus322.vsblob.vsassets.iocflvsblobprodcus383.vsblob.vsassets.ioci.dot.netckzvsblobprodcus347.vsblob.vsassets.iod0svsblobprodcus381.vsblob.vsassets.iodata.nuget.orgdlbvsblobprodcus316.vsblob.vsassets.ioe7bvsblobprodcus348.vsblob.vsassets.iofdpvsblobprodcus345.vsblob.vsassets.iofrdvsblobprodcus327.vsblob.vsassets.iogbsvsblobprodcus365.vsblob.vsassets.ioh6tvsblobprodcus346.vsblob.vsassets.ioi1qvsblobprodcus353.vsblob.vsassets.ioimzvsblobprodcus368.vsblob.vsassets.iojd4vsblobprodcus366.vsblob.vsassets.iojosvsblobprodcus372.vsblob.vsassets.iojrqvsblobprodcus343.vsblob.vsassets.iok0ivsblobprodcus356.vsblob.vsassets.iok4kvsblobprodcus344.vsblob.vsassets.iokgfvsblobprodcus314.vsblob.vsassets.iokijvsblobprodcus387.vsblob.vsassets.iokxqvsblobprodcus376.vsblob.vsassets.iol49vsblobprodcus358.vsblob.vsassets.iol7avsblobprodcus319.vsblob.vsassets.ioljcvsblobprodcus317.vsblob.vsassets.iolylvsblobprodcus31.vsblob.vsassets.iom16vsblobprodcus374.vsblob.vsassets.iom6xvsblobprodcus342.vsblob.vsassets.iomfjvsblobprodcus373.vsblob.vsassets.ion3kvsblobprodcus335.vsblob.vsassets.ioo3svsblobprodcus318.vsblob.vsassets.ioofvvsblobprodcus315.vsblob.vsassets.iopc2vsblobprodcus360.vsblob.vsassets.iopdfvsblobprodcus380.vsblob.vsassets.iope3vsblobprodcus354.vsblob.vsassets.iopkgs.dev.azure.comrcxvsblobprodcus328.vsblob.vsassets.ios8mvsblobprodcus38.vsblob.vsassets.iose1vsblobprodcus349.vsblob.vsassets.iosouthcentralus0.in.applicationinsights.azure.comsqdvsblobprodcus333.vsblob.vsassets.iost8vsblobprodcus339.vsblob.vsassets.iotphvsblobprodcus375.vsblob.vsassets.iou3hvsblobprodcus371.vsblob.vsassets.iou6ovsblobprodcus377.vsblob.vsassets.ioukkvsblobprodcus352.vsblob.vsassets.iouy6vsblobprodcus34.vsblob.vsassets.iov53vsblobprodcus320.vsblob.vsassets.iovb4vsblobprodcus33.vsblob.vsassets.iovwvvsblobprodcus334.vsblob.vsassets.iox3yvsblobprodcus370.vsblob.vsassets.ioxupvsblobprodcus332.vsblob.vsassets.ioyluvsblobprodcus367.vsblob.vsassets.ioyttvsblobprodcus357.vsblob.vsassets.ioTo allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.