From 93cac839bf5c0163545778d1b829af59f49634e7 Mon Sep 17 00:00:00 2001 From: Tom Granot Date: Sat, 12 Dec 2020 19:50:07 +0200 Subject: [PATCH 1/4] Prefix the www subdomain for URLs in the testMaxTotalConnections test so it doesn't fail on DNS weridness. Should probably investigate further / refactor, but this blocks the thread on everything else on the repo, so I'm calling it. --- .../org/asynchttpclient/channel/MaxTotalConnectionTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/test/java/org/asynchttpclient/channel/MaxTotalConnectionTest.java b/client/src/test/java/org/asynchttpclient/channel/MaxTotalConnectionTest.java index fcf34896f6..e24c961a46 100644 --- a/client/src/test/java/org/asynchttpclient/channel/MaxTotalConnectionTest.java +++ b/client/src/test/java/org/asynchttpclient/channel/MaxTotalConnectionTest.java @@ -69,7 +69,7 @@ public void testMaxTotalConnectionsExceedingException() throws IOException { @Test(groups = "online") public void testMaxTotalConnections() throws Exception { - String[] urls = new String[]{"https://google.com", "https://github.com"}; + String[] urls = new String[]{"https://www.google.com", "https://www.github.com"}; final CountDownLatch latch = new CountDownLatch(2); final AtomicReference ex = new AtomicReference<>(); From c22fe840d1e5b2d1c252404f23eb2ed60d30eead Mon Sep 17 00:00:00 2001 From: Tom Granot Date: Sat, 12 Dec 2020 21:12:03 +0200 Subject: [PATCH 2/4] Add fixes to various tests (see https://github.com/AsyncHttpClient/async-http-client/pull/1753) --- .github/workflows/maven.yml | 2 +- .../org/asynchttpclient/AsyncStreamHandlerTest.java | 12 +++++++++--- .../channel/MaxTotalConnectionTest.java | 2 +- .../reactivestreams/ReactiveStreamsErrorTest.java | 4 ++-- .../java/org/asynchttpclient/ws/TextMessageTest.java | 1 + 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 324d98d6be..f68e412e12 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -9,7 +9,7 @@ on: jobs: build: - runs-on: ubuntu-16.04 + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - name: Set up JDK 1.8 diff --git a/client/src/test/java/org/asynchttpclient/AsyncStreamHandlerTest.java b/client/src/test/java/org/asynchttpclient/AsyncStreamHandlerTest.java index 1547872aaa..34bae9cfeb 100644 --- a/client/src/test/java/org/asynchttpclient/AsyncStreamHandlerTest.java +++ b/client/src/test/java/org/asynchttpclient/AsyncStreamHandlerTest.java @@ -436,7 +436,10 @@ public void asyncOptionsTest() throws Throwable { final AtomicReference responseHeaders = new AtomicReference<>(); + // Some responses contain the TRACE method, some do not - account for both + // FIXME: Actually refactor this test to account for both cases final String[] expected = {"GET", "HEAD", "OPTIONS", "POST"}; + final String[] expectedWithTrace = {"GET", "HEAD", "OPTIONS", "POST", "TRACE"}; Future f = client.prepareOptions("http://www.apache.org/").execute(new AsyncHandlerAdapter() { @Override @@ -455,10 +458,13 @@ public String onCompleted() { HttpHeaders h = responseHeaders.get(); assertNotNull(h); String[] values = h.get(ALLOW).split(",|, "); - assertNotNull(values); - assertEquals(values.length, expected.length); + String[] valuesWithTrace = h.get(ALLOW).split(",|, "); + assertNotNull(values); + // Some responses contain the TRACE method, some do not - account for both + assert(values.length == expected.length || valuesWithTrace.length == expectedWithTrace.length); Arrays.sort(values); - assertEquals(values, expected); + // Some responses contain the TRACE method, some do not - account for both + assert(values == expected || valuesWithTrace == expectedWithTrace); })); } diff --git a/client/src/test/java/org/asynchttpclient/channel/MaxTotalConnectionTest.java b/client/src/test/java/org/asynchttpclient/channel/MaxTotalConnectionTest.java index e24c961a46..492399e3af 100644 --- a/client/src/test/java/org/asynchttpclient/channel/MaxTotalConnectionTest.java +++ b/client/src/test/java/org/asynchttpclient/channel/MaxTotalConnectionTest.java @@ -69,7 +69,7 @@ public void testMaxTotalConnectionsExceedingException() throws IOException { @Test(groups = "online") public void testMaxTotalConnections() throws Exception { - String[] urls = new String[]{"https://www.google.com", "https://www.github.com"}; + String[] urls = new String[]{"https://www.google.com", "https://www.youtube.com"}; final CountDownLatch latch = new CountDownLatch(2); final AtomicReference ex = new AtomicReference<>(); diff --git a/client/src/test/java/org/asynchttpclient/reactivestreams/ReactiveStreamsErrorTest.java b/client/src/test/java/org/asynchttpclient/reactivestreams/ReactiveStreamsErrorTest.java index d95973a0eb..2eb2cd7b06 100644 --- a/client/src/test/java/org/asynchttpclient/reactivestreams/ReactiveStreamsErrorTest.java +++ b/client/src/test/java/org/asynchttpclient/reactivestreams/ReactiveStreamsErrorTest.java @@ -46,8 +46,8 @@ public class ReactiveStreamsErrorTest extends AbstractBasicTest { public void initClient() { client = asyncHttpClient(config() .setMaxRequestRetry(0) - .setRequestTimeout(3_000) - .setReadTimeout(1_000)); + .setRequestTimeout(5_000) + .setReadTimeout(3_000)); } @AfterTest diff --git a/client/src/test/java/org/asynchttpclient/ws/TextMessageTest.java b/client/src/test/java/org/asynchttpclient/ws/TextMessageTest.java index d3249944d4..b9f9e91142 100644 --- a/client/src/test/java/org/asynchttpclient/ws/TextMessageTest.java +++ b/client/src/test/java/org/asynchttpclient/ws/TextMessageTest.java @@ -16,6 +16,7 @@ import org.testng.annotations.Test; import java.net.UnknownHostException; +import java.net.ConnectException; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; import java.util.concurrent.atomic.AtomicReference; From de8832f798488ef09466fe5a864cb117968fc1fc Mon Sep 17 00:00:00 2001 From: Tom Granot Date: Sat, 12 Dec 2020 21:45:34 +0200 Subject: [PATCH 3/4] Some more changes. --- .../java/org/asynchttpclient/AsyncStreamHandlerTest.java | 9 ++++++--- .../reactivestreams/ReactiveStreamsErrorTest.java | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/client/src/test/java/org/asynchttpclient/AsyncStreamHandlerTest.java b/client/src/test/java/org/asynchttpclient/AsyncStreamHandlerTest.java index 34bae9cfeb..ce7607e92e 100644 --- a/client/src/test/java/org/asynchttpclient/AsyncStreamHandlerTest.java +++ b/client/src/test/java/org/asynchttpclient/AsyncStreamHandlerTest.java @@ -458,13 +458,16 @@ public String onCompleted() { HttpHeaders h = responseHeaders.get(); assertNotNull(h); String[] values = h.get(ALLOW).split(",|, "); - String[] valuesWithTrace = h.get(ALLOW).split(",|, "); assertNotNull(values); // Some responses contain the TRACE method, some do not - account for both - assert(values.length == expected.length || valuesWithTrace.length == expectedWithTrace.length); + assert(values.length == expected.length || values.length == expectedWithTrace.length); Arrays.sort(values); // Some responses contain the TRACE method, some do not - account for both - assert(values == expected || valuesWithTrace == expectedWithTrace); + if(values.length == expected.length) { + assertEquals(values, expected); + } else { + assertEquals(values, expectedWithTrace); + } })); } diff --git a/client/src/test/java/org/asynchttpclient/reactivestreams/ReactiveStreamsErrorTest.java b/client/src/test/java/org/asynchttpclient/reactivestreams/ReactiveStreamsErrorTest.java index 2eb2cd7b06..d95973a0eb 100644 --- a/client/src/test/java/org/asynchttpclient/reactivestreams/ReactiveStreamsErrorTest.java +++ b/client/src/test/java/org/asynchttpclient/reactivestreams/ReactiveStreamsErrorTest.java @@ -46,8 +46,8 @@ public class ReactiveStreamsErrorTest extends AbstractBasicTest { public void initClient() { client = asyncHttpClient(config() .setMaxRequestRetry(0) - .setRequestTimeout(5_000) - .setReadTimeout(3_000)); + .setRequestTimeout(3_000) + .setReadTimeout(1_000)); } @AfterTest From de3c985097d1c2fcc84e22df2d549c446f0218ed Mon Sep 17 00:00:00 2001 From: Tom Granot Date: Sat, 12 Dec 2020 22:06:19 +0200 Subject: [PATCH 4/4] Final fix for TestMessageTest --- .../test/java/org/asynchttpclient/ws/TextMessageTest.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/client/src/test/java/org/asynchttpclient/ws/TextMessageTest.java b/client/src/test/java/org/asynchttpclient/ws/TextMessageTest.java index b9f9e91142..72c3e1d244 100644 --- a/client/src/test/java/org/asynchttpclient/ws/TextMessageTest.java +++ b/client/src/test/java/org/asynchttpclient/ws/TextMessageTest.java @@ -71,11 +71,14 @@ public void onEmptyListenerTest() throws Exception { } } - @Test(timeOut = 60000, expectedExceptions = UnknownHostException.class) + @Test(timeOut = 60000, expectedExceptions = {UnknownHostException.class, ConnectException.class}) public void onFailureTest() throws Throwable { try (AsyncHttpClient c = asyncHttpClient()) { c.prepareGet("ws://abcdefg").execute(new WebSocketUpgradeHandler.Builder().build()).get(); } catch (ExecutionException e) { + + String expectedMessage = "DNS name not found"; + assertTrue(e.getCause().toString().contains(expectedMessage)); throw e.getCause(); } }