From 5446c28a4248c3e6216fedaf894ab1ea4ec79c18 Mon Sep 17 00:00:00 2001 From: Tim Yates Date: Mon, 22 Apr 2024 17:00:58 +0100 Subject: [PATCH] Passthrough docker.check.timeout.seconds system property or env (#605) * Passthrough docker.check.timeout.seconds system property When starting the test-resources server * Add env var and docs --- .../docs/guide/architecture-configuration.adoc | 6 ++++++ src/main/docs/guide/architecture-server.adoc | 1 + src/main/docs/guide/toc.yml | 2 ++ .../testresources/buildtools/ServerUtils.java | 11 +++++++++++ .../buildtools/ServerUtilsTest.groovy | 17 +++++++++++++++++ 5 files changed, 37 insertions(+) create mode 100644 src/main/docs/guide/architecture-configuration.adoc diff --git a/src/main/docs/guide/architecture-configuration.adoc b/src/main/docs/guide/architecture-configuration.adoc new file mode 100644 index 000000000..f44fdcba6 --- /dev/null +++ b/src/main/docs/guide/architecture-configuration.adoc @@ -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. diff --git a/src/main/docs/guide/architecture-server.adoc b/src/main/docs/guide/architecture-server.adoc index 579025b59..a22b46834 100644 --- a/src/main/docs/guide/architecture-server.adoc +++ b/src/main/docs/guide/architecture-server.adoc @@ -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. + diff --git a/src/main/docs/guide/toc.yml b/src/main/docs/guide/toc.yml index 49dfb8e06..d1581fe66 100644 --- a/src/main/docs/guide/toc.yml +++ b/src/main/docs/guide/toc.yml @@ -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: diff --git a/test-resources-build-tools/src/main/java/io/micronaut/testresources/buildtools/ServerUtils.java b/test-resources-build-tools/src/main/java/io/micronaut/testresources/buildtools/ServerUtils.java index 2384d2abb..1f7827f6c 100644 --- a/test-resources-build-tools/src/main/java/io/micronaut/testresources/buildtools/ServerUtils.java +++ b/test-resources-build-tools/src/main/java/io/micronaut/testresources/buildtools/ServerUtils.java @@ -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. * @@ -461,6 +465,13 @@ public boolean isCDSDumpInvocation() { public Map getSystemProperties() { Map 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)); } diff --git a/test-resources-build-tools/src/test/groovy/io/micronaut/testresources/buildtools/ServerUtilsTest.groovy b/test-resources-build-tools/src/test/groovy/io/micronaut/testresources/buildtools/ServerUtilsTest.groovy index 67b5570d4..73fdcebee 100644 --- a/test-resources-build-tools/src/test/groovy/io/micronaut/testresources/buildtools/ServerUtilsTest.groovy +++ b/test-resources-build-tools/src/test/groovy/io/micronaut/testresources/buildtools/ServerUtilsTest.groovy @@ -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")