Possible race condition with JUnit 5 in 1.16.1 and 1.16.2
See original GitHub issueWhen trying to upgrade from 1.15.3
to 1.16.2
we encountered an issue breaking our tests that might be a race condition.
It seems that connecting to the exposed port is not possible yet when the test cases are executed. Adding timeouts to the @BeforeEach
method does reduce these errors which would suggest a race condition here.
I did have a look at PR 4597 and the linked issues. Maybe these could be related but cannot say for sure.
So far I have not been able to create a local reproducer but adding debug logging produces the following output:
[main] INFO 🐳 [rabbitmq:3.8] - Creating container for image: rabbitmq:3.8
[main] INFO 🐳 [rabbitmq:3.8] - Starting container with ID: 633fc3b2f14fb048fd089b805c2596cba8d36358e5802af6e78075f50cfecc96
[main] INFO 🐳 [rabbitmq:3.8] - Container rabbitmq:3.8 is starting: 633fc3b2f14fb048fd089b805c2596cba8d36358e5802af6e78075f50cfecc96
[main] INFO 🐳 [rabbitmq:3.8] - Container rabbitmq:3.8 started in PT4.845S
[AMQP Connection 127.0.0.1:49668] WARN com.rabbitmq.client.impl.ForgivingExceptionHandler - An unexpected connection driver error occurred (Exception message: Connection reset)
[main] INFO 🐳 [rabbitmq:3.8] - Creating container for image: rabbitmq:3.8
[main] INFO 🐳 [rabbitmq:3.8] - Starting container with ID: 57d3b35f8cba584142d5efc0c69c1864802b3c977cefddf815cd415b972af66f
[main] INFO 🐳 [rabbitmq:3.8] - Container rabbitmq:3.8 is starting: 57d3b35f8cba584142d5efc0c69c1864802b3c977cefddf815cd415b972af66f
[main] INFO 🐳 [rabbitmq:3.8] - Container rabbitmq:3.8 started in PT5.483S
[main] INFO 🐳 [rabbitmq:3.8] - Creating container for image: rabbitmq:3.8
[main] INFO 🐳 [rabbitmq:3.8] - Starting container with ID: 364373afe9fed9056c0314b75709b76a5013c1f7d375089c2329d51686cba14e
[main] INFO 🐳 [rabbitmq:3.8] - Container rabbitmq:3.8 is starting: 364373afe9fed9056c0314b75709b76a5013c1f7d375089c2329d51686cba14e
[main] INFO 🐳 [rabbitmq:3.8] - Container rabbitmq:3.8 started in PT5.912S
This shows a run of three tests starting a container with a rabbitmq:3.8
image, in our tests we try to connect to that container during the @BeforeEach
setup method (Moving this call to the actual test method did not solve the issue). The first test results in an error where as the other two complete successfully. We have also seen runs with all three tests failing.
From the log output it would seem the container is up and running before the test gets executed, the actual behaviour suggests differently. With 1.16.0
or 1.15.3
we did not observe any similar issues.
Connection reset
could also imply that the container was shutting down again already but that would be unexpected during the test setup and adding timeout at the start of the setup method should not have an effect on it.
Changing to a shared container instance for all tests did also not solve the issue.
Please let me know if you require any further information.
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (4 by maintainers)
Indeed using
RabbitMQContainer
seems to solve the issue. It is interesting that this has never had an impact before.Thanks a lot for your help and sorry for this inconvenience.
Awesome, great that it works for you now 👍