-
Notifications
You must be signed in to change notification settings - Fork 70
fix: Support Postgres ready_conditions for already mounted volumes #416
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
Open
cbrevik
wants to merge
6
commits into
testcontainers:main
Choose a base branch
from
cbrevik:postgres-readiness-conditions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+22
−3
Open
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2f4f05f
fix: Support Postgres ready_conditions for already mounted volumes
cbrevik acb12e9
fix: Use truncated listening log line
cbrevik f63cad0
fix: Use pg_isready to check for readiness
cbrevik 59b26fa
nit
cbrevik 01a59a0
fix: Forgot dbname arg
cbrevik 0b92a8c
fix: Hybrid strategy, wait for pg_isready to be ready
cbrevik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's intentional to wait the message against both - as in case of not initialized DB it may lead to flakiness
See
#158
and my comment:
#415 (comment)
we may introduce separate method to specify that DB already initialized or allow configuring named volume on Image side (so it will automatically change the set of conditions)
But I don't think we should change these expectations
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would possibly doing it like
testcontainers-dotnet(usingpg_isready, introduced in psql 9.3, in 2013) be a way to support both cases without custom set of conditions for different setups?:https://github.com/testcontainers/testcontainers-dotnet/blob/1cfac505ebf33f6abb30f55c92a1839101fcb34b/src/Testcontainers.PostgreSql/PostgreSqlBuilder.cs#L138C44-L138C54
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated PR with suggestion on how to do it with
pg_isready. Followed the same pattern as the Kafka-module and did it inexec_after_start:testcontainers-rs-modules-community/src/kafka/apache.rs
Line 126 in a47c5d6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, but running tests it seems like it does not actually wait 🙈 So I guess this doesn't work like I thought it would.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Figured out the issue, container was not ready to accept connections. So adopting a hybrid strategy of checking just once for
database system is ready to accept connectionsalso then enables checking for final readiness withpg_isreadyafterwardsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm afraid that first occurrence of
database system is ready to accept connectionsstill may lead to flakiness, it might be a log of initialization andpg_isreadycan be called between init and actual startThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I thought the point of
pg_isreadythat as soon as the image is loaded that tool makes it easier to avoid flakiness. Would it be possible to have a "ready condition" that uses aExecCommand(sort of liketestcontainers-dotnet) that can be retried until exit code is a specific one? I'm thinking since that works fortestcontainers-dotnet.I see it is also used in
testcontainers-elixir: https://github.com/testcontainers/testcontainers-elixir/blob/62cef58c518f1ab63859d9327825db5b9a8f21d8/lib/container/postgres_container.ex#L228In
testcontainers-node: https://github.com/testcontainers/testcontainers-node/blob/075ade49273d553d00bed5fb418de2db3ffb1c6c/packages/modules/postgresql/src/postgresql-container.ts#L42And in
testcontainers-php: https://github.com/testcontainers/testcontainers-php/blob/8602d6545713bd91d6d875de55be9db660f5b68c/src/Modules/PostgresContainer.php#L25Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK
pg_isreadyis still flaky thing during init scenariotestcontainers-javastill rely on 2 log entries instead ofpg_isreadyWe can, but it requires separate PR and interface proposal. We already have functionality that allows to reach similar behavior via healthcheck override - it's different, but it's docker-way for similar needs.
The only issue is that we don't expose it as part of Image itself, only as an extension to override for now (we can extend in fact)
We also had another PR that attempted to support this - perhaps I need to re-consider this (for example
testcontainers-nodealso uses healthcheck functionality for that)However, considering the same flakiness problem with
pg_isready, it doesn’t appear to be a crucial functionality for this PR.