From e7cdfa31af08074aa9dbb3f3d21a622144995b9d Mon Sep 17 00:00:00 2001 From: anatoly0karyakin Date: Mon, 13 Jun 2022 14:02:09 +0300 Subject: [PATCH] Don't ignore sql test query exception, add it as cause exception (#5484) --- .../org/testcontainers/containers/JdbcDatabaseContainer.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/jdbc/src/main/java/org/testcontainers/containers/JdbcDatabaseContainer.java b/modules/jdbc/src/main/java/org/testcontainers/containers/JdbcDatabaseContainer.java index 84d242a29c7..0b80eaac406 100644 --- a/modules/jdbc/src/main/java/org/testcontainers/containers/JdbcDatabaseContainer.java +++ b/modules/jdbc/src/main/java/org/testcontainers/containers/JdbcDatabaseContainer.java @@ -151,6 +151,7 @@ protected void waitUntilContainerStarted() { // Repeatedly try and open a connection to the DB and execute a test query long start = System.currentTimeMillis(); + Exception lastConnectionException = null; while (System.currentTimeMillis() < start + (1000 * startupTimeoutSeconds)) { if (!isRunning()) { Thread.sleep(100L); @@ -165,6 +166,7 @@ protected void waitUntilContainerStarted() { // we explicitly want this exception to fail fast without retries throw e; } catch (Exception e) { + lastConnectionException = e; // ignore so that we can try again logger().debug("Failure when trying test query", e); Thread.sleep(100L); @@ -176,7 +178,8 @@ protected void waitUntilContainerStarted() { String.format( "Container is started, but cannot be accessed by (JDBC URL: %s), please check container logs", this.getJdbcUrl() - ) + ), + lastConnectionException ); }