Skip to content

Commit 8449d11

Browse files
committed
Fix tests, close AsyncHttpClient#1229
1 parent 34c46bd commit 8449d11

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

client/src/test/java/org/asynchttpclient/PerRequestRelative302Test.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public void setUpGlobal() throws Exception {
7575
server.start();
7676
port1 = connector.getLocalPort();
7777
logger.info("Local HTTP server started successfully");
78+
port2 = findFreePort();
7879
}
7980

8081
@Test(groups = "online")
@@ -132,15 +133,18 @@ private static int getPort(Uri uri) {
132133
// @Test(groups = "standalone")
133134
public void redirected302InvalidTest() throws Exception {
134135
isSet.getAndSet(false);
135-
try (AsyncHttpClient c = asyncHttpClient()) {
136-
// If the test hit a proxy, no ConnectException will be thrown and instead of 404 will be returned.
137-
Response response = c.preparePost(getTargetUrl()).setFollowRedirect(true).setHeader("X-redirect", String.format("http://localhost:%d/", port2)).execute().get();
136+
Exception e = null;
138137

139-
assertNotNull(response);
140-
assertEquals(response.getStatusCode(), 404);
138+
try (AsyncHttpClient c = asyncHttpClient()) {
139+
c.preparePost(getTargetUrl()).setFollowRedirect(true).setHeader("X-redirect", String.format("http://localhost:%d/", port2)).execute().get();
141140
} catch (ExecutionException ex) {
142-
assertEquals(ex.getCause().getClass(), ConnectException.class);
141+
e = ex;
143142
}
143+
144+
assertNotNull(e);
145+
Throwable cause = e.getCause();
146+
assertTrue(cause instanceof ConnectException);
147+
assertTrue(cause.getMessage().contains(":" + port2));
144148
}
145149

146150
// @Test(groups = "standalone")

client/src/test/java/org/asynchttpclient/Relative302Test.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public void setUpGlobal() throws Exception {
7272
server.start();
7373
port1 = connector.getLocalPort();
7474
logger.info("Local HTTP server started successfully");
75+
port2 = findFreePort();
7576
}
7677

7778
@Test(groups = "online")
@@ -96,19 +97,22 @@ public void redirected302Test() throws Exception {
9697
}
9798
}
9899

99-
// @Test(groups = "standalone")
100+
// @Test(groups = "standalone")
100101
public void redirected302InvalidTest() throws Exception {
101102
isSet.getAndSet(false);
103+
104+
Exception e = null;
102105

103-
// If the test hit a proxy, no ConnectException will be thrown and instead of 404 will be returned.
104106
try (AsyncHttpClient c = asyncHttpClient(config().setFollowRedirect(true))) {
105-
Response response = c.prepareGet(getTargetUrl()).setHeader("X-redirect", String.format("http://localhost:%d/", port2)).execute().get();
106-
107-
assertNotNull(response);
108-
assertEquals(response.getStatusCode(), 404);
107+
c.prepareGet(getTargetUrl()).setHeader("X-redirect", String.format("http://localhost:%d/", port2)).execute().get();
109108
} catch (ExecutionException ex) {
110-
assertEquals(ex.getCause().getClass(), ConnectException.class);
109+
e = ex;
111110
}
111+
112+
assertNotNull(e);
113+
Throwable cause = e.getCause();
114+
assertTrue(cause instanceof ConnectException);
115+
assertTrue(cause.getMessage().contains(":" + port2));
112116
}
113117

114118
// @Test(groups = "standalone")

0 commit comments

Comments
 (0)