Skip to content

Commit 9554f72

Browse files
committed
Properly close client but test is disabled anyway
1 parent 9f817eb commit 9554f72

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

client/src/test/java/org/asynchttpclient/netty/TimeToLiveIssue.java

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,40 +12,38 @@
1212
*/
1313
package org.asynchttpclient.netty;
1414

15-
import org.asynchttpclient.*;
16-
import org.testng.annotations.Test;
15+
import static org.asynchttpclient.Dsl.*;
1716

1817
import java.util.concurrent.Future;
1918
import java.util.concurrent.TimeUnit;
2019

21-
import static org.testng.Assert.assertEquals;
20+
import org.asynchttpclient.AbstractBasicTest;
21+
import org.asynchttpclient.AsyncHttpClient;
22+
import org.asynchttpclient.Request;
23+
import org.asynchttpclient.RequestBuilder;
24+
import org.asynchttpclient.Response;
25+
import org.testng.annotations.Test;
2226

23-
public class TimeToLiveIssue extends AbstractBasicTest
24-
{
25-
@Test(groups = "standalone", enabled = false, description = "https://github.com/AsyncHttpClient/async-http-client/issues/1113")
26-
public void testTTLBug() throws Throwable
27-
{
27+
public class TimeToLiveIssue extends AbstractBasicTest {
28+
@Test(enabled = false, description = "https://github.com/AsyncHttpClient/async-http-client/issues/1113")
29+
public void testTTLBug() throws Throwable {
2830
// The purpose of this test is to reproduce two issues:
2931
// 1) Connections that are rejected by the pool are not closed and eventually use all available sockets.
3032
// 2) It is possible for a connection to be closed while active by the timer task that checks for expired connections.
3133

32-
DefaultAsyncHttpClientConfig.Builder config = new DefaultAsyncHttpClientConfig.Builder();
33-
config.setKeepAlive(true);
34-
config.setConnectionTtl(1);
35-
config.setPooledConnectionIdleTimeout(1);
36-
37-
AsyncHttpClient client = new DefaultAsyncHttpClient(config.build());
34+
try (AsyncHttpClient client = asyncHttpClient(config().setKeepAlive(true).setConnectionTtl(1).setPooledConnectionIdleTimeout(1))) {
3835

39-
for (int i = 0; i < 200000; ++i) {
40-
Request request = new RequestBuilder().setUrl(String.format("http://localhost:%d/", port1)).build();
36+
for (int i = 0; i < 200000; ++i) {
37+
Request request = new RequestBuilder().setUrl(String.format("http://localhost:%d/", port1)).build();
4138

42-
Future<Response> future = client.executeRequest(request);
43-
future.get(5, TimeUnit.SECONDS);
39+
Future<Response> future = client.executeRequest(request);
40+
future.get(5, TimeUnit.SECONDS);
4441

45-
// This is to give a chance to the timer task that removes expired connection
46-
// from sometimes winning over poll for the ownership of a connection.
47-
if (System.currentTimeMillis() % 100 == 0) {
48-
Thread.sleep(5);
42+
// This is to give a chance to the timer task that removes expired connection
43+
// from sometimes winning over poll for the ownership of a connection.
44+
if (System.currentTimeMillis() % 100 == 0) {
45+
Thread.sleep(5);
46+
}
4947
}
5048
}
5149
}

0 commit comments

Comments
 (0)