Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifying the degree of parallelism #4044

Closed
MatisseHack opened this issue Oct 6, 2022 · 4 comments
Closed

Allow specifying the degree of parallelism #4044

MatisseHack opened this issue Oct 6, 2022 · 4 comments

Comments

@MatisseHack
Copy link

Description

I have several test projects written with xUnit that I want to run in CI. These unit tests are IO bound and run much more quickly when parallelized with dotnet vstest --parallel. However, machines in my CI system (GitHub Actions) only have two CPU cores, which limits test execution to two concurrent assemblies. I would like to speed up my tests when run in CI by increasing the degree of parallelism further.

I added the following xunit.runner.json file to my project, but it only affected parallelization within each assembly.

{
  "parallelizeAssembly": true,
  "maxParallelThreads": -1
}

I was very surprised that parallelizeAssembly seemingly has no effect when run with the dotnet CLI. I assume MSBuild and VSTest create separate xUnit test runners for each assembly, which is why this setting has no effect?

I was able to work around that issue by using dotnet test --no-build -maxCpuCount:8, but the maxCpuCount parameter does not work with dotnet vstest, which tends to give me cleaner test output. Would it make sense to add support for maxCpuCount (or a similar parameter) in VSTest?

Steps to reproduce

Run dotnet vstest --parallel on a machine with more test projects than CPU cores.

Expected behavior

The dotnet CLI should respect properties in my xunit.runner.json file. However, barring that, it would be nice if there was a parameter that would increase the degree of parallelism when running dotnet vstest --parallel.

Actual behavior

A higher degree of parallelism can only be achieved when running tests through MSBuild (dotnet test).

Diagnostic logs

N/A

Environment

Linux and macOS

$ dotnet --version
6.0.401
@nohwnd nohwnd added the vNext label Oct 7, 2022
@nohwnd
Copy link
Member

nohwnd commented Oct 7, 2022

@MatisseHack I think all the options you set are propagated correctly but our code assumes that tests will run in parallel (doing CPU bound work at the same time), and hence it chooses the minimal number between logical processor count, the specified maxCpuCount and assembly count to avoid overwhelming the CPU with too much parallel work. In your case the maxParallelLevel will be 2, because you have 2 logical processors.

In your case this assumption is not correct, because your tests are IO bound, and hence they run concurrently on the processors (they don't always do CPU work, so more than 2 concurrent tests can easily be handled by the CPU).

We don't have an option for that, and I don't think we can easily add it as there is an existing behavior, and we don't want to add yet another very similar option.

@MatisseHack
Copy link
Author

Do you mean that -maxCpuCount should work as a parameter to dotnet vstest? I got an error when I tried that:

The argument -maxCpuCount:1 is invalid. Please use the /help option to check the list of valid arguments.

Allowing this parameter and making it consistent with the behavior of dotnet test -maxCpuCount:8 would make the most sense to me, but I realize there is legacy behavior to consider when calling vstest.console.exe directly.

Is there any way to use the same test adapter for all assemblies then? I'm not familiar with the internals of VSTest, but am I correct in thinking that it's creating a separate xUnit test adapter for each assembly, which overrides xUnit's ability to run assemblies in parallel? Would it be possible to add an option to adjust this behavior instead?

@elpht
Copy link

elpht commented Feb 17, 2024

I don't understand that having test frameworks, like xUnit, that are able to handle (and interested in doing that) parallelism, vstest opts for the no-no, "I don't support it, nor I let others do it". Woudn't be the easiest for vstest to hand over that responsibility to the test framework or, at least, allowing that option?

@nohwnd
Copy link
Member

nohwnd commented Jul 8, 2024

This is a new feature and won't be implemented, we are focusing on adding new features to Testing.Platform instead. https://aka.ms/testingplatform

@nohwnd nohwnd closed this as not planned Won't fix, can't repro, duplicate, stale Jul 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants