From 267991982e6dbf985cb2701adf468c79caf05b40 Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Tue, 16 Apr 2019 11:43:49 +0200 Subject: [PATCH] Increased timeouts for tests that connect to external sites. Signed-off-by: Simone Bordet --- .../java/client/ConscryptHTTP2ClientTest.java | 25 +++++++-- .../alpn/java/client/JDK9HTTP2ClientTest.java | 26 ++++++++-- .../jetty/client/ExternalSiteTest.java | 52 +++++++------------ 3 files changed, 60 insertions(+), 43 deletions(-) diff --git a/jetty-alpn/jetty-alpn-conscrypt-client/src/test/java/org/eclipse/jetty/alpn/java/client/ConscryptHTTP2ClientTest.java b/jetty-alpn/jetty-alpn-conscrypt-client/src/test/java/org/eclipse/jetty/alpn/java/client/ConscryptHTTP2ClientTest.java index e10442b2345..e6f30ee8434 100644 --- a/jetty-alpn/jetty-alpn-conscrypt-client/src/test/java/org/eclipse/jetty/alpn/java/client/ConscryptHTTP2ClientTest.java +++ b/jetty-alpn/jetty-alpn-conscrypt-client/src/test/java/org/eclipse/jetty/alpn/java/client/ConscryptHTTP2ClientTest.java @@ -19,6 +19,7 @@ package org.eclipse.jetty.alpn.java.client; import java.net.InetSocketAddress; +import java.net.Socket; import java.security.Security; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -39,6 +40,7 @@ import org.eclipse.jetty.util.FuturePromise; import org.eclipse.jetty.util.Jetty; import org.eclipse.jetty.util.Promise; import org.eclipse.jetty.util.ssl.SslContextFactory; +import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; @@ -50,6 +52,11 @@ public class ConscryptHTTP2ClientTest @Test public void testConscryptHTTP2Client() throws Exception { + String host = "webtide.com"; + int port = 443; + + Assumptions.assumeTrue(canConnectTo(host, port)); + Security.insertProviderAt(new OpenSSLProvider(), 1); SslContextFactory sslContextFactory = new SslContextFactory.Client(); sslContextFactory.setProvider("Conscrypt"); @@ -61,9 +68,6 @@ public class ConscryptHTTP2ClientTest client.addBean(sslContextFactory); client.start(); - String host = "webtide.com"; - int port = 443; - FuturePromise sessionPromise = new FuturePromise<>(); client.connect(sslContextFactory, new InetSocketAddress(host, port), new Session.Listener.Adapter(), sessionPromise); Session session = sessionPromise.get(5, TimeUnit.SECONDS); @@ -93,11 +97,24 @@ public class ConscryptHTTP2ClientTest } }); - assertTrue(latch.await(5, TimeUnit.SECONDS)); + assertTrue(latch.await(15, TimeUnit.SECONDS)); } finally { client.stop(); } } + + private boolean canConnectTo(String host, int port) + { + try + { + new Socket(host, port).close(); + return true; + } + catch (Throwable x) + { + return false; + } + } } diff --git a/jetty-alpn/jetty-alpn-java-client/src/test/java/org/eclipse/jetty/alpn/java/client/JDK9HTTP2ClientTest.java b/jetty-alpn/jetty-alpn-java-client/src/test/java/org/eclipse/jetty/alpn/java/client/JDK9HTTP2ClientTest.java index 67e72579f23..ec75a606856 100644 --- a/jetty-alpn/jetty-alpn-java-client/src/test/java/org/eclipse/jetty/alpn/java/client/JDK9HTTP2ClientTest.java +++ b/jetty-alpn/jetty-alpn-java-client/src/test/java/org/eclipse/jetty/alpn/java/client/JDK9HTTP2ClientTest.java @@ -19,6 +19,7 @@ package org.eclipse.jetty.alpn.java.client; import java.net.InetSocketAddress; +import java.net.Socket; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -36,6 +37,7 @@ import org.eclipse.jetty.util.FuturePromise; import org.eclipse.jetty.util.Jetty; import org.eclipse.jetty.util.Promise; import org.eclipse.jetty.util.ssl.SslContextFactory; +import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; @@ -45,17 +47,18 @@ public class JDK9HTTP2ClientTest @Test public void testJDK9HTTP2Client() throws Exception { - SslContextFactory sslContextFactory = new SslContextFactory.Client(); + String host = "webtide.com"; + int port = 443; + + Assumptions.assumeTrue(canConnectTo(host, port)); HTTP2Client client = new HTTP2Client(); try { + SslContextFactory sslContextFactory = new SslContextFactory.Client(); client.addBean(sslContextFactory); client.start(); - String host = "webtide.com"; - int port = 443; - FuturePromise sessionPromise = new FuturePromise<>(); client.connect(sslContextFactory, new InetSocketAddress(host, port), new Session.Listener.Adapter(), sessionPromise); Session session = sessionPromise.get(5, TimeUnit.SECONDS); @@ -85,11 +88,24 @@ public class JDK9HTTP2ClientTest } }); - latch.await(5, TimeUnit.SECONDS); + latch.await(15, TimeUnit.SECONDS); } finally { client.stop(); } } + + private boolean canConnectTo(String host, int port) + { + try + { + new Socket(host, port).close(); + return true; + } + catch (Throwable x) + { + return false; + } + } } diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/ExternalSiteTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/ExternalSiteTest.java index 731c2d9a554..90811dc0e67 100644 --- a/jetty-client/src/test/java/org/eclipse/jetty/client/ExternalSiteTest.java +++ b/jetty-client/src/test/java/org/eclipse/jetty/client/ExternalSiteTest.java @@ -66,30 +66,23 @@ public class ExternalSiteTest assumeCanConnectTo(host, port); final CountDownLatch latch1 = new CountDownLatch(1); - client.newRequest(host, port).send(new Response.CompleteListener() + client.newRequest(host, port).send(result -> { - @Override - public void onComplete(Result result) - { - if (!result.isFailed() && result.getResponse().getStatus() == 200) - latch1.countDown(); - } + assertTrue(result.isSucceeded()); + assertEquals(200, result.getResponse().getStatus()); + latch1.countDown(); }); - assertTrue(latch1.await(10, TimeUnit.SECONDS)); + assertTrue(latch1.await(15, TimeUnit.SECONDS)); // Try again the same URI, but without specifying the port final CountDownLatch latch2 = new CountDownLatch(1); - client.newRequest("http://" + host).send(new Response.CompleteListener() + client.newRequest("http://" + host).send(result -> { - @Override - public void onComplete(Result result) - { - assertTrue(result.isSucceeded()); - assertEquals(200, result.getResponse().getStatus()); - latch2.countDown(); - } + assertTrue(result.isSucceeded()); + assertEquals(200, result.getResponse().getStatus()); + latch2.countDown(); }); - assertTrue(latch2.await(10, TimeUnit.SECONDS)); + assertTrue(latch2.await(15, TimeUnit.SECONDS)); } @Tag("external") @@ -107,16 +100,13 @@ public class ExternalSiteTest assumeCanConnectTo(host, port); final CountDownLatch latch = new CountDownLatch(1); - client.newRequest(host, port).scheme("https").path("/nvp").send(new Response.CompleteListener() + client.newRequest(host, port).scheme("https").path("/nvp").send(result -> { - @Override - public void onComplete(Result result) - { - if (result.isSucceeded() && result.getResponse().getStatus() == 200) - latch.countDown(); - } + assertTrue(result.isSucceeded()); + assertEquals(200, result.getResponse().getStatus()); + latch.countDown(); }); - assertTrue(latch.await(5, TimeUnit.SECONDS)); + assertTrue(latch.await(15, TimeUnit.SECONDS)); } @Tag("external") @@ -133,14 +123,7 @@ public class ExternalSiteTest { final CountDownLatch latch = new CountDownLatch(3); client.newRequest(host, port) - .onResponseFailure(new Response.FailureListener() - { - @Override - public void onFailure(Response response, Throwable failure) - { - latch.countDown(); - } - }) + .onResponseFailure((response, failure) -> latch.countDown()) .send(new Response.Listener.Adapter() { @Override @@ -156,7 +139,7 @@ public class ExternalSiteTest latch.countDown(); } }); - assertTrue(latch.await(10, TimeUnit.SECONDS)); + assertTrue(latch.await(15, TimeUnit.SECONDS)); } } @@ -173,6 +156,7 @@ public class ExternalSiteTest ContentResponse response = client.newRequest(host, port) .scheme(HttpScheme.HTTPS.asString()) .path("/twitter") + .timeout(15, TimeUnit.SECONDS) .send(); assertEquals(200, response.getStatus()); }