testcontainers/testcontainers-rs-modules-community

Postgres module wait condition is inaccurate

Closed this issue · 5 comments

As already mentioned in testcontainers/testcontainers-rs#533, the postgres module does not sufficiently wait until the container is started up completely. The reason is a peculiarity of the postgres container setup which, with default settings, runs an init script that does a "pre-run" of the database but then restarts the database (as you also can see in the logs of testcontainers/testcontainers-rs#533).

Therefore, the existing wait strategy to wait for the string "database system is ready to accept connections" is not enough because it will trigger during the init script run after which the DB will still restart and be unreachable for a short time.

In testcontainers-java this is accounted for by setting withTimes(2) (https://github.com/testcontainers/testcontainers-java/blob/1f38f0d9604edb9e89fd3b3ee1eff6728e2d1e07/modules/postgresql/src/main/java/org/testcontainers/containers/PostgreSQLContainer.java#L60-L65)

Since testcontainers-rs does not seem to support withTimes, one workaround is to look for "port 5423" (init script only binds to a unix socket). It would probably better to implement withTimes or use a regex that only triggers after the second output of "database system is ready to accept connections".

Hi @jrudolph!

Thank you for the report!

I'm currently working on refactoring log consumers and changing underlying logic for wait strategies.
I think it's a right thing to support wait_times() here. I'll try to incorporate this into the next release

For now, we can consider a workaround, but Postgres module isn't part of testcontainers core crate - it's placed in modules

Thanks for the quick response. Can you move the ticket to the correct repo?

I've opened a feature request for this and transferred the issue to testcontainers-rs-modules-community

Thanks one more time!

It turns out there was no need to introduce with_times (even though, it was released as pasrt of testcontainers: 0.20.0)
Java uses with_times without stream filter (i.e checks both stderr and stdout)

In fact, postgres uses different standard streams for the two runs. So we need to expect "the database system is ready to accept connections" once on stdout and once on stderr.

Closed with #162

jkp commented

I think this is an issue in python too