#12327 Fix flaky assertions
Signed-off-by: Ludovic Orban <lorban@bitronix.be>
This commit is contained in:
parent
3b1f38e592
commit
e8a258baba
|
@ -13,8 +13,8 @@
|
||||||
|
|
||||||
package org.eclipse.jetty.test.client.transport;
|
package org.eclipse.jetty.test.client.transport;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.eclipse.jetty.client.Destination;
|
import org.eclipse.jetty.client.Destination;
|
||||||
|
@ -28,10 +28,10 @@ import org.eclipse.jetty.server.internal.HttpConnection;
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.jupiter.params.provider.MethodSource;
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
|
|
||||||
|
import static org.awaitility.Awaitility.await;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.Matchers.empty;
|
|
||||||
import static org.hamcrest.Matchers.greaterThan;
|
import static org.hamcrest.Matchers.greaterThan;
|
||||||
import static org.hamcrest.Matchers.not;
|
import static org.hamcrest.Matchers.is;
|
||||||
|
|
||||||
public class ConnectionPoolTest extends AbstractTest
|
public class ConnectionPoolTest extends AbstractTest
|
||||||
{
|
{
|
||||||
|
@ -39,13 +39,14 @@ public class ConnectionPoolTest extends AbstractTest
|
||||||
@MethodSource("transports")
|
@MethodSource("transports")
|
||||||
public void testPreCreateConnections(Transport transport) throws Exception
|
public void testPreCreateConnections(Transport transport) throws Exception
|
||||||
{
|
{
|
||||||
|
int maxConnectionsPerDestination = 8;
|
||||||
prepareServer(transport, new EmptyServerHandler());
|
prepareServer(transport, new EmptyServerHandler());
|
||||||
ConnectionListener serverConnections = new ConnectionListener();
|
ConnectionListener serverConnections = new ConnectionListener();
|
||||||
connector.addBean(serverConnections);
|
connector.addBean(serverConnections);
|
||||||
server.start();
|
server.start();
|
||||||
|
|
||||||
startClient(transport);
|
startClient(transport);
|
||||||
client.setMaxConnectionsPerDestination(8);
|
client.setMaxConnectionsPerDestination(maxConnectionsPerDestination);
|
||||||
if (transport == Transport.HTTPS)
|
if (transport == Transport.HTTPS)
|
||||||
((HttpClientTransportOverHTTP)client.getTransport()).setInitializeConnections(true);
|
((HttpClientTransportOverHTTP)client.getTransport()).setInitializeConnections(true);
|
||||||
|
|
||||||
|
@ -54,15 +55,25 @@ public class ConnectionPoolTest extends AbstractTest
|
||||||
destination.getConnectionPool().preCreateConnections(client.getMaxConnectionsPerDestination())
|
destination.getConnectionPool().preCreateConnections(client.getMaxConnectionsPerDestination())
|
||||||
.get(5, TimeUnit.SECONDS);
|
.get(5, TimeUnit.SECONDS);
|
||||||
|
|
||||||
// Verify that connections have been created.
|
// Verify that server connections have been created.
|
||||||
List<Connection> connections = switch (transport)
|
await().atMost(5, TimeUnit.SECONDS).untilAsserted(() ->
|
||||||
{
|
{
|
||||||
case HTTP, HTTPS -> serverConnections.filter(HttpConnection.class);
|
switch (transport)
|
||||||
case H2C, H2 -> serverConnections.filter(HTTP2ServerConnection.class);
|
{
|
||||||
case H3 -> serverConnections.filter(ServerQuicConnection.class);
|
case HTTP, HTTPS:
|
||||||
case FCGI -> serverConnections.filter(ServerFCGIConnection.class);
|
assertThat(serverConnections.filter(HttpConnection.class).size(), is(maxConnectionsPerDestination));
|
||||||
};
|
break;
|
||||||
assertThat(connections, not(empty()));
|
case H2C, H2:
|
||||||
|
assertThat(serverConnections.filter(HTTP2ServerConnection.class).size(), is(maxConnectionsPerDestination));
|
||||||
|
break;
|
||||||
|
case H3:
|
||||||
|
assertThat(serverConnections.filter(ServerQuicConnection.class).size(), is(1));
|
||||||
|
break;
|
||||||
|
case FCGI:
|
||||||
|
assertThat(serverConnections.filter(ServerFCGIConnection.class).size(), is(maxConnectionsPerDestination));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Verify that TLS was performed.
|
// Verify that TLS was performed.
|
||||||
List<Connection> sslConnections = switch (transport)
|
List<Connection> sslConnections = switch (transport)
|
||||||
|
@ -72,7 +83,7 @@ public class ConnectionPoolTest extends AbstractTest
|
||||||
};
|
};
|
||||||
if (sslConnections != null)
|
if (sslConnections != null)
|
||||||
{
|
{
|
||||||
assertThat(sslConnections.size(), greaterThan(0));
|
assertThat(sslConnections.size(), is(maxConnectionsPerDestination));
|
||||||
sslConnections.forEach(c -> assertThat(c.getBytesIn(), greaterThan(0L)));
|
sslConnections.forEach(c -> assertThat(c.getBytesIn(), greaterThan(0L)));
|
||||||
sslConnections.forEach(c -> assertThat(c.getBytesOut(), greaterThan(0L)));
|
sslConnections.forEach(c -> assertThat(c.getBytesOut(), greaterThan(0L)));
|
||||||
}
|
}
|
||||||
|
@ -80,7 +91,7 @@ public class ConnectionPoolTest extends AbstractTest
|
||||||
|
|
||||||
private static class ConnectionListener implements Connection.Listener
|
private static class ConnectionListener implements Connection.Listener
|
||||||
{
|
{
|
||||||
private final List<Connection> connections = new ArrayList<>();
|
private final List<Connection> connections = new CopyOnWriteArrayList<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onOpened(Connection connection)
|
public void onOpened(Connection connection)
|
||||||
|
|
Loading…
Reference in New Issue