@@ -409,6 +409,7 @@ public void testPoolIdleTimeout(TestContext ctx) {
409
409
410
410
poolOptions
411
411
.setPoolCleanerPeriod (pooleCleanerPeriod )
412
+ .setMaxLifetime (0 )
412
413
.setIdleTimeout (idleTimeout )
413
414
.setIdleTimeoutUnit (TimeUnit .MILLISECONDS );
414
415
options .setPort (8080 );
@@ -422,6 +423,49 @@ public void testPoolIdleTimeout(TestContext ctx) {
422
423
.onComplete (ctx .asyncAssertSuccess ());
423
424
}
424
425
426
+ @ Test
427
+ public void testPoolMaxLifetime (TestContext ctx ) {
428
+ ProxyServer proxy = ProxyServer .create (vertx , options .getPort (), options .getHost ());
429
+ AtomicReference <ProxyServer .Connection > proxyConn = new AtomicReference <>();
430
+ int pooleCleanerPeriod = 100 ;
431
+ int maxLifetime = 3000 ;
432
+ Async latch = ctx .async ();
433
+ proxy .proxyHandler (conn -> {
434
+ proxyConn .set (conn );
435
+ long now = System .currentTimeMillis ();
436
+ conn .clientCloseHandler (v -> {
437
+ long lifetime = System .currentTimeMillis () - now ;
438
+ int delta = 500 ;
439
+ int lowerBound = maxLifetime - pooleCleanerPeriod - delta ;
440
+ int upperBound = maxLifetime + pooleCleanerPeriod + delta ;
441
+ ctx .assertTrue (lifetime >= lowerBound , "Was expecting connection to be closed in more than " + lowerBound + ": " + lifetime );
442
+ ctx .assertTrue (lifetime <= upperBound , "Was expecting connection to be closed in less than " + upperBound + ": " + lifetime );
443
+ latch .complete ();
444
+ });
445
+ conn .connect ();
446
+ });
447
+
448
+ // Start proxy
449
+ Async listenLatch = ctx .async ();
450
+ proxy .listen (8080 , "localhost" , ctx .asyncAssertSuccess (res -> listenLatch .complete ()));
451
+ listenLatch .awaitSuccess (20_000 );
452
+
453
+ poolOptions
454
+ .setPoolCleanerPeriod (pooleCleanerPeriod )
455
+ .setIdleTimeout (0 )
456
+ .setMaxLifetime (maxLifetime )
457
+ .setMaxLifetimeUnit (TimeUnit .MILLISECONDS );
458
+ options .setPort (8080 );
459
+ options .setHost ("localhost" );
460
+ PgPool pool = createPool (options , poolOptions );
461
+
462
+ // Create a connection that remains in the pool
463
+ pool
464
+ .getConnection ()
465
+ .flatMap (SqlClient ::close )
466
+ .onComplete (ctx .asyncAssertSuccess ());
467
+ }
468
+
425
469
@ Test
426
470
public void testPoolConnectTimeout (TestContext ctx ) {
427
471
Async async = ctx .async (2 );
0 commit comments