Skip to content

Commit

Permalink
Merge pull request #217 from kunickiaj/environmentstrategy
Browse files Browse the repository at this point in the history
Make ping retry timeout configurable for DockerClientProviderStrategy
  • Loading branch information
rnorth committed Sep 21, 2016
2 parents f436842 + 59aa768 commit acea6a9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
* Use Docker machine (if available on the PATH) to locate a Docker environment.
*/
public class DockerMachineClientProviderStrategy extends DockerClientProviderStrategy {
private static final String PING_TIMEOUT_DEFAULT = "30";
private static final String PING_TIMEOUT_PROPERTY_NAME = "testcontainers.dockermachineprovider.timeout";

@Override
public void test() throws InvalidConfigurationException {

Expand Down Expand Up @@ -44,7 +47,8 @@ public void test() throws InvalidConfigurationException {
}

// If the docker-machine VM has started, the docker daemon may still not be ready. Retry pinging until it works.
ping(client, 30);
final int timeout = Integer.parseInt(System.getProperty(PING_TIMEOUT_PROPERTY_NAME, PING_TIMEOUT_DEFAULT));
ping(client, timeout);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* to try and locate a docker environment.
*/
public class EnvironmentAndSystemPropertyClientProviderStrategy extends DockerClientProviderStrategy {
private static final String PING_TIMEOUT_DEFAULT = "10";
private static final String PING_TIMEOUT_PROPERTY_NAME = "testcontainers.environmentprovider.timeout";

@Override
public void test() throws InvalidConfigurationException {
Expand All @@ -17,8 +19,10 @@ public void test() throws InvalidConfigurationException {
config = DefaultDockerClientConfig.createDefaultConfigBuilder().build();
client = getClientForConfig(config);

ping(client, 1);
final int timeout = Integer.parseInt(System.getProperty(PING_TIMEOUT_PROPERTY_NAME, PING_TIMEOUT_DEFAULT));
ping(client, timeout);
} catch (Exception e) {
LOGGER.error("ping failed with configuration {} due to {}", getDescription(), e.toString(), e);
throw new InvalidConfigurationException("ping failed");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
import java.nio.file.Paths;

public class UnixSocketClientProviderStrategy extends DockerClientProviderStrategy {

protected static final String DOCKER_SOCK_PATH = "/var/run/docker.sock";
private static final String SOCKET_LOCATION = "unix://" + DOCKER_SOCK_PATH;
private static final int SOCKET_FILE_MODE_MASK = 0xc000;
private static final String PING_TIMEOUT_DEFAULT = "10";
private static final String PING_TIMEOUT_PROPERTY_NAME = "testcontainers.unixsocketprovider.timeout";


@Override
public void test()
Expand Down Expand Up @@ -52,7 +54,8 @@ protected DockerClientConfig tryConfiguration(String dockerHost) {
.build();
client = getClientForConfig(config);

ping(client, 10);
final int timeout = Integer.parseInt(System.getProperty(PING_TIMEOUT_PROPERTY_NAME, PING_TIMEOUT_DEFAULT));
ping(client, timeout);

return config;
}
Expand Down

0 comments on commit acea6a9

Please sign in to comment.