rieckpil / testing-spring-boot-applications-masterclass

šŸƒ Build Better Spring Boot Applications: A Comprehensive Testing Course to Boost Your Confidence and Productivity.
https://rieckpil.de/testing-spring-boot-applications-masterclass/
MIT License
306 stars 234 forks source link

Problems with web tests and DockerComposeContainer #305

Closed alexrodriguez closed 1 year ago

alexrodriguez commented 1 year ago

Hello,

First let me thank you for the course content. I enjoyed it very much. I'm having an issue with DockerComposeContainer and I hope you can help me.

My environment:

The issue is while running web-tests both ReviewCreationWT and ReviewCreationPageObjectsWT fail with the following error:

17:16:18.365 [Thread-46] INFO  šŸ³ [docker-compose] - Container de8cbjkxk6bq-database-1  Starting
17:16:18.373 [Thread-46] INFO  šŸ³ [docker-compose] - Container de8cbjkxk6bq-keycloak-1  Starting
17:16:18.982 [Thread-46] INFO  šŸ³ [docker-compose] - Container de8cbjkxk6bq-database-1  Started
17:16:19.130 [Thread-46] INFO  šŸ³ [docker-compose] - Container de8cbjkxk6bq-keycloak-1  Started
17:16:19.136 [Thread-46] INFO  šŸ³ [docker-compose] - Container de8cbjkxk6bq-sqs-1  Started
17:16:19.149 [main] INFO  šŸ³ [docker-compose] - Docker Compose has finished running
17:16:19.150 [main] INFO  šŸ³ [alpine/socat:1.7.4.3-r0] - Creating container for image: alpine/socat:1.7.4.3-r0
17:16:19.201 [main] ERROR šŸ³ [alpine/socat:1.7.4.3-r0] - Could not start container
org.testcontainers.containers.ContainerLaunchException: Aborting attempt to link to container de8cbjkxk6bq_database_1 as it is not running
        at org.testcontainers.containers.GenericContainer.applyConfiguration(GenericContainer.java:828)
        at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:378)
        at org.testcontainers.containers.GenericContainer.lambda$doStart$0(GenericContainer.java:344)
        at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:81)
        at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:334)
        at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:322)
        at org.testcontainers.containers.DockerComposeContainer.startAmbassadorContainers(DockerComposeContainer.java:359)
        at org.testcontainers.containers.DockerComposeContainer.start(DockerComposeContainer.java:190)
        at de.rieckpil.courses.AbstractWebTest.<clinit>(AbstractWebTest.java:50)
        at java.base/jdk.internal.misc.Unsafe.ensureClassInitialized0(Native Method)
        at java.base/jdk.internal.misc.Unsafe.ensureClassInitialized(Unsafe.java:1155)
        at java.base/jdk.internal.reflect.UnsafeFieldAccessorFactory.newFieldAccessor(UnsafeFieldAccessorFactory.java:42)
        at java.base/jdk.internal.reflect.ReflectionFactory.newFieldAccessor(ReflectionFactory.java:185)
        at java.base/java.lang.reflect.Field.acquireFieldAccessor(Field.java:1132)
        at java.base/java.lang.reflect.Field.getFieldAccessor(Field.java:1113)
        at java.base/java.lang.reflect.Field.get(Field.java:425)
        at org.junit.platform.commons.util.ReflectionUtils.lambda$tryToReadFieldValue$5(ReflectionUtils.java:671)
        at org.junit.platform.commons.function.Try.lambda$call$0(Try.java:57)
        at org.junit.platform.commons.function.Try.of(Try.java:93)
        at org.junit.platform.commons.function.Try.call(Try.java:57)
        at org.junit.platform.commons.util.ReflectionUtils.tryToReadFieldValue(ReflectionUtils.java:671)
        at org.junit.jupiter.engine.descriptor.ExtensionUtils.lambda$registerExtensionsFromFields$4(ExtensionUtils.java:106)
        at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
        at java.base/java.util.stream.SortedOps$SizedRefSortingSink.end(SortedOps.java:357)
        at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:510)
        at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
        at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
        at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
        at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
        at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
        at org.junit.jupiter.engine.descriptor.ExtensionUtils.registerExtensionsFromFields(ExtensionUtils.java:98)
        at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.prepare(ClassBasedTestDescriptor.java:150)
        at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.prepare(ClassBasedTestDescriptor.java:80)
        at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$prepare$2(NodeTestTask.java:123)
        at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
        at org.junit.platform.engine.support.hierarchical.NodeTestTask.prepare(NodeTestTask.java:123)
        at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:90)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
        at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
        at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
        at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
        at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
        at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
        at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
        at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
        at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
        at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
        at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35)
        at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
        at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54)
        at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:107)
        at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88)
        at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54)
        at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67)
        at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52)
        at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:114)
        at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86)
        at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86)
        at org.apache.maven.surefire.junitplatform.LazyLauncher.execute(LazyLauncher.java:55)
        at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.execute(JUnitPlatformProvider.java:223)
        at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.invokeAllTests(JUnitPlatformProvider.java:175)
        at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.invoke(JUnitPlatformProvider.java:139)
        at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:456)
        at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:169)
        at org.apache.maven.surefire.booter.ForkedBooter.run(ForkedBooter.java:595)
        at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:581)
[INFO] Running de.rieckpil.courses.book.review.ReviewCreationWT
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0 s <<< FAILURE! - in de.rieckpil.courses.book.review.ReviewCreationWT
[ERROR] de.rieckpil.courses.book.review.ReviewCreationWT  Time elapsed: 0 s  <<< ERROR!

Thanks for your help!

rieckpil commented 1 year ago

Hey Alex šŸ‘‹ thanks for reaching out :)

That issue might be a pending Testcontainers issue to support Compose v2, see:

I assume the underscore de8cbjkxk6bq_database_1 may be the issue here.

Are you using the latest state on the main branch? I've added there .withOptions("--compatibility") to the AbstractWebTest class and the DockerCompose setup, which should do the trick.

alexrodriguez commented 1 year ago

Hey, Thanks for the assist... I was working of the master branch... changing to main solves the problem. Thanks again, and keep the good content coming. I appreciate it.