Testcontainers-java: MongoDBContainer fails to start when using tag 4.4

Created on 3 Aug 2020  ·  5Comments  ·  Source: testcontainers/testcontainers-java

Testcontainers version: 1.14.3.

A container initialized as follows, fails to start with this error: ContainerLaunchException: Timed out waiting for log output matching '.*waiting for connections on port.*'

val container = new MongoDBContainer("mongo:4.4");
container.start()

I suppose it happens because MongoDBContainer waits a message that matches waiting for connections on port to appear in logs.

However, Mongo 4.4 logs contain only this message: Waiting for connections (without on port).

You can find full Mongo container logs here: mongo-container-logs.txt

mongo:4.2 image works good.
mongo:4.3 image simply doesn't exist.

modulemongodb resolutioacknowledged resolutiopr-submitted typbug

Most helpful comment

@vcvitaly is correct, this is about the change in the log format (which we actually already briefly discussed in Slack).

Starting in MongoDB 4.4, mongod / mongos instances now output all log messages in structured JSON format. Log entries are written as a series of key-value pairs, where each key indicates a log message field type, such as “severity”, and each corresponding value records the associated logging information for that field type, such as “informational”.

Besides from the JSON log format, the field now contains the following string (note the capital W):

Waiting for connections

The regex should probably be changed to

Wait.forLogMessage("(?i).*waiting for connections", 1)

in order to support both versions. Can you try this out @remal? If it works, feel free to submit a PR to fix this use.

@vcvitaly

I see that many tests are using static tags. Do you think tests should be ran against the 'latest' tag?

I don't think this is a good idea since we have no control over what happens with the latest images. The only reasonable thing Testcontainers can guarantee is support for certain fixed image versions that comply with our implicit image expectations and constraints.

All 5 comments

Also, note the capital W in "Waiting for connections".

Naturally, this problem also affects use of the mongo:4 image.

The log format has been changed in 4.4 indeed.

@remal please try overriding the wait strategy

new MongoDBContainer("mongo:4.4").
       waitingFor(
            Wait.forLogMessage(".*waiting for connections", 1)
        )

@bsideup @rnorth @kiview
The similar issue was described in https://github.com/testcontainers/testcontainers-java/issues/2984 where the latest image failed as well for _mock-server_.

I see that many tests are using static tags. Do you think tests should be ran against the 'latest' tag?

@vcvitaly is correct, this is about the change in the log format (which we actually already briefly discussed in Slack).

Starting in MongoDB 4.4, mongod / mongos instances now output all log messages in structured JSON format. Log entries are written as a series of key-value pairs, where each key indicates a log message field type, such as “severity”, and each corresponding value records the associated logging information for that field type, such as “informational”.

Besides from the JSON log format, the field now contains the following string (note the capital W):

Waiting for connections

The regex should probably be changed to

Wait.forLogMessage("(?i).*waiting for connections", 1)

in order to support both versions. Can you try this out @remal? If it works, feel free to submit a PR to fix this use.

@vcvitaly

I see that many tests are using static tags. Do you think tests should be ran against the 'latest' tag?

I don't think this is a good idea since we have no control over what happens with the latest images. The only reasonable thing Testcontainers can guarantee is support for certain fixed image versions that comply with our implicit image expectations and constraints.

With 4.4.1 this worked for me:
waitingFor( Wait.forLogMessage(".*Waiting for connections*.*", 1) )

I generally use HostPortWaitStrategy which does not rely on the internals of the image in use.
For example;
new MongoDBContainer(mongoVersion) .waitingFor(Wait.forListeningPort().withStartupTimeout(Duration.ofSeconds(30)));

With this, you don't have to keep changing your regex every time mongodb decides to change their log message.

I would love to know if there is any practical difference between LogMessageWaitStrategy vs HostPortWaitStrategy (in the context of MongoDBContainer).

Was this page helpful?
0 / 5 - 0 ratings