Skip to content

Commit

Permalink
chore: fix session acquire timeout test (#2793)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
olavloite and gcf-owl-bot[bot] authored Feb 7, 2024
1 parent 1765e08 commit 79c30d2
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1639,15 +1639,16 @@ 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.
options =
SessionPoolOptions.newBuilder()
.setMinSessions(1)
.setMaxSessions(2)
.setMaxIdleSessions(0)
.setInitialWaitForSessionTimeoutMillis(50L)
.setAcquireSessionTimeout(null)
.build();
FakeClock clock = new FakeClock();
clock.currentTimeMillis.set(System.currentTimeMillis());
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 79c30d2

Please sign in to comment.