Skip to content

Commit 954eef6

Browse files
committed
Stabilize test by keeping reference to NetClient
Closes #5853
1 parent 9a399e2 commit 954eef6

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

vertx-core/src/test/java/io/vertx/tests/http/HttpTest.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
package io.vertx.tests.http;
1313

14+
import io.netty.buffer.ByteBufUtil;
1415
import io.netty.channel.ConnectTimeoutException;
1516
import io.netty.channel.EventLoop;
1617
import io.netty.handler.codec.compression.DecompressionException;
@@ -4779,14 +4780,16 @@ protected void testHttpConnect(RequestOptions options, int sc) {
47794780
Buffer buffer = TestUtils.randomBuffer(128);
47804781
Buffer received = Buffer.buffer();
47814782
CompletableFuture<Void> closeSocket = new CompletableFuture<>();
4782-
vertx.createNetServer(new NetServerOptions().setPort(1235).setHost("localhost")).connectHandler(socket -> {
4783+
vertx.createNetServer(new NetServerOptions().setPort(0).setHost("localhost")).connectHandler(socket -> {
47834784
socket.handler(socket::write);
47844785
closeSocket.thenAccept(v -> {
47854786
socket.close();
47864787
});
47874788
}).listen().onComplete(onSuccess(netServer -> {
4789+
// Declare netClient here to avoid having it randomly garbage collected just after it created the connection
4790+
NetClient netClient = vertx.createNetClient(new NetClientOptions());
47884791
server.requestHandler(req -> {
4789-
vertx.createNetClient(new NetClientOptions()).connect(1235, "localhost").onComplete(onSuccess(dst -> {
4792+
netClient.connect(netServer.actualPort(), "localhost").onComplete(onSuccess(dst -> {
47904793

47914794
req.response().setStatusCode(sc);
47924795
req.response().setStatusMessage("Connection established");
@@ -4812,7 +4815,7 @@ protected void testHttpConnect(RequestOptions options, int sc) {
48124815
}
48134816
});
48144817
socket.closeHandler(v -> {
4815-
assertEquals(buffer, received);
4818+
assertEquals(ByteBufUtil.hexDump(buffer.getBytes()),ByteBufUtil.hexDump(received.getBytes()));
48164819
testComplete();
48174820
});
48184821
socket.write(buffer);

0 commit comments

Comments
 (0)