From ed14641e8788e3e59c6d3fde01da01c3df2461fb Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Wed, 14 Sep 2016 18:12:34 +0200 Subject: [PATCH] Made test more robust. --- .../eclipse/jetty/client/HttpClientTest.java | 24 +++++-------------- 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientTest.java index 45dbb931360..92bdff89738 100644 --- a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientTest.java +++ b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientTest.java @@ -22,7 +22,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.HttpCookie; -import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.ServerSocket; import java.net.Socket; @@ -828,19 +827,8 @@ public class HttpClientTest extends AbstractHttpClientServerTest @Test public void testConnectHostWithMultipleAddresses() throws Exception { - String host = "google.com"; - try - { - // Likely that the DNS for google.com returns multiple addresses. - Assume.assumeTrue(InetAddress.getAllByName(host).length > 1); - } - catch (Throwable x) - { - Assume.assumeNoException(x); - } + start(new EmptyServerHandler()); - startClient(); - client.setFollowRedirects(false); // Avoid redirects from 80 to 443. client.setSocketAddressResolver(new SocketAddressResolver.Async(client.getExecutor(), client.getScheduler(), client.getConnectTimeout()) { @Override @@ -853,7 +841,7 @@ public class HttpClientTest extends AbstractHttpClientServerTest { // Add as first address an invalid address so that we test // that the connect operation iterates over the addresses. - result.add(0, new InetSocketAddress("idontexist", 80)); + result.add(0, new InetSocketAddress("idontexist", port)); promise.succeeded(result); } @@ -866,9 +854,9 @@ public class HttpClientTest extends AbstractHttpClientServerTest } }); - // Response code may be 200 or 302; - // if no exceptions the test passes. - client.newRequest(host, 80) + // If no exceptions the test passes. + client.newRequest("localhost", connector.getLocalPort()) + .scheme(scheme) .header(HttpHeader.CONNECTION, "close") .send(); } @@ -1232,7 +1220,7 @@ public class HttpClientTest extends AbstractHttpClientServerTest // before closing the connection, so we need to wait before checking // that the connection is closed to avoid races. Thread.sleep(1000); - Assert.assertTrue(((HttpConnectionOverHTTP)connection).isClosed()); + Assert.assertTrue(connection.isClosed()); } }