Skip to content

Add note about controlling concurrency when using parallel execution to user guide #1675

@gilday

Description

@gilday

While working with parallel test execution in JUnit 5.3.1, I came across a mystery that I have not yet solved wherein I can trick JUnit into running more concurrent tests than it is configured to run as a side-effect of sleeping a thread inside of a CompletableFuture i.e.

    CompletableFuture.runAsync(
              () -> {
                try {
                  Thread.sleep(1000);
                } catch (InterruptedException e) {
                  Thread.currentThread().interrupt();
                }
              })
          .join();

When this code is present in a test, JUnit will run an additional concurrent test. For example, if junit.jupiter.execution.parallel.config.fixed.parallelism=4, one expects at most 4 tests to run concurrently; however if this CompletableFuture code snippet is present in all running tests, I observe at most 8 concurrent tests (assuming the total number of tests is greater than 8).

Steps to reproduce

Maven project gilday/junit-parallelization-issue contains code to reproduce this issue. It includes a counter class HighWaterMark which observes at most 8 concurrent tests running when junit.jupiter.execution.parallel.config.fixed.parallelism=4.

Context

  • Jupiter 5.3.1
  • Maven Surefire 2.22.1
  • JDK 1.8

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions