Repository navigation
Parallelize core SDK and CLI tests - #56036
Evangelink merged 7 commits into
Conversation
Co-authored-by: Copilot App <[email protected]>
|
Azure Pipelines: Successfully started running 2 pipeline(s). 1 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
🔍 Build Failure AnalysisSummary — All 10 build legs failed identically at Root cause: Raising
|
| Code | Project | File:Line | Message |
|---|---|---|---|
MSTEST0075 |
dotnet.Tests |
RunParserTests.cs:47 |
Directory.SetCurrentDirectory mutates process-global state; no [ResourceLock]/[DoNotParallelize] |
MSTEST0075 |
dotnet.Tests |
RunParserTests.cs:63,79,94,110,126,145,161,179,196,211 |
same root cause |
MSTEST0074 |
dotnet.Tests |
TestCommandParserTests.cs:133,139,147 |
Environment.SetEnvironmentVariable mutates process-global state; no [ResourceLock]/[DoNotParallelize] |
🤖 Generated by the Build Failure Analysis workflow using (a href="(dev.azure.com/redacted) · commit 722e4da
🤖 Automated content by GitHub Copilot. Generated by the Build Failure Analysis workflow. · auto · 170.3 AIC · ⌖ 1.92 AIC · ⊞ 7.1K · [◷]( · ◷)
Transfer process-global state protections into the slice that enables dotnet.Tests parallelism, so it builds and runs independently. Co-authored-by: Copilot App <[email protected]> Copilot-Session: a4ec0e90-6d52-4abd-aa3f-0805ec56797f
The dotnet.Tests parallelism opt-in and these analyzer-required locks now live together in dotnet#56036. Co-authored-by: Copilot App <[email protected]> Copilot-Session: b626e1af-2a85-4181-9294-76d18d1515bc
Preserve the reviewer-approved explanation when moving RunParser test ownership into the core SDK parallelization slice. Co-authored-by: Copilot App <[email protected]> Copilot-Session: a4ec0e90-6d52-4abd-aa3f-0805ec56797f
Initialize the SDK test context from the MSTest base class and serialize context publication so parallel classes cannot observe incomplete process hooks. Co-authored-by: Copilot App <[email protected]> Copilot-Session: a4ec0e90-6d52-4abd-aa3f-0805ec56797f
Use an injectable TimeProvider for TestRunPolicy so active-time accounting can be tested without scheduler-sensitive delays under parallel test load. Co-authored-by: Copilot App <[email protected]> Copilot-Session: a4ec0e90-6d52-4abd-aa3f-0805ec56797f
|
Azure Pipelines: Successfully started running 2 pipeline(s). 1 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
CI triage for
|
| Check | Classification | Evidence |
|---|---|---|
dotnet-sdk-public-ci (Build Monitor Helix Jobs) |
pre-existing | Only failing job in the build. Failing Helix work items: Microsoft.DotNet.ApiCompat.IntegrationTests.dll, Microsoft.DotNet.GenAPI.IntegrationTests.dll, Microsoft.TemplateEngine.Authoring.Tasks.IntegrationTests.dll (exit code 2, failureCategory: InfrastructureError). |
dotnet-sdk-public-ci |
pre-existing | Roll-up of the job above; every other leg succeeded. |
Build Analysis |
pre-existing | Roll-up of the same AzDO build; reported knownIssues: [], unmatched failures are just Failed work item information: / Bash exited with code '1'. |
Root cause: setup commands in those three integration-test assemblies cannot restore the .NET 11 reference packs, e.g.
error NU1101: Unable to find package Microsoft.NETCore.App.Ref. No packages exist with this id in source(s): testPackages0, testPackages1
error NU1100: Unable to resolve 'Microsoft.NETCore.App.Ref (= 11.0.0-preview.7.26381.103)' for 'net11.0'
Already tracked by #56057.
Why this is not caused by this PR:
- The identical three work items fail on
refs/heads/mainin build 1575758 (queued 23:47 UTC, before this PR's build) and build 1575987. - None of those three test projects are touched by this PR, and they still inherit the default
MSTestParallelizeScope=Nonefromtest/Directory.Build.props(only the comment changed there). - Every failed test in this build belongs to one of those three assemblies — 19 on Linux x64, 19 on Windows x64, 19 on Mac arm64, 32 on Windows x64 FullFramework. Zero failures in the projects this PR parallelizes (~16k tests per leg).
Action: re-run only. A rerun of the same merge commit is already in flight as build 1576236; it will keep failing the same way until #56057 is resolved on main.
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
Review tier: Lite
Findings: 1
New issues introduced by this change (1)
| Severity | Finding |
|---|---|
test/Microsoft.NET.TestFramework/SdkTestContext.cs — SdkTestContext.Current now takes s_initializationLock on every access. With test assemblies… |
What changed in this PR
This PR enables audited MSTest parallelization (ClassLevel/MethodLevel) across core SDK + CLI test assemblies, and hardens shared-process/global state usage (CWD, environment variables, static state, timers) so eligible tests can safely run concurrently.
Changes:
- Opts selected test projects into
MSTestParallelizeScope(ClassLevel/MethodLevel), keeping known-serial assemblies atNone. - Adds targeted
[DoNotParallelize]/[ResourceLock]annotations and restores/isolates shared resources (CWD, env vars, process-wide servers, static timeouts). - Makes
TestRunPolicytime deterministic for tests via optionalTimeProvider+ manual test provider, reducing scheduler sensitivity.
| File | Description |
|---|---|
| test/trustedroots.Tests/trustedroots.Tests.csproj | Enables MethodLevel parallelization for trustedroots tests. |
| test/System.CommandLine.StaticCompletions.Tests/System.CommandLine.StaticCompletions.Tests.csproj | Enables ClassLevel parallelization for static completions tests. |
| test/sdk-tasks.Tests/sdk-tasks.Tests.csproj | Enables ClassLevel parallelization for sdk-tasks tests. |
| test/msbuild.Integration.Tests/msbuild.Integration.Tests.csproj | Enables MethodLevel parallelization for MSBuild integration tests. |
| test/Microsoft.Win32.Msi.Tests/Microsoft.Win32.Msi.Tests.csproj | Enables MethodLevel parallelization for MSI-related tests. |
| test/Microsoft.WebTools.AspireService.Tests/Microsoft.WebTools.AspireService.Tests.csproj | Enables ClassLevel parallelization (per-class serial) for Aspire service tests. |
| test/Microsoft.NET.ToolPack.Tests/Microsoft.NET.ToolPack.Tests.csproj | Enables ClassLevel parallelization for ToolPack tests. |
| test/Microsoft.NET.TestFramework/SdkTestContext.cs | Adds synchronization around SdkTestContext.Current initialization/updates. |
| test/Microsoft.NET.TestFramework.MSTest/SdkTest.cs | Forces SdkTestContext initialization from MSTest base constructor. |
| test/Microsoft.NET.Sdk.Web.Tests/Microsoft.NET.Sdk.Web.Tests.csproj | Enables ClassLevel parallelization for Web SDK tests. |
| test/Microsoft.NET.Rebuild.Tests/Microsoft.NET.Rebuild.Tests.csproj | Enables MethodLevel parallelization for Rebuild tests. |
| test/Microsoft.NET.Infrastructure.Tests/Microsoft.NET.Infrastructure.Tests.csproj | Enables ClassLevel parallelization for infrastructure tests. |
| test/Microsoft.NET.Clean.Tests/Microsoft.NET.Clean.Tests.csproj | Enables MethodLevel parallelization for Clean tests. |
| test/Microsoft.NET.Build.Tasks.Tests/Microsoft.NET.Build.Tasks.Tests.csproj | Switches Build.Tasks tests from fully-serialized to ClassLevel parallelization. |
| test/Microsoft.NET.Build.Tasks.Tests/GivenTasksUseAbsolutePaths.cs | Marks a CWD-sensitive class as non-parallelizable. |
| test/Microsoft.NET.Build.Tasks.Tests/GivenAWriteAppConfigWithSupportedRuntimeMultiThreading.cs | Marks class as non-parallelizable. |
| test/Microsoft.NET.Build.Tasks.Tests/GivenATaskEnvironmentDefault.cs | Marks class as non-parallelizable. |
| test/Microsoft.NET.Build.Tasks.Tests/GivenAResolveRuntimePackAssetsTask.cs | Marks class as non-parallelizable. |
| test/Microsoft.NET.Build.Tasks.Tests/GivenAResolvePackageFileConflictsMultiThreading.cs | Marks class as non-parallelizable. |
| test/Microsoft.NET.Build.Tasks.Tests/GivenAResolvePackageAssetsMultiThreading.cs | Marks class as non-parallelizable. |
| test/Microsoft.NET.Build.Tasks.Tests/GivenAResolveAppHostsMultiThreading.cs | Marks class as non-parallelizable. |
| test/Microsoft.NET.Build.Tasks.Tests/GivenAPickBestRidMultiThreading.cs | Marks class as non-parallelizable. |
| test/Microsoft.NET.Build.Tasks.Tests/GivenAGetPackagesToPrune.cs | Marks class as non-parallelizable. |
| test/Microsoft.NET.Build.Tasks.Tests/GivenAGenerateRuntimeConfigMultiThreading.cs | Marks class as non-parallelizable. |
| test/Microsoft.NET.Build.Tasks.Tests/GivenAGenerateDepsFileMultiThreading.cs | Marks class as non-parallelizable. |
| test/Microsoft.NET.Build.Tasks.Tests/GivenAGenerateClsidMapMultiThreading.cs | Marks class as non-parallelizable. |
| test/Microsoft.NET.Build.Tasks.Tests/GivenAGenerateBundleMultiThreading.cs | Marks class as non-parallelizable. |
| test/Microsoft.NET.Build.Tasks.Tests/GivenACheckForUnsupportedWinMDReferencesMultiThreading.cs | Marks class as non-parallelizable. |
| test/Microsoft.NET.Build.Extensions.Tasks.Tests/Microsoft.NET.Build.Extensions.Tasks.Tests.csproj | Enables ClassLevel parallelization for Build.Extensions tests. |
| test/Microsoft.NET.Build.Extensions.Tasks.Tests/GivenAGetDependsOnNETStandardMultiThreading.cs | Marks class as non-parallelizable. |
| test/Microsoft.Extensions.DotNetDeltaApplier.Tests/Microsoft.Extensions.DotNetDeltaApplier.Tests.csproj | Enables ClassLevel parallelization for delta applier tests. |
| test/Microsoft.Extensions.DotNetDeltaApplier.Tests/HotReloadAgentTest.cs | Adds env-var resource lock to a Hot Reload env var test. |
| test/Microsoft.DotNet.TemplateLocator.Tests/Microsoft.DotNet.TemplateLocator.Tests.csproj | Enables MethodLevel parallelization for TemplateLocator tests. |
| test/Microsoft.DotNet.PackageInstall.Tests/ToolPackageDownloaderTests.cs | Marks PATH/global package mutation fixture as non-parallelizable. |
| test/Microsoft.DotNet.PackageInstall.Tests/NuGetPackageDownloaderFactoryTests.cs | Marks env-var-sensitive test method as non-parallelizable. |
| test/Microsoft.DotNet.PackageInstall.Tests/Microsoft.DotNet.PackageInstall.Tests.csproj | Enables ClassLevel parallelization for PackageInstall tests. |
| test/Microsoft.DotNet.PackageInstall.Tests/EndToEndToolTests.cs | Marks shared tool-builder cache tests as non-parallelizable. |
| test/Microsoft.DotNet.MSBuildSdkResolver.Tests/Microsoft.DotNet.MSBuildSdkResolver.Tests.csproj | Enables ClassLevel parallelization for MSBuildSdkResolver tests. |
| test/Microsoft.DotNet.Cli.Telemetry.Tests/Microsoft.DotNet.Cli.Telemetry.Tests.csproj | Enables ClassLevel parallelization for CLI telemetry tests. |
| test/dotnet.Tests/TelemetryTests/TelemetryHostMatrixTests.cs | Marks build-server matrix test class as non-parallelizable. |
| test/dotnet.Tests/TelemetryTests/TelemetryCommonPropertiesTests.cs | Adds env-var resource locks and restores original env values after mutation. |
| test/dotnet.Tests/TelemetryTests/TelemetryClientTests.cs | Marks process-wide telemetry/static-state tests as non-parallelizable. |
| test/dotnet.Tests/ProjectTools/LaunchSettingsParserTests.cs | Adds env-var resource lock + ClassCleanup to restore static env vars. |
| test/dotnet.Tests/ParserTests/CommonOptionsTests.cs | Marks parser tests as non-parallelizable due to inherited env state. |
| test/dotnet.Tests/GivenParserDirectives.cs | Avoids process CWD coupling by using per-test directory + working dir. |
| test/dotnet.Tests/dotnet.Tests.csproj | Switches dotnet.Tests to ClassLevel parallelization. |
| test/dotnet.Tests/ConfigurerTests/GivenADotnetFirstTimeUseConfigurerWIthStateSetup.cs | Marks telemetry-static-state tests as non-parallelizable. |
| test/dotnet.Tests/CommandTests/Tool/Install/ToolInstallCommandTests.cs | Adds DoNotParallelize to an ignored, CWD-sensitive test method. |
| test/dotnet.Tests/CommandTests/Test/TestRunPolicyTests.cs | Uses manual time provider to make timeout test deterministic; adds helper. |
| test/dotnet.Tests/CommandTests/Test/TestCommandParserTests.cs | Adds env-var resource locks to feature-flag/env dependent tests. |
| test/dotnet.Tests/CommandTests/Run/RunParserTests.cs | Marks CWD-mutating parser tests as non-parallelizable. |
| test/dotnet.Tests/CommandTests/Reference/Add/GivenDotnetAddReference.cs | Uses per-test directory + working dir to avoid process CWD coupling. |
| test/dotnet.Tests/CommandTests/New/SdkInfoProviderTests.cs | Adds env-var resource lock for DOTNET_ROOT-based behavior. |
| test/dotnet.Tests/CommandTests/MSBuild/GivenMSBuildLogger.cs | Marks ActivitySource-listener tests as non-parallelizable. |
| test/dotnet.Tests/CommandTests/MSBuild/GivenMsbuildForwardingApp.cs | Adjusts env-var locking for an env-var-sensitive DataRow test. |
| test/dotnet.Tests/CommandTests/MSBuild/GivenDotnetVsTestForwardingApp.cs | Makes env var restore accurate; marks env-var test as non-parallelizable. |
| test/dotnet.Tests/CommandTests/MSBuild/GivenDotnetRunInvocation.cs | Marks CWD-sensitive invocation tests as non-parallelizable. |
| test/dotnet.Tests/CommandTests/MSBuild/GivenDotnetBuildInvocation.cs | Adds env-var lock and restores original LLM env values after mutation. |
| test/dotnet.Tests/CommandTests/MSBuild/DotnetMsbuildInProcTests.cs | Marks telemetry-static-state tests as non-parallelizable. |
| test/dotnet.Tests/CommandTests/Hidden/Complete/CompleteCommandTests.cs | Restores process-wide timeout + isolates CWD; marks tests non-parallelizable. |
| test/dotnet.Tests/CommandFactoryTests/GivenAProjectDependencyCommandResolver.cs | Adds env-var lock + per-test MSBUILD_EXE_PATH save/restore. |
| test/dotnet-MsiInstallation.Tests/dotnet-MsiInstallation.Tests.csproj | Keeps MSTest parallelization disabled (serial) with updated rationale comment. |
| test/dotnet-aot.Tests/SdkForwardingAppTests.cs | Adds resource locks for SDK dir scope + env vars. |
| test/dotnet-aot.Tests/NativeEntryPointTests.cs | Adds multiple resource locks and restores additional static/global state. |
| test/dotnet-aot.Tests/MSBuildEvaluationTests.cs | Adds SDK directory scope lock. |
| test/dotnet-aot.Tests/FormatForwardingAppTests.cs | Adds SDK directory scope lock. |
| test/dotnet-aot.Tests/FileBasedAppRunPlanTests.cs | Adds reporter lock to serialize shared reporter usage. |
| test/dotnet-aot.Tests/EnvironmentProviderTests.cs | Adds SDK directory scope lock. |
| test/dotnet-aot.Tests/dotnet-aot.Tests.csproj | Switches dotnet-aot.Tests to ClassLevel parallelization with lock guidance. |
| test/dotnet-aot.Tests/AotRunCommandTests.cs | Adds resource locks for native entry point/reporter/env vars. |
| test/dotnet-aot.Tests/AotParserTests.cs | Adds reporter/console resource locks. |
| test/Directory.Build.props | Updates repo-level MSTest parallelization guidance comment (default remains None). |
| test/ArgumentForwarding.Tests/ArgumentForwarding.Tests.csproj | Enables MethodLevel parallelization for argument-forwarding tests. |
| test/AGENTS.md | Updates contributor guidance: “audit before raising parallelism” and prefers ResourceLock. |
| src/Cli/dotnet/Commands/Test/MTP/TestRunPolicy.cs | Adds optional TimeProvider + switches to ITimer for testable timeout behavior. |
Use volatile publication and a thread-local recursive initialization context so parallel tests only contend during first initialization. Co-authored-by: Copilot App <[email protected]> Copilot-Session: a4ec0e90-6d52-4abd-aa3f-0805ec56797f
Local before/after benchmarkNo complete comparison on my Windows machine using the SDK repo test runner.
I could not produce a reliable before/after total for this PR: Timed out while running the baseline dotnet.Tests project after more than 90 minutes; not included in before/after totals. |
|
/azp run |
|
Azure Pipelines: Successfully started running 3 pipeline(s). 1 pipeline(s) were filtered out due to trigger conditions. |
Co-authored-by: Copilot App <[email protected]>

Summary
This draft is the common/default CODEOWNERS split of the broader SDK test-parallelization work. It enables audited
ClassLevelorMethodLevelparallelization for the eligible core SDK and CLI test assemblies in this ownership slice.The audit covers:
The changes isolate CWD, environment, filesystem, and static-state interactions where possible. Narrow resource locks or serial-tail execution remain where shared state cannot safely participate in parallel execution.
dotnet-MsiInstallation.Testsintentionally remains atNone: all four test classes share one Hyper-V VM and its persisted snapshot graph, so class-level execution would still contend on one inherently serial resource.10× benchmark results
The combined Razor-fixed branch was measured on the same machine under an exclusive benchmark lock. Each iteration ran the identical 54 affected projects sequentially through
scripts/RunTests.cs, with the same 90-minute per-project timeout and the same exclusion for the pre-existing hanging interruption test.All 10 changed iterations completed with zero timeouts and retained exactly the same 10-project local-environment/prerequisite failure set as all 10 baseline iterations; there were no new or resolved failing projects. These combined-branch measurements provide performance and stability context, not isolated attribution or a per-slice tests-passed claim.
Representative project medians:
dotnet.Testsimproved from 5,400.162s to 1,611.950s (70.15%), ToolPack improved 52.49%, and Infrastructure tests improved 33.29%.CI regression fixes and validation
The initial split build exposed analyzer dependencies that follow the
dotnet.Testsproject-level parallel opt-in:RunParserTestsmutates process-wide current-directory state, and six test-command parser methods mutate environment variables. The required[DoNotParallelize]andResourceLock(WellKnownResources.EnvironmentVariables)annotations now live in this independently buildable PR. The repository build succeeded, andRunParserTests|TestCommandDefinitionTestscompleted with 123 passed, 0 failed, and 1 not executed.Replacement CI then exposed lazy, concurrent
SdkTestContextinitialization. The fix initializes the context from the MSTest base constructor and serializes reentrant initialization while preserving early publication for recursive SDK-version resolution. With Helix-equivalentDOTNET_PROCESSOR_COUNT=2,GivenMsbuildForwardingApppassed 10/10, and the correlatedGivenMsbuildForwardingApp|GivenMSBuildLoggerpair passed 10/10.The next CI run exposed a scheduler-sensitive assumption in
TimeoutOnlyCountsTimeWithActiveTestApplications: its 300ms active timeout elapsed while the delayed continuation was starved for over one second. Commitc5c0bae851030bfc55ba4eb997bcb5eac5aea78bgives internalTestRunPolicyan optionalTimeProvider(production remainsTimeProvider.System) and makes this test advance active/inactive time deterministically. The method passed 10/10, and the exact 155-test Helix shard passed 3/3 runs (465/465 tests) withDOTNET_PROCESSOR_COUNT=4; final build/test completed without warnings or errors.The same CI run’s nine ApiCompat, GenAPI, and TemplateEngine restore failures were also present in contemporaneous
mainbuild 1575657 and all requested unavailable framework-reference packages11.0.0-preview.7.26381.103; they are target-branch failures, not caused by this PR. Final CI build 1575811 completed with every platform build passing and no PR-specific test failures. Its remaining red work items were exactly the target-branch framework-pack restore failures reproduced inmainbuild 1575657.