Skip to content

Commit

Permalink
Passthrough docker.check.timeout.seconds system property or env (#605)
Browse files Browse the repository at this point in the history
* Passthrough docker.check.timeout.seconds system property

When starting the test-resources server

* Add env var and docs
  • Loading branch information
timyates authored Apr 22, 2024
1 parent 0eebd07 commit 5446c28
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/docs/guide/architecture-configuration.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
=== Docker Client creation timeout

The test-resources server communicates with Docker via a docker client.
By default, creation of this client is expected to take less than 10 seconds.
However, under certain circumstances (limited resources, docker in docker, etc.), this may take longer.
To configure the timeout, you can pass a system property `docker.check.timeout.seconds` or an environment variable `TEST_RESOURCES_DOCKER_CHECK_TIMEOUT_SECONDS` with the number of seconds you require.
1 change: 1 addition & 0 deletions src/main/docs/guide/architecture-server.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ For example, a MySQL database may need to be started when the tests start, and s
For this purpose, the test resource server must be started before the application under test starts, and shutdown after test resources are no longer needed.

It means, for example, that with https://docs.gradle.org/current/userguide/userguide_single.html#sec:continuous_build[Gradle continuous builds], the test resources server would outlive a single build, making it possible to develop your application while not paying the price of starting a container on each build.

2 changes: 2 additions & 0 deletions src/main/docs/guide/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ architecture:
title: The test resources server
architecture-shared-server:
title: Sharing containers between independent builds
architecture-configuration:
title: Configuring the server
architecture-client:
title: The test resources client
architecture-embedded:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ public class ServerUtils {
private static final String CDS_CLASS_LST = "cds.classlist";
private static final String FLAT_JAR = "flat.jar";

// See io.micronaut.testresources.testcontainers.DockerSupport.TIMEOUT
private static final String DOCKER_CHECK_TIMEOUT_SECONDS_ENV = "TEST_RESOURCES_DOCKER_CHECK_TIMEOUT_SECONDS";
private static final String DOCKER_CHECK_TIMEOUT_SECONDS_PROPERTY = "docker.check.timeout.seconds";

/**
* Writes the server settings in an output directory.
*
Expand Down Expand Up @@ -461,6 +465,13 @@ public boolean isCDSDumpInvocation() {
public Map<String, String> getSystemProperties() {
Map<String, String> systemProperties = new HashMap<>();
systemProperties.put(JMX_SYSTEM_PROPERTY, null);
String dockerCheckTimeout = System.getProperty(DOCKER_CHECK_TIMEOUT_SECONDS_PROPERTY);
if (dockerCheckTimeout == null) {
dockerCheckTimeout = System.getenv(DOCKER_CHECK_TIMEOUT_SECONDS_ENV);
}
if (dockerCheckTimeout != null) {
systemProperties.put(DOCKER_CHECK_TIMEOUT_SECONDS_PROPERTY, dockerCheckTimeout);
}
if (explicitPort != null) {
systemProperties.put(MICRONAUT_SERVER_PORT, String.valueOf(explicitPort));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,23 @@ class ServerUtilsTest extends Specification {
'abc' | [new File('def')] | 98
}

@RestoreSystemProperties
def "can set the docker check timeout"() {
def portFile = tmpDir.resolve("port-file")
def settingsDir = tmpDir.resolve("settings")
def factory = Mock(ServerFactory)
System.setProperty('docker.check.timeout.seconds', "100")

when:
ServerUtils.startOrConnectToExistingServer(9999, portFile, settingsDir, null, null, null, null, factory)

then:
1 * factory.startServer(_) >> { ServerUtils.ProcessParameters params ->
assert params.mainClass == 'io.micronaut.testresources.server.TestResourcesService'
assert params.systemProperties['docker.check.timeout.seconds'] == '100'
}
}

@RestoreSystemProperties
def "waits for the server to be available when using an explicit port"() {
def portFile = tmpDir.resolve("port-file")
Expand Down

0 comments on commit 5446c28

Please sign in to comment.