From b3e8d56a7e7b1cc73d2d96a8cebbd0919b3b0b38 Mon Sep 17 00:00:00 2001 From: Ludovic Orban Date: Wed, 2 Feb 2022 11:10:09 +0100 Subject: [PATCH 1/2] #7461 Use less strict assertion for expiring pool to account for potential expirations Signed-off-by: Ludovic Orban --- .../java/org/eclipse/jetty/client/ConnectionPoolTest.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 ccecb188b969..257c810cdc67 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 @@ -54,6 +54,8 @@ import org.junit.jupiter.params.provider.MethodSource; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.lessThanOrEqualTo; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -316,7 +318,10 @@ public void resolve(String host, int port, Promise> prom assertEquals(1, destinations.size()); HttpDestination destination = (HttpDestination)destinations.get(0); AbstractConnectionPool connectionPool = (AbstractConnectionPool)destination.getConnectionPool(); - assertEquals(2, connectionPool.getConnectionCount()); + if (DUPLEX_MAX_DURATION == factory) + assertThat(connectionPool.getConnectionCount(), lessThanOrEqualTo(2)); // The connections can expire upon release. + else + assertThat(connectionPool.getConnectionCount(), is(2)); } @ParameterizedTest From f6c285ddb94268aa74d2857f20d790605dfe8a61 Mon Sep 17 00:00:00 2001 From: Ludovic Orban Date: Fri, 11 Feb 2022 12:14:37 +0100 Subject: [PATCH 2/2] #7461 Adapt other tests to use less strict assertion for expiring pool Signed-off-by: Ludovic Orban --- .../jetty/client/ConnectionPoolTest.java | 39 ++++++++++++------- 1 file changed, 24 insertions(+), 15 deletions(-) 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 257c810cdc67..31838e0eb7a5 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 static Stream pools() 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 void resolve(String host, int port, Promise> prom } @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 void testConcurrentRequestsAllBlockedOnServerWithLargeConnectionPool(Conn } @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 @@ protected void service(String target, org.eclipse.jetty.server.Request jettyRequ 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 void testConnectionMaxUsage(ConnectionPoolFactory factory) throws Excepti 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 void testIdleTimeoutNoRequests(ConnectionPoolFactory factory) throws Exce // 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);