Repository navigation
Enable safe parallelization for task test projects - #55992
Merged
Merged
Conversation
Run the audited task test projects at class-level parallel scope and serialize classes that mutate process-wide current directory or environment state. Co-authored-by: Copilot App <[email protected]>
|
Azure Pipelines: Successfully started running 1 pipeline(s). 2 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
Copilot review overview
Review tier: Lite
Findings: None
What changed in this PR
This PR enables conservative MSTest class-level parallel execution for several task-focused test projects, and adds targeted serialization via [ResourceLock] for tests that mutate process-global state (current directory / environment variables) to keep parallel runs isolated.
Changes:
- Enable
MSTestParallelizeScope=ClassLevelin four MSTest test projects. - Add
[ResourceLock(WellKnownResources.CurrentDirectory)]to test classes that callDirectory.SetCurrentDirectory(...). - Serialize the publish environment-variable test with
[ResourceLock(WellKnownResources.EnvironmentVariables)]and restore the original value viatry/finally.
| File | Description |
|---|---|
| test/sdk-tasks.Tests/sdk-tasks.Tests.csproj | Opt into MSTest class-level parallelization. |
| test/Microsoft.NET.Sdk.Publish.Tasks.Tests/Microsoft.NET.Sdk.Publish.Tasks.Tests.csproj | Opt into MSTest class-level parallelization. |
| test/Microsoft.NET.Sdk.Publish.Tasks.Tests/EnvironmentHelperTests.cs | Serialize env-var mutation and restore original value reliably. |
| test/Microsoft.NET.Build.Tasks.Tests/Microsoft.NET.Build.Tasks.Tests.csproj | Switch from assembly-serial execution to class-level parallelization. |
| test/Microsoft.NET.Build.Tasks.Tests/GivenTasksUseAbsolutePaths.cs | Serialize CWD-mutating test class via WellKnownResources.CurrentDirectory. |
| test/Microsoft.NET.Build.Tasks.Tests/GivenAWriteAppConfigWithSupportedRuntimeMultiThreading.cs | Serialize CWD-mutating test class via resource lock. |
| test/Microsoft.NET.Build.Tasks.Tests/GivenATaskEnvironmentDefault.cs | Serialize CWD-mutating test class via resource lock. |
| test/Microsoft.NET.Build.Tasks.Tests/GivenAResolveRuntimePackAssetsTask.cs | Serialize CWD-mutating test class via resource lock. |
| test/Microsoft.NET.Build.Tasks.Tests/GivenAResolvePackageFileConflictsMultiThreading.cs | Serialize CWD-mutating test class via resource lock. |
| test/Microsoft.NET.Build.Tasks.Tests/GivenAResolvePackageAssetsMultiThreading.cs | Serialize CWD-mutating test class via resource lock. |
| test/Microsoft.NET.Build.Tasks.Tests/GivenAResolveAppHostsMultiThreading.cs | Serialize CWD-mutating test class via resource lock. |
| test/Microsoft.NET.Build.Tasks.Tests/GivenAPickBestRidMultiThreading.cs | Serialize CWD-mutating test class via resource lock. |
| test/Microsoft.NET.Build.Tasks.Tests/GivenAGetPackagesToPrune.cs | Serialize CWD-mutating test class via resource lock. |
| test/Microsoft.NET.Build.Tasks.Tests/GivenAGenerateRuntimeConfigMultiThreading.cs | Serialize CWD-mutating test class via resource lock. |
| test/Microsoft.NET.Build.Tasks.Tests/GivenAGenerateDepsFileMultiThreading.cs | Serialize CWD-mutating test class via resource lock. |
| test/Microsoft.NET.Build.Tasks.Tests/GivenAGenerateClsidMapMultiThreading.cs | Serialize CWD-mutating test class via resource lock. |
| test/Microsoft.NET.Build.Tasks.Tests/GivenAGenerateBundleMultiThreading.cs | Serialize CWD-mutating test class via resource lock. |
| test/Microsoft.NET.Build.Tasks.Tests/GivenACheckForUnsupportedWinMDReferencesMultiThreading.cs | Serialize CWD-mutating test class via resource lock. |
| test/Microsoft.NET.Build.Extensions.Tasks.Tests/Microsoft.NET.Build.Extensions.Tasks.Tests.csproj | Opt into MSTest class-level parallelization. |
| test/Microsoft.NET.Build.Extensions.Tasks.Tests/GivenAGetDependsOnNETStandardMultiThreading.cs | Serialize CWD-mutating test class via resource lock. |
Member
Author
Local before/after benchmarkPartial local gain confirmed on my Windows machine using the SDK repo test runner.
Comparable clean total: 1m 22.3s before -> 49.682s after (32.578s saved, 39.6%).
Single local run; timings can vary with machine load, but this gives a direct before/after signal on this machine. |
JeremyKuhne
approved these changes
Sep 9, 2026
Evangelink
enabled auto-merge (squash)
September 9, 2026 05:41
Run CWD-mutating classes in MSTest's serial tail so they cannot affect unannotated tests that read relative paths. Resolve dependency-context baseline files from the test assembly directory as an additional safeguard. Co-authored-by: Copilot App <[email protected]>
Member
Author
|
/azp run |
|
Azure Pipelines: Successfully started running 2 pipeline(s). 2 pipeline(s) were filtered out due to trigger conditions. |
JeremyKuhne
approved these changes
Sep 9, 2026
Evangelink
had a problem deploying
to
copilot-pat-pool
September 9, 2026 19:47 — with
GitHub Actions
Failure
This branch had an error being deployed
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.
These task-focused MSTest projects currently run serially even though most test classes do not share mutable state. Enabling conservative class-level parallelism should reduce execution time while preserving isolation for process-global resources.
Changes
ClassLevelparallelization in four task test projects.[DoNotParallelize], preventing them from affecting unannotated tests that read relative paths.WellKnownResources.EnvironmentVariablesand restore its original value from afinallyblock.Testing
Microsoft.NET.Build.Tasks.Tests: 355 passed, 0 failed with 32 class-level workers.GivenADependencyContextBuilderandGivenAGenerateDepsFilePathResolutionrun: 27 passed, 0 failed.Local before/after benchmark
Partial local gain confirmed on Windows using the SDK repository test runner. Comparable clean total: 1m 22.3s before -> 49.682s after (32.578s saved, 39.6%).