question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JUnit5: Start containers concurrently

See original GitHub issue

When using Testcontainers in combination with JUnit5 using @Testcontainers and @Container all the containers are started sequentially.

Especially when there are multiple containers involved it could save some time to start them in parallel.

This feature request is about facilitating the concurrent start of containers.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
40rn05lyvcommented, Aug 6, 2022

It’s possible to use both @Container annotation with a parallel approach. You can implement org.testcontainers.lifecycle.Startable interface that would have several containers inside it. Like this:

public class ParallelContainers implements org.testcontainers.lifecycle.Startable {

    private final GenericContainer container1 = ...;
    private final GenericContainer container2 = ...;

    @Override
    public void start() {
        Stream.of(this.container1, this.container2).parallel().forEach(GenericContainer::start);
    }

    @Override
    public void stop() {
        Stream.of(this.container1, this.container2).parallel().forEach(GenericContainer::stop);
    }

}

And then just use @Container ParallelContainers containers in test classes.

0reactions
Olex1313commented, Dec 11, 2022

Well sorry for long thinking about the problem, maybe it instead could be a flag on @Container annotation, so in the https://github.com/testcontainers/testcontainers-java/blob/main/modules/junit-jupiter/src/main/java/org/testcontainers/junit/jupiter/TestcontainersExtension.java, we might split containers into 2 groups every time we have to start it, and as you said start ones with the flag with sample of code like this

parallelContainers.parallel().forEach(GenericContainer::start);

?

Read more comments on GitHub >

github_iconTop Results From Across the Web

JUnit 5 Quickstart - Testcontainers for Java
The @Container annotation tells JUnit to notify this field about various events in the test lifecycle. In this case, our rule object is...
Read more >
JUnit 5 User Guide
However, both delimiter attributes cannot be set simultaneously. Comments in CSV files. Any line beginning with a # symbol will be interpreted ...
Read more >
JUnit 5 tests are executed in parallel inside IntelliJ and locally ...
JUnit 5 tests are executed in parallel inside IntelliJ and locally with Maven, but not inside Maven Docker container on Google Cloud Build....
Read more >
Introduction to Testcontainers with JUnit 5 and Spring Boot
Get started with Testcontainers to write integration tests for your Spring Boot application with ease. This tutorial covers a first ...
Read more >
JUnit5: Parallelization of Parameterized Tests (Only)
In order to run selected parameterized tests concurrently, ... As presented, it is clear that there were two separate containers spinned up ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found