testcontainers / testcontainers/testcontainers-java
Container restart retried without waiting
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 8.7k
- Forks
- 1.9k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 9
Description
Hi, I started using TestContainers today. It simplifies the work a lot! 🎉
However, I'm facing a problem with version 1.9.1 with MySQLContainer.
When I run the tests locally it works like a charm. However, in another computer it is trying to spawn 3 instances of the container without waiting between attempts. This is happening because an exception happened before the wait strategy could be invoked.
The exception in my case is the following:
java.lang.IllegalStateException: copyFileToContainer can only be used with created / running container
at org.testcontainers.containers.GenericContainer.copyFileToContainer(GenericContainer.java:1075)
at org.testcontainers.containers.GenericContainer.copyFileToContainer(GenericContainer.java:1067)
at java.util.HashMap.forEach(HashMap.java:1289)
at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:262)
at org.testcontainers.containers.GenericContainer.lambda$doStart$0(GenericContainer.java:237)
at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:76)
at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:235)
at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:220)
at org.testcontainers.containers.GenericContainer.starting(GenericContainer.java:738)
at org.testcontainers.containers.FailureDetectingExternalResource$1.evaluate(FailureDetectingExternalResource.java:29)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:365)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:273)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:238)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:159)
at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:379)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:340)
at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:125)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:413)
As you can see, it is thrown, from GenericContainer#tryStart, before reaching the invocation of the retry strategy.
It looks like it might be caused by the container not being started yet. So maybe it is taking some milliseconds more in that computer. So maybe executing the wait strategy before the copy operation starts might help.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in GenericContainer#tryStart, using the stack trace to inspect the retry path around copyFileToContainer and the wait strategy. Confirm the retry behavior when startup throws before the wait strategy is invoked; done means retries no longer spawn containers without waiting.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, java
- Domain
- devops, testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100