From cf7353f274e0067b0d3d7352355d9579d405e0fb Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Mon, 7 Nov 2022 16:16:25 -0600 Subject: [PATCH] Jetty 10 - Improve test reliability (#8868) * Don't care about stop failures in this test * More consistent ConnectTimeoutTest + using IANA example.com (as it will route to a real machine, and will never have this specific port open) Signed-off-by: Joakim Erdfelt --- .../GlobalWebappConfigBindingTest.java | 3 ++- .../http2/client/ConnectTimeoutTest.java | 7 +++++-- .../client/HttpClientConnectTimeoutTest.java | 18 +++++++++++------ .../http/client/HttpClientTimeoutTest.java | 20 +++++++++++++------ 4 files changed, 33 insertions(+), 15 deletions(-) diff --git a/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/bindings/GlobalWebappConfigBindingTest.java b/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/bindings/GlobalWebappConfigBindingTest.java index e8061783981..51713264f07 100644 --- a/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/bindings/GlobalWebappConfigBindingTest.java +++ b/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/bindings/GlobalWebappConfigBindingTest.java @@ -23,6 +23,7 @@ import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.eclipse.jetty.toolchain.test.PathAssert; import org.eclipse.jetty.toolchain.test.jupiter.WorkDir; import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension; +import org.eclipse.jetty.util.component.LifeCycle; import org.eclipse.jetty.webapp.WebAppContext; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -61,7 +62,7 @@ public class GlobalWebappConfigBindingTest public void teardownEnvironment() throws Exception { // Stop jetty. - jetty.stop(); + LifeCycle.stop(jetty); } @Test diff --git a/jetty-http2/http2-client/src/test/java/org/eclipse/jetty/http2/client/ConnectTimeoutTest.java b/jetty-http2/http2-client/src/test/java/org/eclipse/jetty/http2/client/ConnectTimeoutTest.java index cce94af67b6..777bdea5fd4 100644 --- a/jetty-http2/http2-client/src/test/java/org/eclipse/jetty/http2/client/ConnectTimeoutTest.java +++ b/jetty-http2/http2-client/src/test/java/org/eclipse/jetty/http2/client/ConnectTimeoutTest.java @@ -24,6 +24,7 @@ import org.eclipse.jetty.http2.api.Session; import org.eclipse.jetty.http2.api.server.ServerSessionListener; import org.eclipse.jetty.util.Promise; import org.junit.jupiter.api.Assumptions; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import static org.hamcrest.MatcherAssert.assertThat; @@ -33,10 +34,12 @@ import static org.junit.jupiter.api.Assertions.assertTrue; public class ConnectTimeoutTest extends AbstractTest { @Test + @Tag("external") public void testConnectTimeout() throws Exception { - final String host = "10.255.255.1"; - final int port = 80; + // Using IANA hosted example.com:81 to reliably produce a Connect Timeout. + final String host = "example.com"; + final int port = 81; int connectTimeout = 1000; assumeConnectTimeout(host, port, connectTimeout); diff --git a/tests/test-http-client-transport/src/test/java/org/eclipse/jetty/http/client/HttpClientConnectTimeoutTest.java b/tests/test-http-client-transport/src/test/java/org/eclipse/jetty/http/client/HttpClientConnectTimeoutTest.java index b8e553ccfc3..0a7cd2f2aa1 100644 --- a/tests/test-http-client-transport/src/test/java/org/eclipse/jetty/http/client/HttpClientConnectTimeoutTest.java +++ b/tests/test-http-client-transport/src/test/java/org/eclipse/jetty/http/client/HttpClientConnectTimeoutTest.java @@ -47,11 +47,13 @@ public class HttpClientConnectTimeoutTest extends AbstractTest @ParameterizedTest @ArgumentsSource(TransportProvider.class) + @Tag("external") public void testBlockingConnectTimeoutFailsRequest(Transport transport) throws Exception { // Failure to connect is based on InetSocket address failure, which Unix-Domain does not use. @@ -292,6 +294,7 @@ public class HttpClientTimeoutTest extends AbstractTest @ParameterizedTest @ArgumentsSource(TransportProvider.class) + @Tag("external") public void testNonBlockingConnectTimeoutFailsRequest(Transport transport) throws Exception { // Failure to connect is based on InetSocket address failure, which Unix-Domain does not use. @@ -302,8 +305,9 @@ public class HttpClientTimeoutTest extends AbstractTest private void testConnectTimeoutFailsRequest(boolean blocking) throws Exception { - String host = "10.255.255.1"; - int port = 80; + // Using IANA hosted example.com:81 to reliably produce a Connect Timeout. + final String host = "example.com"; + final int port = 81; int connectTimeout = 1000; assumeConnectTimeout(host, port, connectTimeout); @@ -329,6 +333,7 @@ public class HttpClientTimeoutTest extends AbstractTest @ParameterizedTest @ArgumentsSource(TransportProvider.class) + @Tag("external") public void testConnectTimeoutIsCancelledByShorterRequestTimeout(Transport transport) throws Exception { // Failure to connect is based on InetSocket address failure, which Unix-Domain does not use. @@ -336,8 +341,9 @@ public class HttpClientTimeoutTest extends AbstractTest init(transport); - String host = "10.255.255.1"; - int port = 80; + // Using IANA hosted example.com:81 to reliably produce a Connect Timeout. + final String host = "example.com"; + final int port = 81; int connectTimeout = 2000; assumeConnectTimeout(host, port, connectTimeout); @@ -365,6 +371,7 @@ public class HttpClientTimeoutTest extends AbstractTest @ParameterizedTest @ArgumentsSource(TransportProvider.class) + @Tag("external") public void testRetryAfterConnectTimeout(Transport transport) throws Exception { // Failure to connect is based on InetSocket address failure, which Unix-Domain does not use. @@ -372,8 +379,9 @@ public class HttpClientTimeoutTest extends AbstractTest init(transport); - final String host = "10.255.255.1"; - final int port = 80; + // Using IANA hosted example.com:81 to reliably produce a Connect Timeout. + final String host = "example.com"; + final int port = 81; int connectTimeout = 1000; assumeConnectTimeout(host, port, connectTimeout);