Skip to content

Commit 8eea37c

Browse files
authored
Remember failure to ping docker daemon to reduce log garbage and reduce run time (#456)
1 parent 184546d commit 8eea37c

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
All notable changes to this project will be documented in this file.
33

44
## UNRELEASED
5+
### Changed
6+
- Added caching of failure to find a docker daemon, so that subsequent tests fail fast. This is likely to be a significant improvement in situations where there is no docker daemon available, dramatically reducing run time and log output when further attempts to find the docker daemon cannot succeed.
7+
58
### Fixed
69
- Fixed local Docker Compose executable name resolution on Windows (#416)
710
- Fix TAR composition on Windows (#444)

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.List;
2121
import java.util.Objects;
2222
import java.util.concurrent.TimeUnit;
23+
import java.util.concurrent.atomic.AtomicBoolean;
2324
import java.util.stream.Stream;
2425

2526
/**
@@ -35,6 +36,8 @@ public abstract class DockerClientProviderStrategy {
3536
.withConstantThroughput()
3637
.build();
3738

39+
private static final AtomicBoolean FAIL_FAST_ALWAYS = new AtomicBoolean(false);
40+
3841
/**
3942
* @throws InvalidConfigurationException if this strategy fails
4043
*/
@@ -64,6 +67,11 @@ protected int getPriority() {
6467
* @return a working DockerClientConfig, as determined by successful execution of a ping command
6568
*/
6669
public static DockerClientProviderStrategy getFirstValidStrategy(List<DockerClientProviderStrategy> strategies) {
70+
71+
if (FAIL_FAST_ALWAYS.get()) {
72+
throw new IllegalStateException("Previous attempts to find a Docker environment failed. Will not retry. Please see logs and check configuration");
73+
}
74+
6775
List<String> configurationFailures = new ArrayList<>();
6876

6977
return Stream
@@ -134,6 +142,7 @@ public static DockerClientProviderStrategy getFirstValidStrategy(List<DockerClie
134142
}
135143
LOGGER.error("As no valid configuration was found, execution cannot continue");
136144

145+
FAIL_FAST_ALWAYS.set(true);
137146
return new IllegalStateException("Could not find a valid Docker environment. Please see logs and check configuration");
138147
});
139148
}

0 commit comments

Comments
 (0)