diff --git a/vertx-core/src/test/java/io/vertx/tests/http/Http2Test.java b/vertx-core/src/test/java/io/vertx/tests/http/Http2Test.java index 213a072c0d1..1bad37fe595 100644 --- a/vertx-core/src/test/java/io/vertx/tests/http/Http2Test.java +++ b/vertx-core/src/test/java/io/vertx/tests/http/Http2Test.java @@ -19,6 +19,7 @@ import io.vertx.core.buffer.Buffer; import io.vertx.core.http.*; import io.vertx.core.net.JdkSSLEngineOptions; +import io.vertx.core.net.NetClient; import io.vertx.core.net.NetSocket; import io.vertx.core.net.OpenSSLEngineOptions; import io.vertx.core.net.SSLEngineOptions; @@ -53,6 +54,8 @@ */ public class Http2Test extends HttpTest { + private NetClient netClient; + public Http2Test() { this(false); } @@ -735,7 +738,10 @@ public void testSslHandshakeTimeout(Checkpoint checkpoint) throws Exception { } }); startServer(); - NetSocket so = vertx.createNetClient().connect(config.port(), config.host()).await(); + // Keep a reference to the client: an unreferenced client is closed when it is garbage collected, which + // would close the connection before the handshake timeout happens + netClient = vertx.createNetClient(); + netClient.connect(config.port(), config.host()).await(); } @Test diff --git a/vertx-core/src/test/java/io/vertx/tests/http/HttpConnectionEarlyResetTest.java b/vertx-core/src/test/java/io/vertx/tests/http/HttpConnectionEarlyResetTest.java index b06c1c186be..73fdea0342b 100644 --- a/vertx-core/src/test/java/io/vertx/tests/http/HttpConnectionEarlyResetTest.java +++ b/vertx-core/src/test/java/io/vertx/tests/http/HttpConnectionEarlyResetTest.java @@ -14,6 +14,7 @@ import io.vertx.core.Context; import io.vertx.core.Vertx; import io.vertx.core.http.HttpServer; +import io.vertx.core.net.NetClient; import io.vertx.core.net.NetClientOptions; import io.vertx.test.core.VertxTestBase; import io.vertx.test.http.HttpTestBase; @@ -34,6 +35,7 @@ public class HttpConnectionEarlyResetTest extends VertxTestBase { private HttpServer httpServer; + private NetClient client; private AtomicReference caught = new AtomicReference<>(); private CountDownLatch resetLatch = new CountDownLatch(1); @@ -57,7 +59,10 @@ public void setUp() throws Exception { @Test public void testExceptionCaught() throws Exception { - vertx.createNetClient(new NetClientOptions().setSoLinger(0)).connect(HttpTestBase.DEFAULT_HTTP_PORT, "localhost").onComplete(onSuccess(socket -> { + // Keep a reference to the client: an unreferenced client is closed when it is garbage collected, which + // would close the connection gracefully before the reset + client = vertx.createNetClient(new NetClientOptions().setSoLinger(0)); + client.connect(HttpTestBase.DEFAULT_HTTP_PORT, "localhost").onComplete(onSuccess(socket -> { vertx.setTimer(2000, id -> { socket.close(); });