Skip to content

Commit ed0db16

Browse files
mimfggrnorth
authored andcommitted
Make StartupCheckStrategy timeout value configurable (#1308)
in case of big docker images (Elasticsearch 6.6.0 is 808MB for example) the hardcoded 30s timeout makes a lot of our builds fail the first time they run. We fixed this locally, but it would be nice to have it as a parameter on the parent class.
1 parent 978d374 commit ed0db16

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

core/src/main/java/org/testcontainers/containers/startupcheck/StartupCheckStrategy.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.rnorth.ducttape.ratelimits.RateLimiterBuilder;
77
import org.rnorth.ducttape.unreliables.Unreliables;
88

9+
import java.time.Duration;
910
import java.util.concurrent.TimeUnit;
1011

1112
import static org.testcontainers.containers.GenericContainer.CONTAINER_RUNNING_TIMEOUT_SEC;
@@ -21,9 +22,17 @@ public abstract class StartupCheckStrategy {
2122
.withConstantThroughput()
2223
.build();
2324

25+
private Duration timeout = Duration.ofSeconds(CONTAINER_RUNNING_TIMEOUT_SEC);
26+
27+
@SuppressWarnings("unchecked")
28+
public <SELF extends StartupCheckStrategy> SELF withTimeout(Duration timeout) {
29+
this.timeout = timeout;
30+
return (SELF) this;
31+
}
32+
2433
public boolean waitUntilStartupSuccessful(DockerClient dockerClient, String containerId) {
2534
final Boolean[] startedOK = {null};
26-
Unreliables.retryUntilTrue(CONTAINER_RUNNING_TIMEOUT_SEC, TimeUnit.SECONDS, () -> {
35+
Unreliables.retryUntilTrue((int) timeout.toMillis(), TimeUnit.MILLISECONDS, () -> {
2736
//noinspection CodeBlock2Expr
2837
return DOCKER_CLIENT_RATE_LIMITER.getWhenReady(() -> {
2938
StartupStatus state = checkStartupState(dockerClient, containerId);

0 commit comments

Comments
 (0)