As described in another question here I'm trying to integrate Testcontainers into a Java / Spring Boot projects for our tests. After failing to get this to work with a generic SQL Server image, I started using our 'custom' image, which basically just creates the database we need.
I'm using testcontainers 1.19.4 with JUnit 5, so my Test class has the @Testcontainers annotation and the container is annotated with @Container.
The problem seems to be the container wait strategy - testcontainers waits for a log message that contains the string 'Started'. I've seen the container logs, and the containers starts just fine but this log message is just never shown.
I tried changing the wait strategy when creating the container, either by using the waitingFor() method on creation or by explicitly setting the wait strategy with setWaitStrategy() in an init method. Currently I have the following code:
@Container
private final static MSSQLServerContainer container = initMSSQLContainer();
static MSSQLServerContainer initMSSQLContainer() {
MSSQLServerContainer tmp = new MSSQLServerContainer<>(DockerImageName
.parse("<custom-image-name>")
.asCompatibleSubstituteFor("mcr.microsoft.com/mssql/server"))
.acceptLicense();
tmp.setWaitStrategy(new LogMessageWaitStrategy().withRegEx(".*SQL Server is now ready for client connections.*")
.withStartupTimeout(Duration.of(180, ChronoUnit.SECONDS )));
return tmp;
}
I know that this message is logged at some point. But the error message does not change. The stacktrace:
Caused by: org.testcontainers.containers.ContainerLaunchException: Timed out waiting for log output matching '.*Started.*'
at org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy.waitUntilReady(LogMessageWaitStrategy.java:47)
at org.testcontainers.containers.wait.strategy.AbstractWaitStrategy.waitUntilReady(AbstractWaitStrategy.java:52)
at org.testcontainers.containers.GenericContainer.waitUntilContainerStarted(GenericContainer.java:912)
at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:503)
... 67 more
So it seems that the wait strategy change is not picked up?
The error is most probably related NOT to your MSSQL container, but to an internal RyukContainer from Testcontainers library. See this line.
You should check more details in the logs. I'd guess Testcontainers didn't detect your local docker environment properly. You might need to provide some custom configuration.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With