Skip to content

Commit 79c30d2

Browse files
chore: fix session acquire timeout test (#2793)
* 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 <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 1765e08 commit 79c30d2

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

google-cloud-spanner/src/test/java/com/google/cloud/spanner/SessionPoolTest.java

+10-7
Original file line numberDiff line numberDiff line change
@@ -1166,8 +1166,8 @@ public void blockAndTimeoutOnPoolExhaustion() throws Exception {
11661166
latch.await();
11671167
// Wait until the request has timed out.
11681168
int waitCount = 0;
1169-
while (pool.getNumWaiterTimeouts() == 0L && waitCount < 1000) {
1170-
Thread.sleep(5L);
1169+
while (pool.getNumWaiterTimeouts() == 0L && waitCount < 5000) {
1170+
Thread.sleep(1L);
11711171
waitCount++;
11721172
}
11731173
// 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
12141214
latch.await();
12151215
// Wait until the request has timed out.
12161216
int waitCount = 0;
1217-
while (pool.getNumWaiterTimeouts() == 0L && waitCount < 1000) {
1218-
Thread.sleep(5L);
1217+
while (pool.getNumWaiterTimeouts() == 0L && waitCount < 5000) {
1218+
Thread.sleep(1L);
12191219
waitCount++;
12201220
}
12211221
// Return the checked out session to the pool so the async request will get a session and
@@ -1639,15 +1639,16 @@ public void testSessionNotFoundPartitionedUpdate() {
16391639
assertThat(impl.executePartitionedUpdate(statement)).isEqualTo(1L);
16401640
}
16411641

1642+
@SuppressWarnings("rawtypes")
16421643
@Test
16431644
public void testSessionMetrics() throws Exception {
16441645
// Create a session pool with max 2 session and a low timeout for waiting for a session.
16451646
options =
16461647
SessionPoolOptions.newBuilder()
16471648
.setMinSessions(1)
16481649
.setMaxSessions(2)
1649-
.setMaxIdleSessions(0)
16501650
.setInitialWaitForSessionTimeoutMillis(50L)
1651+
.setAcquireSessionTimeout(null)
16511652
.build();
16521653
FakeClock clock = new FakeClock();
16531654
clock.currentTimeMillis.set(System.currentTimeMillis());
@@ -1746,10 +1747,12 @@ public void testSessionMetrics() throws Exception {
17461747
latch.await();
17471748
// Wait until the request has timed out.
17481749
int waitCount = 0;
1749-
while (pool.getNumWaiterTimeouts() == 0L && waitCount < 1000) {
1750-
Thread.sleep(5L);
1750+
while (pool.getNumWaiterTimeouts() == 0L && waitCount < 5000) {
1751+
//noinspection BusyWait
1752+
Thread.sleep(1L);
17511753
waitCount++;
17521754
}
1755+
assertTrue(pool.getNumWaiterTimeouts() > 0L);
17531756
// Return the checked out session to the pool so the async request will get a session and
17541757
// finish.
17551758
session2.close();

0 commit comments

Comments
 (0)