[Bug]: PostgreSQLContainer skips the JDBC readiness gate, leaving host-side port reachability unverified
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Accessibilité débutants
- 75/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- Active
- Stack technique
- docker, java, postgresql
- Domaine
- databases, testing-qa
Piste de recherche
Commencez par les implémentations obsolète et nouvelle de PostgreSQLContainer et comparez leurs méthodes waitUntilContainerStarted() avec JdbcDatabaseContainer#waitUntilContainerStarted(). Vérifiez que la stratégie d’attente reste respectée avant la vérification de disponibilité JDBC, puis ajoutez ou mettez à jour les tests de disponibilité de la connexion côté hôte et du comportement d’attente personnalisé. Le travail est terminé lorsque PostgreSQLContainer couvre les deux conditions sans provoquer de régression des stratégies d’attente fournies par l’utilisateur.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Module
PostgreSQL
Problem
PostgreSQLContainer — both the deprecated org.testcontainers.containers.PostgreSQLContainer and the new org.testcontainers.postgresql.PostgreSQLContainer — overrides waitUntilContainerStarted() to call only the wait strategy:
@Override
protected void waitUntilContainerStarted() {
getWaitStrategy().waitUntilReady(this);
}
This deliberately skips JdbcDatabaseContainer#waitUntilContainerStarted(), which repeatedly opens a JDBC connection from the host and runs the test query until it succeeds.
The consequence is that Postgres readiness is gated purely on container-side log output. Nothing verifies that the mapped port is routable from the calling JVM, or that a connection can actually be established. Every other JDBC container gets that host-side gate; Postgres is the exception.
On Docker environments that publish ports through a VM (Colima, Docker Desktop), the mapped host port can become routable slightly after database system is ready to accept connections appears in the log, so the first connection after start() returns Connection refused.
Why the override may no longer be needed
git log -L traces the override to #327, which fixed #317. The motive there was noise, not correctness: the Postgres JDBC driver had just moved to java.util.logging and was printing a stack trace for every failed attempt of the connect-retry loop. The PR description even says:
I've changed the
PostgreSQLContainerto use theWaitingConsumerfor waiting for Log output, instead of performing SQL queries. It's basically the same code as inLogWaitStrategy, but I've figured we'll refactor theJdbcDatabaseContainersat a later stage, to make use of aWaitStrategy?
That concern is handled independently today. PostgreSQLContainer#configure() sets:
// Disable Postgres driver use of java.util.logging to reduce noise at startup time
withUrlParam("loggerLevel", "OFF");
So the retry loop no longer produces the log spam the override was introduced to avoid.
Proposal
Have the override run the wait strategy and then delegate:
@Override
protected void waitUntilContainerStarted() {
getWaitStrategy().waitUntilReady(this);
super.waitUntilContainerStarted();
}
This keeps the property the override was preserving — a user-supplied waitingFor(...) is actually honored, which JdbcDatabaseContainer otherwise ignores entirely — while restoring the JDBC readiness gate that every other JDBC container already has.
Downstream context
Surfaced from testcontainers-jooq-codegen-maven-plugin#59. That plugin worked around the missing host-side gate by replacing the container's wait strategy with HostPortWaitStrategy, which then removed the log gate and let code generation run against a database still reporting FATAL: the database system is starting up. Neither gate alone is sufficient, and a downstream caller cannot compose them: GenericContainer#getWaitStrategy is protected, so external code cannot read a container's default in order to wrap it in a WaitAllStrategy.
Happy to open a PR if this direction looks right.
- Langage dominant
- Java
- Étoiles
- 8.7k
- Forks
- 1.9k
- Merge moyen
- 2 j 17 h
- PR mergées (30 j)
- 9
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de testcontainers/testcontainers-java
-
type/bug
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
testcontainers/testcontainers-java#11997 · 1 commentaire ·
-
[Enhancement]: Document why singleton containers are required under Spring's test context caching Ouvertetype/enhancement
Difficulté 1/5 Moins d'une heure Accessibilité débutants 85/100
testcontainers/testcontainers-java#11967 ·
-
type/bug
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
testcontainers/testcontainers-java#11941 ·
-
type/bug
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
testcontainers/testcontainers-java#11829 · 1 commentaire ·
-
type/enhancement
Difficulté 2/5 1-3 heures Accessibilité débutants 65/100
testcontainers/testcontainers-java#11578 ·
Toutes les issues de testcontainers/testcontainers-java
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
-
bug needs triage
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 94/100
objectionary/hone-maven-plugin#1061 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
spring-projects/spring-modulith#1895 ·