question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Parallel Gradle tests have trouble finding valid Docker environment

See original GitHub issue

Hi,

I know about the limitations that JUnit 5 is not tested with a parallel setup and corresponding ticket https://github.com/testcontainers/testcontainers-java/issues/1495.

I’m opening this because it’s a slightly different issue (but probably the same effects). We’re not using parallel JUnit 5 tests or the testcontainers JUnit 5 extension at all, but specify ./gradlew test --parallel to parallelize the different Gradle tasks in a multi-module setup.

We’re often getting the following messages in random modules, while the others work fine (so it’s not a general problem where all modules fail). There is even the chance that everything works fine, but the flakyness has increased lately

    15:15:41.847 [Test worker] DEBUG org.testcontainers.dockerclient.DockerClientProviderStrategy - UnixSocketClientProviderStrategy: failed with exception TimeoutException (org.rnorth.ducttape.TimeoutException: java.util.concurrent.TimeoutException). Root cause TimeoutException (null)
    15:15:41.848 [Test worker] DEBUG org.testcontainers.dockerclient.RootlessDockerClientProviderStrategy - $XDG_RUNTIME_DIR is set but '/run/user/997/docker.sock' does not exist.
    15:15:41.850 [Test worker] DEBUG org.testcontainers.dockerclient.RootlessDockerClientProviderStrategy - '/var/lib/jenkins/.docker/run' does not exist.
    15:15:41.895 [Test worker] DEBUG org.testcontainers.dockerclient.RootlessDockerClientProviderStrategy - '/run/user/997/docker.sock' does not exist.
    15:15:41.961 [Test worker] INFO org.testcontainers.dockerclient.DockerMachineClientProviderStrategy - docker-machine executable was not found on PATH ([/usr/local/bin, /usr/bin, /bin, /usr/games])
    15:15:41.994 [Test worker] ERROR org.testcontainers.dockerclient.DockerClientProviderStrategy - Could not find a valid Docker environment. Please check configuration. Attempted configurations were:
    15:15:41.995 [Test worker] ERROR org.testcontainers.dockerclient.DockerClientProviderStrategy -     UnixSocketClientProviderStrategy: failed with exception TimeoutException (org.rnorth.ducttape.TimeoutException: java.util.concurrent.TimeoutException). Root cause TimeoutException (null)
    15:15:41.996 [Test worker] ERROR org.testcontainers.dockerclient.DockerClientProviderStrategy - As no valid configuration was found, execution cannot continue

Our testcontainers part looks roughly like this in a base integration test class that the tests across modules all extend from:

	private static final DockerImageName imageName = DockerImageName.parse("our-artifactory/postgres:latest")
			.asCompatibleSubstituteFor("postgres");

	private static final PostgreSQLContainer<?> postgresContainer = new PostgreSQLContainer<>(imageName)
		.withDatabaseName("db")
		.withUsername("user")
		.withPassword("pass")
		.withStartupAttempts(5)
		.withStartupTimeout(Duration.ofMinutes(2))
		.withLogConsumer(new Slf4jLogConsumer(log));

	static {
		// Only use init script if resource exists
		String initScript = "docker/db/init.sql";
		URL resource = ScriptUtils.class.getClassLoader().getResource(initScript);
		if (resource == null) {
			initScript = null;
		}

		postgresContainer.withInitScript(initScript).start();
	}

Unfortunately, I can’t share more or an example project. But any help is highly appreciated.

Cheers, Christoph

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
dreis2211commented, Mar 25, 2022

That particular build step takes ~12 minutes sequentially vs. roughly 6 minutes when we run it with --parallel, @kiview .

1reaction
dreis2211commented, Mar 25, 2022

Raising client.ping.timeout to 30 again solved the issue for me. Maybe the default of 30 can be brought back or this ticket can be turned into a documentation ticket.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Test Container test cases are failing due to "Could not find a ...
In my case this error caused by root permission. If you are using ubuntu, docker wants permission to create container and testcontainers can ......
Read more >
Improve the Performance of Gradle Builds
Tests in parallel must be independent. They should not share resources such as files or databases. If your tests do share resources, they...
Read more >
Running Parallel Tests in Docker - Java Code Geeks - 2022
So when you start the second test (in parallel) you will get a failure regarding that a conflict container name because of trying...
Read more >
Reuse test containers in parallel integration tests
Implementation. Gradle. def runItDocker = tasks.register("runItDocker", JavaExec) { it.outputs.cacheIf { true }
Read more >
Speed-up your Testcontainers tests - Callista Enterprise AB
Use the singleton pattern; Speed-up start time with multiple containers; Reuse your Testcontainers; Runing tests in a docker container ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found