Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,10 @@ private void tryStart() {
// Wait until inspect container returns the mapped ports
containerInfo =
await()
.atMost(5, TimeUnit.SECONDS)
.atMost(
TestcontainersConfiguration.getInstance().getContainerPortMappingTimeout(),
TimeUnit.SECONDS
)
.pollInterval(DynamicPollInterval.ofMillis(50))
.pollInSameThread()
.until(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ public Integer getClientPingTimeout() {
return Integer.parseInt(getEnvVarOrProperty("client.ping.timeout", "10"));
}

public Integer getContainerPortMappingTimeout() {
return Integer.parseInt(getEnvVarOrProperty("container.port.mapping.timeout", "5"));
}

@Nullable
@Contract("_, !null, _ -> !null")
private String getConfigurable(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,28 @@ void shouldReadReuseFromEnvironment() {
assertThat(newConfig().environmentSupportsReuse()).as("reuse enabled via env var").isTrue();
}

@Test
void shouldReadContainerPortMappingTimeout() {
assertThat(newConfig().getContainerPortMappingTimeout())
.as("port mapping timeout is 5 seconds by default")
.isEqualTo(5);

classpathProperties.setProperty("container.port.mapping.timeout", "31");
assertThat(newConfig().getContainerPortMappingTimeout())
.as("port mapping timeout is changed by classpath properties")
.isEqualTo(31);

userProperties.setProperty("container.port.mapping.timeout", "32");
assertThat(newConfig().getContainerPortMappingTimeout())
.as("port mapping timeout is changed by user properties")
.isEqualTo(32);

environment.put("TESTCONTAINERS_CONTAINER_PORT_MAPPING_TIMEOUT", "33");
assertThat(newConfig().getContainerPortMappingTimeout())
.as("port mapping timeout is changed by env var")
.isEqualTo(33);
}

@Test
void shouldTrimImageNames() {
userProperties.setProperty("ryuk.container.image", " testcontainers/ryuk:0.3.2 ");
Expand Down
5 changes: 5 additions & 0 deletions docs/features/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ but does not allow starting privileged containers, you can turn off the Ryuk con
> **client.ping.timeout = 10**
> Specifies for how long Testcontainers will try to connect to the Docker client to obtain valid info about the client before giving up and trying next strategy, if applicable (in seconds).

## Customizing container startup behaviour

> **container.port.mapping.timeout = 5**
> Specifies for how long Testcontainers will wait for the Docker daemon to report the mapped ports of a starting container before giving up (in seconds).

## Customizing Docker host detection

Testcontainers will attempt to detect the Docker environment and configure everything to work automatically.
Expand Down