https://kotlinlang.org logo
Title
t

tim

09/14/2021, 12:33 PM
Hello not sure if i should ask in here or in the testcontainers slack so apologies if this is in the wrong place. i'm using tests containers + kotest for integration tests (mongo + kafka containers). I'm finding that the first integration test passes, but subsequent tests are failing because the host machine ports are now unavailable. Everything works in isolation, its only when all my integration tests are run that the issue pops up. I've tried putting in a short delay after the containers are told to stop but it doesn't seem to work. Any suggestions?
l

LeoColman

09/14/2021, 1:23 PM
Can you try changing the IsolationMode to InstancePertTest and check if things work/
t

tim

09/14/2021, 2:09 PM
yep two sec
s

sam

09/14/2021, 2:12 PM
Also sample code helps
t

tim

09/14/2021, 2:14 PM
Sadly setting the isolation mode doesn't seem to change it
lemme upload a gist to gh
Okay uploaded a gist with the typical setup here - https://gist.github.com/tim-hm/c703716126f998f8247514f9c8503c6a We've created a base IntegrationSpec that all of our integration tests inherit from ... the integration spec is responsible for starting/stopping the app and needed infra. When running these tests, the first integration spec passes and subsequent tests fail due to the port issue. Tests pass when run standalone.
s

sam

09/14/2021, 2:21 PM
When you say one passes do you mean one spec entirely or one test in each spec
t

tim

09/14/2021, 2:22 PM
One spec entirely
s

sam

09/14/2021, 2:24 PM
What's the error you get
t

tim

09/14/2021, 2:59 PM
15:58:52.706 [pool-1-thread-1] INFO  🐳 [confluentinc/cp-kafka:6.2.0] - Creating container for image: confluentinc/cp-kafka:6.2.0
15:58:52.766 [pool-1-thread-1] INFO  🐳 [confluentinc/cp-kafka:6.2.0] - Starting container with ID: 999ff788b655fab8358f3ab76353c055c8b0b40518bf7219ebed31e488539ba1
15:58:52.869 [pool-1-thread-1] ERROR 🐳 [confluentinc/cp-kafka:6.2.0] - Could not start container
com.github.dockerjava.api.exception.InternalServerErrorException: Status 500: {"message":"driver failed programming external connectivity on endpoint pedantic_fermi (7a1e6a574f534347cbcb08e635677b9ff74133eb1790bcb9b5e9e5ae617591a6): Bind for 0.0.0.0:9093 failed: port is already allocated"}

	at org.testcontainers.shaded.com.github.dockerjava.core.DefaultInvocationBuilder.execute(DefaultInvocationBuilder.java:247)
	at <http://org.testcontainers.shaded.com.github.dockerjava.core.DefaultInvocationBuilder.post|org.testcontainers.shaded.com.github.dockerjava.core.DefaultInvocationBuilder.post>(DefaultInvocationBuilder.java:102)
	at org.testcontainers.shaded.com.github.dockerjava.core.exec.StartContainerCmdExec.execute(StartContainerCmdExec.java:31)
	at org.testcontainers.shaded.com.github.dockerjava.core.exec.StartContainerCmdExec.execute(StartContainerCmdExec.java:13)
	at org.testcontainers.shaded.com.github.dockerjava.core.exec.AbstrSyncDockerCmdExec.exec(AbstrSyncDockerCmdExec.java:21)
	at org.testcontainers.shaded.com.github.dockerjava.core.command.AbstrDockerCmd.exec(AbstrDockerCmd.java:35)
	at org.testcontainers.shaded.com.github.dockerjava.core.command.StartContainerCmdImpl.exec(StartContainerCmdImpl.java:43)
	at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:423)
	at org.testcontainers.containers.GenericContainer.lambda$doStart$0(GenericContainer.java:329)
	at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:81)
	at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:327)
	at org.testcontainers.containers.KafkaContainer.doStart(KafkaContainer.java:97)
	at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:315)
	at glimpse.commons.testing.kotest.IntegrationSpec$2.invokeSuspend(IntegrationSpec.kt:67)
	at glimpse.commons.testing.kotest.IntegrationSpec$2.invoke(IntegrationSpec.kt)
	at glimpse.commons.testing.kotest.IntegrationSpec$2.invoke(IntegrationSpec.kt)
	at io.kotest.core.TestConfiguration$beforeSpec$1.beforeSpec(TestConfiguration.kt:250)
	at io.kotest.core.spec.LifecycleKt.invokeBeforeSpec(lifecycle.kt:141)
	at io.kotest.engine.spec.runners.SingleInstanceSpecRunner$execute$3.invokeSuspend(SingleInstanceSpecRunner.kt:63)
	at io.kotest.engine.spec.runners.SingleInstanceSpecRunner$execute$3.invoke(SingleInstanceSpecRunner.kt)
	at io.kotest.engine.spec.runners.SingleInstanceSpecRunner$execute$3.invoke(SingleInstanceSpecRunner.kt)
	at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:89)
	at kotlinx.coroutines.CoroutineScopeKt.coroutineScope(CoroutineScope.kt:264)
	at io.kotest.engine.spec.runners.SingleInstanceSpecRunner.execute(SingleInstanceSpecRunner.kt:62)
	at io.kotest.engine.spec.SpecExecutor$runTests$run$1.invokeSuspend(SpecExecutor.kt:87)
	at io.kotest.engine.spec.SpecExecutor$runTests$run$1.invoke(SpecExecutor.kt)
	at io.kotest.engine.spec.SpecExecutor$runTests$run$1.invoke(SpecExecutor.kt)
	at io.kotest.engine.spec.SpecExecutor.interceptSpec(SpecExecutor.kt:101)
	at io.kotest.engine.spec.SpecExecutor.runTests(SpecExecutor.kt:92)
	at io.kotest.engine.spec.SpecExecutor.runTestsIfAtLeastOneEnabled(SpecExecutor.kt:72)
	at io.kotest.engine.spec.SpecExecutor.execute(SpecExecutor.kt:41)
	at io.kotest.engine.launchers.DefaultSpecLauncher$sequential$3$1$2.invokeSuspend(DefaultSpecLauncher.kt:56)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
	at java.base/java.lang.Thread.run(Thread.java:831)
15:58:52.873 [pool-1-thread-1] ERROR 🐳 [confluentinc/cp-kafka:6.2.0] - There are no stdout/stderr logs available for the failed container
s

sam

09/14/2021, 3:08 PM
Looks to me like it's not shutting down properly and so the port is still in use when the next spec tries to start it up
I know you tried a delay, but if you put in like a 10 minute delay, and then it works, then it's probably shutdown related
maybe put the delay in the beforeSpec of the 2nd spec
t

tim

09/14/2021, 8:14 PM
good suggestion 🙏 will try that in the morning
got pulled away to other tasks i think the issues is with our code in that some resources aren't being closed properly as some projects that don't include those resources don't have the same issue