Skip to content

Commit 9f77a6d

Browse files
authored
Shorten fallback to another strategy (#4386)
* Removed double check of configured Docker client strategy. * Shortened the ping timeout (when choosing docker client) to 5 seconds. * Added `client.ping.timeout` configuration option. * Made relevant change in the docs.
1 parent b1cdaf9 commit 9f77a6d

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

core/src/main/java/org/testcontainers/dockerclient/DockerClientProviderStrategy.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,11 @@ public static DockerClientProviderStrategy getFirstValidStrategy(List<DockerClie
111111

112112
List<String> configurationFailures = new ArrayList<>();
113113

114+
String dockerClientStrategyClassName = TestcontainersConfiguration.getInstance().getDockerClientStrategyClassName();
114115
return Stream
115116
.concat(
116117
Stream
117-
.of(TestcontainersConfiguration.getInstance().getDockerClientStrategyClassName())
118+
.of(dockerClientStrategyClassName)
118119
.filter(Objects::nonNull)
119120
.flatMap(it -> {
120121
try {
@@ -136,6 +137,7 @@ public static DockerClientProviderStrategy getFirstValidStrategy(List<DockerClie
136137
.peek(strategy -> log.info("Loaded {} from ~/.testcontainers.properties, will try it first", strategy.getClass().getName())),
137138
strategies
138139
.stream()
140+
.filter(it -> !it.getClass().getCanonicalName().equals(dockerClientStrategyClassName))
139141
.filter(DockerClientProviderStrategy::isApplicable)
140142
.sorted(Comparator.comparing(DockerClientProviderStrategy::getPriority).reversed())
141143
)
@@ -145,7 +147,7 @@ public static DockerClientProviderStrategy getFirstValidStrategy(List<DockerClie
145147

146148
Info info;
147149
try {
148-
info = Unreliables.retryUntilSuccess(30, TimeUnit.SECONDS, () -> {
150+
info = Unreliables.retryUntilSuccess(TestcontainersConfiguration.getInstance().getClientPingTimeout(), TimeUnit.SECONDS, () -> {
149151
return strategy.PING_RATE_LIMITER.getWhenReady(() -> {
150152
log.debug("Pinging docker daemon...");
151153
return dockerClient.infoCmd().exec();

core/src/main/java/org/testcontainers/utility/TestcontainersConfiguration.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,10 @@ public String getImageSubstitutorClassName() {
210210
return getEnvVarOrProperty("image.substitutor", null);
211211
}
212212

213+
public Integer getClientPingTimeout() {
214+
return Integer.parseInt(getEnvVarOrProperty("client.ping.timeout", "5"));
215+
}
216+
213217
@Nullable
214218
@Contract("_, !null, _ -> !null")
215219
private String getConfigurable(@NotNull final String propertyName, @Nullable final String defaultValue, Properties... propertiesSources) {

docs/features/configuration.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ but does not allow starting privileged containers, you can turn off the Ryuk con
9494
> **pull.pause.timeout = 30**
9595
> By default Testcontainers will abort the pull of an image if the pull appears stalled (no data transferred) for longer than this duration (in seconds).
9696
97+
## Customizing client ping behaviour
98+
99+
> **client.ping.timeout = 5**
100+
> 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).
101+
97102
## Customizing Docker host detection
98103

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

0 commit comments

Comments
 (0)