Reusable containers and Gradle parallel test execution #4394
Replies: 2 comments 2 replies
-
|
@keith-miller it looks like, since your tests are executed in parallel, they all fail to find a running container and decide to start one. There isn't much that Testcontainers can do about it (we have no awareness of other Testcontainers sessions on the same machine, at least not yet), but you can workaround it by running a single job that would start these before your parallel test sessions, so that every parallel session will be able to discover running containers. |
Beta Was this translation helpful? Give feedback.
-
|
For reusable containers with parallel Gradle tests, use # ~/.testcontainers.properties
testcontainers.reuse.enable=trueThen mark containers as reusable in code: @Container
static PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>("postgres:15")
.withReuse(true); // ← key methodFor Gradle parallel execution, set @Testcontainers
abstract class BaseIntegrationTest {
@Container
static PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>("postgres:15")
.withReuse(true);
static String jdbcUrl;
static String username;
static String password;
@BeforeAll
static void setup() {
jdbcUrl = postgres.getJdbcUrl();
username = postgres.getUsername();
password = postgres.getPassword();
}
}Important: With For full parallelism without port conflicts, use |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
First off thank you for such a great library!
We have a question about reusing containers. We're currently switching our Gradle builds over to parallel mode, and we are noticing that we're having issues with our generic Redis container being started multiple times. Here is the init code block:
Then, we see during the run:

and after:

The CockroachDB/RabbitMQ seem to handle the startup race condition fine and only start one container. The Redis GenericContainer starts multiple times. So, is there a way to handle the startup race condition for the Redis container?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions