From 3a2985541ea955a91d0a96243d57900dff289357 Mon Sep 17 00:00:00 2001 From: Brett Wooldridge Date: Thu, 20 Mar 2014 11:52:27 +0900 Subject: [PATCH] Fix unit tests to calculate proper times per retry. --- .../java/com/zaxxer/hikari/TestConnectionTimeoutRetry.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/zaxxer/hikari/TestConnectionTimeoutRetry.java b/src/test/java/com/zaxxer/hikari/TestConnectionTimeoutRetry.java index d92d3620..ca553e9e 100644 --- a/src/test/java/com/zaxxer/hikari/TestConnectionTimeoutRetry.java +++ b/src/test/java/com/zaxxer/hikari/TestConnectionTimeoutRetry.java @@ -61,7 +61,7 @@ public class TestConnectionTimeoutRetry final StubDataSource stubDataSource = ds.unwrap(StubDataSource.class); stubDataSource.setThrowException(new SQLException("Connection refused")); - final long timePerTry = config.getConnectionTimeout() / (config.getAcquireRetries() + 1); + final long timePerTry = Math.max(config.getConnectionTimeout() / (config.getAcquireRetries() + 1), 1000); ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); scheduler.schedule(new Runnable() { @@ -78,7 +78,8 @@ public class TestConnectionTimeoutRetry connection.close(); long elapsed = System.currentTimeMillis() - start; - Assert.assertTrue("Waited too long to get a connection.", (elapsed >= timePerTry * 3) && (elapsed < config.getConnectionTimeout())); + Assert.assertTrue("Connection returned too quickly, something is wrong.", elapsed >= timePerTry * 3); + Assert.assertTrue("Waited too long to get a connection.", elapsed < config.getConnectionTimeout()); } catch (SQLException e) {