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 @@ -391,11 +391,21 @@ public static DockerClient getClientForConfig(TransportConfig transportConfig) {
String transportType = TestcontainersConfiguration.getInstance().getTransportType();
switch (transportType) {
case "httpclient5":
dockerHttpClient =
new ZerodepDockerHttpClient.Builder()
.dockerHost(transportConfig.getDockerHost())
.sslConfig(transportConfig.getSslConfig())
.build();
ZerodepDockerHttpClient.Builder builder = new ZerodepDockerHttpClient.Builder()
.dockerHost(transportConfig.getDockerHost())
.sslConfig(transportConfig.getSslConfig());

Duration connectionTimeout = TestcontainersConfiguration.getInstance().getClientConnectionTimeout();
if (connectionTimeout != null) {
builder.connectionTimeout(connectionTimeout);
}

Duration responseTimeout = TestcontainersConfiguration.getInstance().getClientResponseTimeout();
if (responseTimeout != null) {
builder.responseTimeout(responseTimeout);
}

dockerHttpClient = builder.build();
break;
default:
throw new IllegalArgumentException("Unknown transport type '" + transportType + "'");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.time.Duration;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
Expand Down Expand Up @@ -224,6 +225,18 @@ public Integer getClientPingTimeout() {
return Integer.parseInt(getEnvVarOrProperty("client.ping.timeout", "10"));
}

@Nullable
public Duration getClientConnectionTimeout() {
String timeout = getEnvVarOrProperty("client.connection.timeout", null);
return timeout != null ? Duration.ofSeconds(Integer.parseInt(timeout)) : null;
}

@Nullable
public Duration getClientResponseTimeout() {
String timeout = getEnvVarOrProperty("client.response.timeout", null);
return timeout != null ? Duration.ofSeconds(Integer.parseInt(timeout)) : null;
}

@Nullable
@Contract("_, !null, _ -> !null")
private String getConfigurable(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,22 @@ void shouldTrimImageNames() {
.isEqualTo("testcontainers/ryuk:0.3.2");
}

@Test
void shouldReadClientConnectionTimeout() {
assertThat(newConfig().getClientConnectionTimeout()).isNull();

userProperties.setProperty("client.connection.timeout", "45");
assertThat(newConfig().getClientConnectionTimeout()).isEqualTo(java.time.Duration.ofSeconds(45));
}

@Test
void shouldReadClientResponseTimeout() {
assertThat(newConfig().getClientResponseTimeout()).isNull();

userProperties.setProperty("client.response.timeout", "120");
assertThat(newConfig().getClientResponseTimeout()).isEqualTo(java.time.Duration.ofSeconds(120));
}

private TestcontainersConfiguration newConfig() {
return new TestcontainersConfiguration(userProperties, classpathProperties, environment);
}
Expand Down
8 changes: 8 additions & 0 deletions docs/features/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ 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 client connection and response timeouts

> **client.connection.timeout = (not set)**
> Specifies the maximum time allowed to establish a connection to the Docker daemon (in seconds). If not configured, the default connection timeout of the underlying transport client (3 minutes) is used.

> **client.response.timeout = (not set)**
> Specifies the maximum time allowed to wait for a response from the Docker daemon after a connection is established (in seconds). If not configured, the default response timeout of the underlying transport client is used.

## Customizing Docker host detection

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