Limit the number of concurrent tests - #1305
Merged
Merged
Conversation
Every test compiles code with Roslyn, so running one test per CPU thread uses a lot of memory: a single test project peaks at 20 GB on a 15 thread machine, and the test projects of the Roslyn versions run in parallel. Add a testconfig.json limiting 'xUnit.maxParallelThreads' to 8. It is shared by all the Roslyn versions as they are in the same folder, and Microsoft.Testing.Platform.MSBuild copies it to the output folder of each project. The peak memory of a test project goes from 20 GB to 3 GB, for the same duration (57s vs 58s). The value is not a multiplier such as '0.5x' so that the 4 threads CI machines keep their current parallelism.
meziantou
enabled auto-merge (squash)
August 19, 2026 20:08
This was referenced Aug 19, 2026
Closed
Bump Meziantou.Analyzer from 3.0.103 to 3.0.170
Analogy-LogViewer/Analogy.LogViewer.OpenTelemetry#94
Closed
Closed
Closed
Closed
Bump Meziantou.Analyzer from 3.0.139 to 3.0.173
Analogy-LogViewer/Analogy.LogViewer.NLog.Targets#552
Closed
This was referenced Sep 21, 2026
Open
Bump Meziantou.Analyzer from 3.0.139 to 3.0.266
Analogy-LogViewer/Analogy.LogViewer.NLog.Targets#579
Closed
Closed
Bump Meziantou.Analyzer from 3.0.139 to 3.0.266
Analogy-LogViewer/Analogy.AspNetCore.LogProvider#560
Closed
Closed
Closed
Closed
Closed
Closed
Closed
Closed
Closed
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.
Every test compiles code with Roslyn, so running one test per CPU thread uses a lot of memory. On a 15 thread machine, a single test project peaks at 20 GB, and
dotnet testat the solution level runs the 5 Roslyn version projects in parallel, which multiplies it.Changes
tests/Meziantou.Analyzer.Test/testconfig.json: limitsxUnit.maxParallelThreadsto 8. The file is shared by all the Roslyn versions, as their projects are in the same folder, andMicrosoft.Testing.Platform.MSBuildcopies it to the output folder of each project asMeziantou.Analyzer.Test.testconfig.json.AGENTS.md: documents the new file, anddotnet test --max-parallel-test-modulesto limit how many test projects run at the same time (there is no configuration file equivalent for that one).Measurements
Roslyn 5.9 test project (3663 tests), Release, 15 CPU threads:
The memory grows much faster than the throughput, so 8 divides the memory by ~7 for the same duration.
Notes for the reviewer
"0.5x", because the CI machines have 4 threads: a multiplier would halve their current parallelism and slow the jobs down, while 8 leaves them unchanged and only caps the bigger development machines.--max-parallel-test-modulesbounds the number of test projects, not the memory of one project, so it does not replace this setting: a single project would still peak at 20 GB.Verification
dotnet test tests/Meziantou.Analyzer.Test/Meziantou.Analyzer.Test.roslyn4.8.csproj --configuration Release: 3533/3533 passedMeziantou.Analyzer.Test.testconfig.jsonis in the output folder of both the roslyn4.8 and the roslyn5.9 projects