8000 testForkedParallel does not behave the same as parallelExecution · Issue #8004 · sbt/sbt · GitHub
[go: up one dir, main page]

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

testForkedParallel does not behave the same as parallelExecution #8004

Open
matthughes opened this issue Jan 10, 2025 · 0 comments
Open

testForkedParallel does not behave the same as parallelExecution #8004

matthughes opened this issue Jan 10, 2025 · 0 comments
Labels

Comments

@matthughes
Copy link
709F

steps

Configure a project to run its forked tests in parallel:

    fork                          := true,
    testForkedParallel            := true,

problem

When running non-forked tests in parallel the use of concurrent restrictions limits the number of in-flight tests:

concurrentRestrictions := Seq(Tags.limit(Tags.All, 2))

However, when running forked tests, SBT uses the number of cores available to the machine:

See ForkMain.scala

    private ExecutorService executorService(
        final ForkConfiguration config, final ObjectOutputStream os) {
      if (config.isParallel()) {
        final int nbThreads = Runtime.getRuntime().availableProcessors();
        logDebug(os, "Create a test executor with a thread pool of " + nbThreads + " threads.");
        // more options later...
        // TODO we might want to configure the blocking queue with size #proc
        return Executors.newFixedThreadPool(nbThreads);
      } else {
        logDebug(os, "Create a single-thread test executor");
        return Executors.newSingleThreadExecutor();
      }
    }

expectation

testForkedParallel should use the same concurrentRestrictions mechanism to limit the number of in-flight tests OR provide some other setting. (e.g., testForkedParallism := 2).

notes

There is a workaround for this which is configuring the number of cores exposed to the JVM via javaOptions:

    Test / javaOptions ++= 
      // Limit to two test threads
      Seq(
        "-XX:ActiveProcessorCount=2",
      )
@matthughes matthughes added the Bug label Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant
0