@@ -409,6 +409,7 @@ public void testPoolIdleTimeout(TestContext ctx) {
409409
410410 poolOptions
411411 .setPoolCleanerPeriod (pooleCleanerPeriod )
412+ .setMaxLifetime (0 )
412413 .setIdleTimeout (idleTimeout )
413414 .setIdleTimeoutUnit (TimeUnit .MILLISECONDS );
414415 options .setPort (8080 );
@@ -422,6 +423,49 @@ public void testPoolIdleTimeout(TestContext ctx) {
422423 .onComplete (ctx .asyncAssertSuccess ());
423424 }
424425
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+
425469 @ Test
426470 public void testPoolConnectTimeout (TestContext ctx ) {
427471 Async async = ctx .async (2 );
0 commit comments