Skip to content

Enable safe parallelization for task test projects - #55992

Merged
Evangelink merged 2 commits into
mainfrom
dev/amauryleve/build-task-parallel-audit
Sep 9, 2026
Merged

Evangelink merged 2 commits into
mainfrom
dev/amauryleve/build-task-parallel-audit

Conversation

@Evangelink

@Evangelink Evangelink commented Aug 28, 2026 •

Copy link
Copy Markdown
Member

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

  • Enable ClassLevel parallelization in four task test projects.
  • Run classes that change the process current directory in MSTest's serial tail with [DoNotParallelize], preventing them from affecting unannotated tests that read relative paths.
  • Resolve dependency-context test baselines from the test assembly directory instead of the process current directory.
  • Serialize the publish environment-variable test with WellKnownResources.EnvironmentVariables and restore its original value from a finally block.
  • Keep tests within each class sequential, avoiding races in class-private fixtures and static test data.

Testing

  • Microsoft.NET.Build.Tasks.Tests: 355 passed, 0 failed with 32 class-level workers.
  • Focused GivenADependencyContextBuilder and GivenAGenerateDepsFilePathResolution run: 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%).

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]>
Copilot AI lite review requested due to automatic review settings August 28, 2026 15:20
@Evangelink
Evangelink requested a review from vijayrkn as a code owner August 28, 2026 15:20
@azure-pipelines

Copy link
Copy Markdown
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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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=ClassLevel in four MSTest test projects.
  • Add [ResourceLock(WellKnownResources.CurrentDirectory)] to test classes that call Directory.SetCurrentDirectory(...).
  • Serialize the publish environment-variable test with [ResourceLock(WellKnownResources.EnvironmentVariables)] and restore the original value via try/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.

@Evangelink

Copy link
Copy Markdown
Member Author

Local before/after benchmark

Partial local gain confirmed on my Windows machine using the SDK repo test runner.

  • Machine: Microsoft Windows 11 Enterprise, AMD RYZEN AI MAX+ 395 w/ Radeon 8060S , 32 logical processors
  • Baseline: origin/main (890dd7f)
  • PR head: dev/amauryleve/build-task-parallel-audit (b0ebdf4)
  • Command shape: .\.dotnet\dotnet.exe scripts\RunTests.cs -- --project <project>
  • Reported numbers use the test run duration from the runner output; build/setup wall-clock is excluded.

Comparable clean total: 1m 22.3s before -> 49.682s after (32.578s saved, 39.6%).

Project Before After Delta Result
Microsoft.NET.Build.Extensions.Tasks.Tests 0.403s 0.379s 0.024s passed
Microsoft.NET.Build.Tasks.Tests 4.308s failed n/a head failed: missing generated .deps.json temp file
Microsoft.NET.Sdk.Publish.Tasks.Tests 1m 21.2s 48.661s 32.524s passed
sdk-tasks.Tests 0.672s 0.642s 0.03s passed

Single local run; timings can vary with machine load, but this gives a direct before/after signal on this machine.

@Evangelink
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]>
@Evangelink

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).
2 pipeline(s) were filtered out due to trigger conditions.

@Evangelink
Evangelink merged commit 1e3cd5a into main Sep 9, 2026
32 checks passed
@Evangelink
Evangelink deleted the dev/amauryleve/build-task-parallel-audit branch September 9, 2026 19:46
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Sep 10, 2026

This branch had an error being deployed

1 failed deployment
copilot-pat-pool — 3d7f4e2e Deployed Sep 9, 2026 by Evangelink via pre_activation #3815
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants