Open simpletasks opened 4 months ago
I had the exact same issue when setting up a KafkaContainer along a Schema Registry container. Schema Registry container relies on environment variables configuration and one of them is the Kafka bootstrap server which needs dependency container to be running before retrieving the mapped ports.
These changes would fix this issue.
Module
Core
Proposal
When configuring test case like:
dependency will fail because the first three Testcontainers are not started and line:
.withEnv("ConnectionStrings__AzureServiceBus", "amqp://host.docker.internal:" + ACTIVE_MQ_CONTAINER.getMappedPort(5672))
will throw an error because can not read the value from the not-started container.Automated init sequence when using @Container annotation can be replaced with:
A possible solution is to defer the resolution of dependency of
ACTIVE_MQ_CONTAINER.getMappedPort(5672))
to a read stage of the dependent container (APP_SERVER container startup time).Using Supplier\<String> instead of String for type of value in Env Map. With this change, the example from above will work.
The current workaround is to start containers manually without @ Container annotation and using manually written checks 'is container started'. Containers in the test class must be declared in an ordered way. Code snippet for manual container start-check:
alternative is:
Expected behavior should be:
Last line:
.withEnv("ConnectionStrings__AzureServiceBus", "amqp://host.docker.internal:" + ACTIVE_MQ_CONTAINER.getMappedPort(5672))
replaced by deferred value retrieval:.withEnv("ConnectionStrings__AzureServiceBus", () -> "amqp://host.docker.internal:" + ACTIVE_MQ_CONTAINER.getMappedPort(5672))
ensures proper startup order when one container depends on some runtime value of another container.