Skip to content

Enable safe parallelization for task test projects - #55992

Open
Evangelink wants to merge 1 commit into
mainfrom
dev/amauryleve/build-task-parallel-audit
Open

Enable safe parallelization for task test projects#55992
Evangelink wants to merge 1 commit into
mainfrom
dev/amauryleve/build-task-parallel-audit

Conversation

@Evangelink

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 the small set of process-global resources.

Changes

  • Enable ClassLevel parallelization in four task test projects.
  • Serialize all classes that change the process current directory with WellKnownResources.CurrentDirectory.
  • Serialize the publish environment-variable test 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.

No DoNotParallelize exclusions are needed because the resource locks cover the complete affected class lifecycle without blocking unrelated classes.

Testing

Local test and benchmark runs were intentionally deferred so the parallelization changes can be measured together in one consolidated 10-run baseline and changed fleet benchmark.

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 <223556219+Copilot@users.noreply.github.com>
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants