-
-
Notifications
You must be signed in to change notification settings - Fork 307
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
[Bug]: The PostgreSqlContainer wait strategy is not reliable (non default configuration) #1092
Comments
Hi, I don't think the Empty postgres container lifecycle:
There could be another reasons such as lack of resources. |
Actually it won't succeed because after step 2 postgres is only listening on a socket (not on TCP/IP) for the initialisation scripts to run. In my proposed fix (#1093) I explicitly pass |
Interesting, this is probably what I did wrong in the past. I remember that I used
This is also a good discovery, thanks. We need to keep this in mind and may need to update other modules (wait strategies) like MongoDB too. |
I read the discussion on docker-library/postgres#146 then looked at the container logs and figured out that passing To go from sporadic errors to reliable errors, the container in private readonly PostgreSqlContainer _postgreSqlContainer = new PostgreSqlBuilder()
.WithResourceMapping("sleep 10"u8.ToArray(), "/docker-entrypoint-initdb.d/init.sh")
.Build(); This gives
Absolutely! The new test added in #1093 ( |
I just did it and found 4 containers failing the start/stop test 3 times in a row.
I also found another possible area if improvement: seeing exactly which tests fail and their errors at a glance in GitHub with the Test Reporter action: https://github.com/0xced/testcontainers-dotnet/actions/runs/7637708663/job/20808723402 |
Unfortunately, this probably does not cover everything (we need to be able to connect too). If we only use a log message (part of it), the wait strategy may indicate readiness too early. We need to pass the start time (since) to the method that gathers the container log messages. The Test Reporter is a good idea. I will need some time to look at everything; there are too many things I need to take care of besides OSS. Thanks a lot for the contribution and the efforts you put in 🙏. Much appreciated and superfast, as always 🏎️. |
The wait strategy was adjusted in #1111. |
Testcontainers version
3.7.0
Using the latest Testcontainers version?
Yes
Host OS
Any
Host arch
Any
.NET version
8.0.100
Docker version
Docker info
What happened?
As already briefly mentioned in #920 (comment), the default wait strategy for
PostgreSqlContainer
might hang forever.There are several ways to trigger this faulty behaviour.
WithVolumeMount("Testcontainers.PostgreSql.Data", "/var/lib/postgresql/data")
WithReuse(true)
The logs produced when reusing an existing volume looks like this:
We can see that
database system is ready to accept connections
appears only once instead of twice which is expected by the wait strategy.When reusing the container or starting/stopping it many times in a row, the logs will grow and
database system is ready to accept connections
will appear more than twice.In both cases the
UntilAsync
method never returnstrue
and starting the container hangs.Relevant log output
No response
Additional information
I have already prepared a fix for this issue that I will submit shortly.
The text was updated successfully, but these errors were encountered: