@@ -1294,7 +1294,7 @@ public void blockAndTimeoutOnPoolExhaustion_withAcquireSessionTimeout() throws E
12941294 .setMinSessions (minSessions )
12951295 .setMaxSessions (1 )
12961296 .setInitialWaitForSessionTimeoutMillis (20L )
1297- .setAcquireSessionTimeout (Duration . ofMillis ( 20L ) )
1297+ .setAcquireSessionTimeout (null )
12981298 .build ();
12991299 setupMockSessionCreation ();
13001300 pool = createPool ();
@@ -1307,29 +1307,30 @@ public void blockAndTimeoutOnPoolExhaustion_withAcquireSessionTimeout() throws E
13071307 Future <Void > fut =
13081308 executor .submit (
13091309 () -> {
1310- latch .countDown ();
13111310 PooledSessionFuture session = pool .getSession ();
1311+ latch .countDown ();
1312+ session .get ();
13121313 session .close ();
13131314 return null ;
13141315 });
13151316 // Wait until the background thread is actually waiting for a session.
13161317 latch .await ();
13171318 // Wait until the request has timed out.
1318- int waitCount = 0 ;
1319- while (pool .getNumWaiterTimeouts () == 0L && waitCount < 5000 ) {
1320- Thread .sleep (1L );
1321- waitCount ++;
1319+ Stopwatch watch = Stopwatch .createStarted ();
1320+ while (pool .getNumWaiterTimeouts () == 0L && watch .elapsed (TimeUnit .MILLISECONDS ) < 1000 ) {
1321+ Thread .yield ();
13221322 }
13231323 // Return the checked out session to the pool so the async request will get a session and
13241324 // finish.
13251325 checkedOutSession .close ();
13261326 // Verify that the async request also succeeds.
13271327 fut .get (10L , TimeUnit .SECONDS );
13281328 executor .shutdown ();
1329+ assertTrue (executor .awaitTermination (10L , TimeUnit .SECONDS ));
13291330
13301331 // Verify that the session was returned to the pool and that we can get it again.
1331- Session session = pool .getSession ();
1332- assertThat (session ).isNotNull ();
1332+ PooledSessionFuture session = pool .getSession ();
1333+ assertThat (session . get () ).isNotNull ();
13331334 session .close ();
13341335 assertThat (pool .getNumWaiterTimeouts ()).isAtLeast (1L );
13351336 }
0 commit comments