From 07065c08d20873e621d57f1dbe3e3794c92ae3e4 Mon Sep 17 00:00:00 2001 From: bunnysayzz Date: Wed, 16 Sep 2026 12:37:57 +0530 Subject: [PATCH 1/2] fix(postgres): run JDBC readiness gate after wait strategy PostgreSQLContainer overrode waitUntilContainerStarted to run only the configured wait strategy, skipping JdbcDatabaseContainer's host-side JDBC loop (real connection + test query). The log-output strategy can fire before the mapped port is reachable on Docker Desktop/Colima, giving Connection refused on first connect. Run the strategy first, then super.waitUntilContainerStarted(), so a user-supplied waitingFor is still honored and the port is proven reachable before start returns. Compiles clean (:testcontainers-postgresql:compileJava); Docker-gated suite left to CI since no daemon is available here. Fixes #11981 --- .../org/testcontainers/postgresql/PostgreSQLContainer.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/postgresql/src/main/java/org/testcontainers/postgresql/PostgreSQLContainer.java b/modules/postgresql/src/main/java/org/testcontainers/postgresql/PostgreSQLContainer.java index 27521487a23..91dfc30b28a 100644 --- a/modules/postgresql/src/main/java/org/testcontainers/postgresql/PostgreSQLContainer.java +++ b/modules/postgresql/src/main/java/org/testcontainers/postgresql/PostgreSQLContainer.java @@ -139,6 +139,12 @@ public PostgreSQLContainer withPassword(final String password) { @Override protected void waitUntilContainerStarted() { + // Run the configured wait strategy first (defaults to the log-output + // strategy), then the JDBC readiness gate from JdbcDatabaseContainer: + // a real host-side connection running the test query. The log line + // alone can precede mapped-port reachability on Docker Desktop/Colima, + // giving Connection refused on first connect. See issue #11981. getWaitStrategy().waitUntilReady(this); + super.waitUntilContainerStarted(); } } From 28f53f4aab5145ac9ec81be5342ffe8ec4d8af2f Mon Sep 17 00:00:00 2001 From: bunnysayzz Date: Thu, 17 Sep 2026 00:50:41 +0530 Subject: [PATCH 2/2] fix(postgres): apply JDBC readiness gate to deprecated container too CodeRabbit review on #12080: the deprecated org.testcontainers.containers.PostgreSQLContainer carries the same strategy-only waitUntilContainerStarted override, so its users would still get a started container before JDBC is reachable. Same fix: strategy first, then super.waitUntilContainerStarted(). --- .../org/testcontainers/containers/PostgreSQLContainer.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/postgresql/src/main/java/org/testcontainers/containers/PostgreSQLContainer.java b/modules/postgresql/src/main/java/org/testcontainers/containers/PostgreSQLContainer.java index 4824654957f..4e4c4c9d4b0 100644 --- a/modules/postgresql/src/main/java/org/testcontainers/containers/PostgreSQLContainer.java +++ b/modules/postgresql/src/main/java/org/testcontainers/containers/PostgreSQLContainer.java @@ -149,6 +149,9 @@ public SELF withPassword(final String password) { @Override protected void waitUntilContainerStarted() { + // Same gate as the non-deprecated container: strategy first, then the + // JDBC readiness check from JdbcDatabaseContainer. See issue #11981. getWaitStrategy().waitUntilReady(this); + super.waitUntilContainerStarted(); } }