-
-
Notifications
You must be signed in to change notification settings - Fork 451
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
docs(postgres): recommend ForSQL strategy #2208
Conversation
✅ Deploy Preview for testcontainers-go ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Thanks for this PR! I'm interested in how you discovered it: is it that you copied the example from pkg.go.dev? |
No, there is a dedicated documentation page for that strategy (I would link it if I wasn't on my phone). EDIT: I'm back home: https://golang.testcontainers.org/features/wait/sql/ |
7b1e83c
to
6153bd4
Compare
6153bd4
to
312a217
Compare
While trying to use a postgres containers and using ForLog(), we had a tests that worked locally, but failed on the CI, for some reason. Searching the web, one can stumble upon https://www.xavierbouclet.com/2022/08/08/TestContainer-Wait-DB-SQL.html If somebody went through the trouble of writing a whole blog post about this, chances are this issue is not uncommon. Also, the SQL strategy was contributed after the log strategy, which might explain why it wasn't default recommendation.
bf173d2
to
0daaffc
Compare
Hi, one missing thing about the shared blogpost is related to how the postgres container is started:
After that, the container and service is ready to use. The blogpost uses the default strategy, which is wait for an open port but this could be available in step 2 causing flaky tests. SQL wait strategy could cause the same. The PostgreSQLContainer implementation relies in the wait strategy instead due to an empty container logs twice the |
@eddumelendez it's unclear to me what makes you say that the postgres container is started in 4 steps rather than just 2. Would you care to elaborate? |
@greg0ire start a postgres container and see the logs to check what I mention |
Ok, I've tried it, so let me explain this a bit more to everyone else:
In case there is no database, there seems indeed to be a start and stop of the server: https://github.com/docker-library/postgres/blob/1424abf76f421d6f7bf933d9e42bbbed866fae3a/16/bookworm/docker-ensure-initdb.sh#L46C2-L51 That start is "socket only", and "does not listen on external TCP/IP". Maybe we could somehow find a way to leverage that? |
True that if the DATA_DIR is empty, PG will start "2 times". But that's why the |
I didn't experience it first hand, @joseboretto did. Let's close this so as not to waste more maintainer time on this, and open an issue if we come up with a reproducer instead. |
Thanks @greg0ire for coming back to the issue and close it 🙇 🙏 |
While trying to use a postgres containers and using ForLog(), we had a tests that worked locally, but failed on the CI, for some reason. Searching the web, one can stumble upon https://www.xavierbouclet.com/2022/08/08/TestContainer-Wait-DB-SQL.html If somebody went through the trouble of writing a whole blog post about this, chances are this issue is not uncommon.
Also, the SQL strategy was contributed after the log strategy, which might explain why it wasn't default recommendation.