I have written a functional tests which uses mock containers using TestContainers.
When I am running a complete application test using ./gradlew clean build
, still the error appears in console but only once (I believe before executing first functional tests) but it doesn't make any of my test Failed. However when I run them individually, I see some of the Functional Tests failed with this error.
For the sake of simplicity I have created simple test as below:
SampleE2ETest.java:
@MicronautTest(transactional = false)
@ExtendWith(MockitoExtension.class)
public class SampleE2ETest extends ContainerBaseTest {
@Test
void sampleTest() {
assertThat("sadas").isEqualTo("asa");
}
}
ContainerBaseTest.java
@Testcontainers
@Tag("integration")
@Tag("docker")
@Slf4j
public abstract class ContainerBaseTest {
static DockerComposeContainer CONTAINER;
public ContainerBaseTest() {
if (CONTAINER == null) {
final WaitStrategy waitStrategy = Wait.forListeningPort().withStartupTimeout(Duration.ofMinutes(2));
Slf4jLogConsumer logConsumer = new Slf4jLogConsumer(log);
log.info("Starting testcontainers...");
CONTAINER = new DockerComposeContainer(new File("docker-compose.yml"))
// Without cron
.withExposedService("app1_1", 2929, waitStrategy).withLogConsumer("app1_1",logConsumer)
.withExposedService("app2_1", 8065, waitStrategy).withLogConsumer("app2_1",logConsumer)
.withExposedService("app3_1", 8090, waitStrategy).withLogConsumer("app3_1",logConsumer)
.withExposedService("app4_1", 9339, waitStrategy).withLogConsumer("app4_1",logConsumer)
.withExposedService("app5_1", 2222, waitStrategy).withLogConsumer("app5_1",logConsumer)
.withExposedService("app6_1", 18080, waitStrategy).withLogConsumer("app6_1",logConsumer)
.withExposedService("app7_1", 9090, waitStrategy).withLogConsumer("app7_1",logConsumer)
.withLocalCompose(true);
CONTAINER.start();
log.info("testcontainers started.");
}
}
}
Above test is getting failed with below error:
18:01:38.913 [Thread-9] INFO 🐳 [docker-compose] - Container k5bii89amzd5-app4-1 Creating
18:01:38.914 [Thread-9] INFO 🐳 [docker-compose] - Container k5bii89amzd5-app6-1 Creating
18:01:38.914 [Thread-9] INFO 🐳 [docker-compose] - Container k5bii89amzd5-app1-1 Creating
18:01:38.914 [Thread-9] INFO 🐳 [docker-compose] - Container k5bii89amzd5-app3-1 Creating
18:01:38.914 [Thread-9] INFO 🐳 [docker-compose] - Container k5bii89amzd5-app7-1 Creating
18:01:38.914 [Thread-9] INFO 🐳 [docker-compose] - Container k5bii89amzd5-app5-1 Creating
18:01:38.915 [Thread-9] INFO 🐳 [docker-compose] - Container k5bii89amzd5-cron-1 Creating
18:01:38.915 [Thread-9] INFO 🐳 [docker-compose] - Container k5bii89amzd5-app2-1 Creating
18:01:39.002 [Thread-9] INFO 🐳 [docker-compose] - Container k5bii89amzd5-cron-1 Created
18:01:39.006 [Thread-9] INFO 🐳 [docker-compose] - Container k5bii89amzd5-app6-1 Created
18:01:39.007 [Thread-9] INFO 🐳 [docker-compose] - Container k5bii89amzd5-app7-1 Created
18:01:39.009 [Thread-9] INFO 🐳 [docker-compose] - Container k5bii89amzd5-app2-1 Created
18:01:39.011 [Thread-9] INFO 🐳 [docker-compose] - Container k5bii89amzd5-app4-1 Created
18:01:39.014 [Thread-9] INFO 🐳 [docker-compose] - Container k5bii89amzd5-app1-1 Created
18:01:39.017 [Thread-9] INFO 🐳 [docker-compose] - Container k5bii89amzd5-app5-1 Created
18:01:39.017 [Thread-9] INFO 🐳 [docker-compose] - Container k5bii89amzd5-app3-1 Created
18:01:39.022 [Thread-9] INFO 🐳 [docker-compose] - Container k5bii89amzd5-app1-1 Starting
18:01:39.023 [Thread-9] INFO 🐳 [docker-compose] - Container k5bii89amzd5-app7-1 Starting
18:01:39.024 [Thread-9] INFO 🐳 [docker-compose] - Container k5bii89amzd5-cron-1 Starting
18:01:39.024 [Thread-9] INFO 🐳 [docker-compose] - Container k5bii89amzd5-app2-1 Starting
18:01:39.025 [Thread-9] INFO 🐳 [docker-compose] - Container k5bii89amzd5-app5-1 Starting
18:01:39.027 [Thread-9] INFO 🐳 [docker-compose] - Container k5bii89amzd5-app6-1 Starting
18:01:39.028 [Thread-9] INFO 🐳 [docker-compose] - Container k5bii89amzd5-app4-1 Starting
18:01:39.029 [Thread-9] INFO 🐳 [docker-compose] - Container k5bii89amzd5-app3-1 Starting
18:01:39.546 [Thread-9] INFO 🐳 [docker-compose] - Container k5bii89amzd5-cron-1 Started
18:01:39.637 [Thread-9] INFO 🐳 [docker-compose] - Container k5bii89amzd5-app1-1 Started
18:01:39.746 [Thread-9] INFO 🐳 [docker-compose] - Container k5bii89amzd5-app3-1 Started
18:01:39.908 [Thread-9] INFO 🐳 [docker-compose] - Container k5bii89amzd5-app2-1 Started
18:01:39.914 [Thread-9] INFO 🐳 [docker-compose] - Container k5bii89amzd5-app6-1 Started
18:01:39.955 [Thread-9] INFO 🐳 [docker-compose] - Container k5bii89amzd5-app7-1 Started
18:01:40.010 [Thread-9] INFO 🐳 [docker-compose] - Container k5bii89amzd5-app5-1 Started
18:01:40.030 [Thread-9] INFO 🐳 [docker-compose] - Container k5bii89amzd5-app4-1 Started
18:01:40.044 [Test worker] DEBUG o.t.s.o.z.exec.WaitForProcess - Process[pid=45511, exitValue=0] stopped with exit code 0
18:01:40.046 [Test worker] INFO 🐳 [docker-compose] - Docker Compose has finished running
18:01:40.050 [Test worker] DEBUG o.t.u.PrefixingImageNameSubstitutor - No prefix is configured
18:01:40.051 [Test worker] DEBUG o.t.utility.ImageNameSubstitutor - Did not find a substitute image for alpine/socat:1.7.3.4-r0 (using image substitutor: DefaultImageNameSubstitutor (composite of 'ConfigurationFileImageNameSubstitutor' and 'PrefixingImageNameSubstitutor'))
18:01:40.054 [Test worker] DEBUG o.t.s.c.g.d.c.command.AbstrDockerCmd - Cmd: ListImagesCmdImpl[imageNameFilter=<null>,showAll=false,filters=org.testcontainers.shaded.com.github.dockerjava.core.util.FiltersBuilder@0]
18:01:40.203 [Test worker] DEBUG o.t.images.AbstractImagePullPolicy - Using locally available and not pulling image: alpine/socat:1.7.3.4-r0
18:01:40.204 [Test worker] DEBUG 🐳 [alpine/socat:1.7.3.4-r0] - Starting container: alpine/socat:1.7.3.4-r0
18:01:40.204 [Test worker] DEBUG 🐳 [alpine/socat:1.7.3.4-r0] - Trying to start container: alpine/socat:1.7.3.4-r0 (attempt 1/1)
18:01:40.205 [Test worker] DEBUG 🐳 [alpine/socat:1.7.3.4-r0] - Starting container: alpine/socat:1.7.3.4-r0
18:01:40.205 [Test worker] INFO 🐳 [alpine/socat:1.7.3.4-r0] - Creating container for image: alpine/socat:1.7.3.4-r0
18:01:40.205 [Test worker] DEBUG o.t.utility.RegistryAuthLocator - Looking up auth config for image: alpine/socat:1.7.3.4-r0 at registry: index.docker.io
18:01:40.206 [Test worker] DEBUG o.t.utility.RegistryAuthLocator - No matching Auth Configs - falling back to defaultAuthConfig [null]
18:01:40.206 [Test worker] DEBUG o.t.d.AuthDelegatingDockerClientConfig - Effective auth config [null]
18:01:40.211 [Test worker] DEBUG o.t.s.c.g.d.c.command.AbstrDockerCmd - Cmd: -1,<null>,false,<null>,<null>,org.testcontainers.shaded.com.github.dockerjava.core.util.FiltersBuilder@96a2da2c
18:01:40.244 [Test worker] ERROR 🐳 [alpine/socat:1.7.3.4-r0] - Could not start container
org.testcontainers.containers.ContainerLaunchException: Aborting attempt to link to container k5bii89amzd5_app7_1 as it is not running
at org.testcontainers.containers.GenericContainer.applyConfiguration(GenericContainer.java:779)
at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:359)
at org.testcontainers.containers.GenericContainer.lambda$doStart$0(GenericContainer.java:325)
at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:81)
at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:323)
Container startup failed
org.testcontainers.containers.ContainerLaunchException: Container startup failed
at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:330)
at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:311)
at org.testcontainers.containers.DockerComposeContainer.startAmbassadorContainers(DockerComposeContainer.java:331)
at org.testcontainers.containers.DockerComposeContainer.start(DockerComposeContainer.java:178)
Caused by: org.rnorth.ducttape.RetryCountExceededException: Retry limit hit with exception
at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:88)
at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:323)
... 96 more
Caused by: org.testcontainers.containers.ContainerLaunchException: Could not create/start container
at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:497)
at org.testcontainers.containers.GenericContainer.lambda$doStart$0(GenericContainer.java:325)
at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:81)
... 97 more
Caused by: org.testcontainers.containers.ContainerLaunchException: Aborting attempt to link to container k5bii89amzd5_app7_1 as it is not running
at org.testcontainers.containers.GenericContainer.applyConfiguration(GenericContainer.java:779)
at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:359)
TestContainer and Junit Dependencies in gradle file
testImplementation("io.micronaut.test:micronaut-test-junit5")
testImplementation("org.junit.jupiter:junit-jupiter-api")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
testImplementation("org.testcontainers:testcontainers:1.15.2")
testImplementation("org.testcontainers:junit-jupiter:1.15.2")
testImplementation("org.junit.jupiter:junit-jupiter-params")
Not sure why it shouldn't work with DockerComposeContainer but moving from DockerComposeContainer to ComposeContainer seems to have solved the issue.
https://github.com/testcontainers/testcontainers-java/issues/7644
https://java.testcontainers.org/modules/docker_compose/#compose-v2