From 79c30d2a4a3f07cc6f74a787bc5636cd2ff285ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Knut=20Olav=20L=C3=B8ite?= Date: Wed, 7 Feb 2024 07:09:29 +0100 Subject: [PATCH] chore: fix session acquire timeout test (#2793) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: fix session acquire timeout test The test for session acquire timeout did not actually do what it was supposed to do, as it did not check that a timeout was actually registered. This again also caused it to busy-wait for 5 seconds to times (MinSessions=0 and MinSessions=1). This fixes both the actual test, and reduces the overall test time by about 10 seconds. * chore: address review comments * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot --- .../google/cloud/spanner/SessionPoolTest.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SessionPoolTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SessionPoolTest.java index dc06c1c5b3e..4db74514805 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SessionPoolTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SessionPoolTest.java @@ -1166,8 +1166,8 @@ public void blockAndTimeoutOnPoolExhaustion() throws Exception { latch.await(); // Wait until the request has timed out. int waitCount = 0; - while (pool.getNumWaiterTimeouts() == 0L && waitCount < 1000) { - Thread.sleep(5L); + while (pool.getNumWaiterTimeouts() == 0L && waitCount < 5000) { + Thread.sleep(1L); waitCount++; } // Return the checked out session to the pool so the async request will get a session and @@ -1214,8 +1214,8 @@ public void blockAndTimeoutOnPoolExhaustion_withAcquireSessionTimeout() throws E latch.await(); // Wait until the request has timed out. int waitCount = 0; - while (pool.getNumWaiterTimeouts() == 0L && waitCount < 1000) { - Thread.sleep(5L); + while (pool.getNumWaiterTimeouts() == 0L && waitCount < 5000) { + Thread.sleep(1L); waitCount++; } // Return the checked out session to the pool so the async request will get a session and @@ -1639,6 +1639,7 @@ public void testSessionNotFoundPartitionedUpdate() { assertThat(impl.executePartitionedUpdate(statement)).isEqualTo(1L); } + @SuppressWarnings("rawtypes") @Test public void testSessionMetrics() throws Exception { // Create a session pool with max 2 session and a low timeout for waiting for a session. @@ -1646,8 +1647,8 @@ public void testSessionMetrics() throws Exception { SessionPoolOptions.newBuilder() .setMinSessions(1) .setMaxSessions(2) - .setMaxIdleSessions(0) .setInitialWaitForSessionTimeoutMillis(50L) + .setAcquireSessionTimeout(null) .build(); FakeClock clock = new FakeClock(); clock.currentTimeMillis.set(System.currentTimeMillis()); @@ -1746,10 +1747,12 @@ public void testSessionMetrics() throws Exception { latch.await(); // Wait until the request has timed out. int waitCount = 0; - while (pool.getNumWaiterTimeouts() == 0L && waitCount < 1000) { - Thread.sleep(5L); + while (pool.getNumWaiterTimeouts() == 0L && waitCount < 5000) { + //noinspection BusyWait + Thread.sleep(1L); waitCount++; } + assertTrue(pool.getNumWaiterTimeouts() > 0L); // Return the checked out session to the pool so the async request will get a session and // finish. session2.close();