diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/ConnectionPoolTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/ConnectionPoolTest.java index 257c810cdc6..31838e0eb7a 100644 --- a/jetty-client/src/test/java/org/eclipse/jetty/client/ConnectionPoolTest.java +++ b/jetty-client/src/test/java/org/eclipse/jetty/client/ConnectionPoolTest.java @@ -77,11 +77,6 @@ public class ConnectionPoolTest return Stream.of(DUPLEX, MULTIPLEX, RANDOM, DUPLEX_MAX_DURATION, ROUND_ROBIN); } - public static Stream poolsNoMaxDuration() - { - return Stream.of(DUPLEX, MULTIPLEX, RANDOM, ROUND_ROBIN); - } - public static Stream poolsNoRoundRobin() { return Stream.of(DUPLEX, MULTIPLEX, RANDOM, DUPLEX_MAX_DURATION); @@ -381,8 +376,7 @@ public class ConnectionPoolTest } @ParameterizedTest - // Connection pool aggressively closes expired connections upon release, which interferes with this test's assertion. - @MethodSource("poolsNoMaxDuration") + @MethodSource("pools") public void testConcurrentRequestsAllBlockedOnServerWithLargeConnectionPool(ConnectionPoolFactory factory) throws Exception { int count = 50; @@ -390,8 +384,7 @@ public class ConnectionPoolTest } @ParameterizedTest - // Connection pool aggressively closes expired connections upon release, which interferes with this test's assertion. - @MethodSource("poolsNoMaxDuration") + @MethodSource("pools") public void testConcurrentRequestsAllBlockedOnServerWithExactConnectionPool(ConnectionPoolFactory factory) throws Exception { int count = 50; @@ -454,9 +447,13 @@ public class ConnectionPoolTest assertTrue(latch.await(5, TimeUnit.SECONDS), "server requests " + barrier.getNumberWaiting() + "<" + count + " - client: " + client.dump()); List destinations = client.getDestinations(); assertEquals(1, destinations.size()); - HttpDestination destination = (HttpDestination)destinations.get(0); - AbstractConnectionPool connectionPool = (AbstractConnectionPool)destination.getConnectionPool(); - assertThat(connectionPool.getConnectionCount(), Matchers.greaterThanOrEqualTo(count)); + // The max duration connection pool aggressively closes expired connections upon release, which interferes with this assertion. + if (DUPLEX_MAX_DURATION != factory) + { + HttpDestination destination = (HttpDestination)destinations.get(0); + AbstractConnectionPool connectionPool = (AbstractConnectionPool)destination.getConnectionPool(); + assertThat(connectionPool.getConnectionCount(), Matchers.greaterThanOrEqualTo(count)); + } } @Test @@ -593,8 +590,17 @@ public class ConnectionPoolTest AbstractConnectionPool connectionPool = (AbstractConnectionPool)destination.getConnectionPool(); assertEquals(0, connectionPool.getActiveConnectionCount()); - assertEquals(1, connectionPool.getIdleConnectionCount()); - assertEquals(1, connectionPool.getConnectionCount()); + if (DUPLEX_MAX_DURATION == factory) + { + // The connections can expire upon release. + assertThat(connectionPool.getIdleConnectionCount(), lessThanOrEqualTo(1)); + assertThat(connectionPool.getConnectionCount(), lessThanOrEqualTo(1)); + } + else + { + assertThat(connectionPool.getIdleConnectionCount(), is(1)); + assertThat(connectionPool.getConnectionCount(), is(1)); + } // Send second request, max usage count will be reached, // the only connection must be closed. @@ -630,7 +636,10 @@ public class ConnectionPoolTest // Trigger the creation of a destination, that will create the connection pool. HttpDestination destination = client.resolveDestination(new Origin("http", "localhost", connector.getLocalPort())); AbstractConnectionPool connectionPool = (AbstractConnectionPool)destination.getConnectionPool(); - assertEquals(1, connectionPool.getConnectionCount()); + if (DUPLEX_MAX_DURATION == factory) + assertThat(connectionPool.getConnectionCount(), lessThanOrEqualTo(1)); // The connections can expire upon release. + else + assertThat(connectionPool.getConnectionCount(), is(1)); // Wait for the pre-created connections to idle timeout. Thread.sleep(idleTimeout + idleTimeout / 2);