Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postgres module wait condition is inaccurate #158

Closed
jrudolph opened this issue Jul 3, 2024 · 5 comments · Fixed by #162
Closed

Postgres module wait condition is inaccurate #158

jrudolph opened this issue Jul 3, 2024 · 5 comments · Fixed by #162

Comments

@jrudolph
Copy link

jrudolph commented Jul 3, 2024

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".

@DDtKey
Copy link
Contributor

DDtKey commented Jul 3, 2024

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

@jrudolph
Copy link
Author

jrudolph commented Jul 3, 2024

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

@DDtKey DDtKey transferred this issue from testcontainers/testcontainers-rs Jul 3, 2024
@DDtKey
Copy link
Contributor

DDtKey commented Jul 3, 2024

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

Thanks one more time!

@DDtKey
Copy link
Contributor

DDtKey commented Jul 7, 2024

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
Copy link

jkp commented Jul 31, 2024

I think this is an issue in python too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants