You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If FailureDetectingExternalResource::starting throws an exception then FailureDetectingExternalResource::finished won't get invoked. This affects cleanup routines implemented in subclasses, such as in DockerComposeContainer::finished. An exception in starting() can lead to lingering Docker containers and networks.
Steps to reproduce
Define a service via docker-compose that exposes a service port to the host which is already in use (in this example it's a Cassandra server listening on localhost's TCP port 9042). Add another service to the docker-compose definition -- this is the container that will be left over after a failed start (in this example it's a Redis container). Run a unit test using a DockerComposeContainer with the said docker-compose service definition. Observe the lingering container after the unit test finished.
package org.testcontainers.junit;
import lombok.extern.slf4j.Slf4j;
import org.junit.Rule;
import org.junit.Test;
import org.testcontainers.containers.DockerComposeContainer;
import java.io.File;
@Slf4j
public class StartFailsCleanupMissing {
private static final int CASSANDRA_PORT = 9042;
@Rule
public DockerComposeContainer environment =
new DockerComposeContainer(new File ("src/test/resources/start-fails-cleanup-missing.yml"))
.withExposedService("cassandra_1", CASSANDRA_PORT)
.withTailChildContainers(true)
.withLocalCompose(true);
@Test
public void test1() throws InterruptedException {
Thread.sleep(60000);
}
}
log output of unit test:
[...]
16:02:24.007 ERROR [docker-compose] - Creating network "ud59hm_default" with the default driver
16:02:24.235 ERROR [docker-compose] - Creating ud59hm_redis_1
16:02:24.237 ERROR [docker-compose] - Creating ud59hm_cassandra_1
16:02:25.931 ERROR [docker-compose] - ERROR: for cassandra Cannot start service cassandra: driver failed programming external connectivity on endpoint ud59hm_cassandra_1 (9961a92541c51345ff0abdc44423b92a717cac069c35f3f22d32b275c78d08cb): Error starting userland proxy: listen tcp 127.0.0.1:9042: bind: address already in use
16:02:25.931 ERROR [docker-compose] - Encountered errors while bringing up the project.
org.testcontainers.containers.ContainerLaunchException: Local Docker Compose exited abnormally with code 1 whilst running command: up -d
at org.testcontainers.containers.LocalDockerCompose.start(DockerComposeContainer.java:503)
at org.testcontainers.containers.DockerComposeContainer.createServices(DockerComposeContainer.java:127)
at org.testcontainers.containers.DockerComposeContainer.starting(DockerComposeContainer.java:109)
at org.testcontainers.containers.FailureDetectingExternalResource$1.evaluate(FailureDetectingExternalResource.java:28)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
The text was updated successfully, but these errors were encountered:
tbcs
added a commit
to tbcs/testcontainers-java
that referenced
this issue
May 4, 2017
If
FailureDetectingExternalResource::starting
throws an exception thenFailureDetectingExternalResource::finished
won't get invoked. This affects cleanup routines implemented in subclasses, such as inDockerComposeContainer::finished
. An exception instarting()
can lead to lingering Docker containers and networks.Steps to reproduce
Define a service via docker-compose that exposes a service port to the host which is already in use (in this example it's a Cassandra server listening on localhost's TCP port 9042). Add another service to the docker-compose definition -- this is the container that will be left over after a failed start (in this example it's a Redis container). Run a unit test using a DockerComposeContainer with the said docker-compose service definition. Observe the lingering container after the unit test finished.
docker-compose service definition:
unit test:
log output of unit test:
The text was updated successfully, but these errors were encountered: