Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/test/java/io/vertx/core/http/HttpTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

package io.vertx.core.http;

import io.netty.buffer.ByteBufUtil;
import io.netty.channel.ConnectTimeoutException;
import io.netty.handler.codec.compression.DecompressionException;
import io.netty.handler.codec.http.HttpHeaderNames;
Expand Down Expand Up @@ -5179,14 +5180,17 @@ protected void testHttpConnect(RequestOptions options, int sc) {
Buffer buffer = TestUtils.randomBuffer(128);
Buffer received = Buffer.buffer();
CompletableFuture<Void> closeSocket = new CompletableFuture<>();
vertx.createNetServer(new NetServerOptions().setPort(1235).setHost("localhost")).connectHandler(socket -> {
// Declare netClient in the main thread to avoid having it randomly garbage collected just after it created the connection
NetClient netClient = vertx.createNetClient(new NetClientOptions());

vertx.createNetServer(new NetServerOptions().setPort(0).setHost("localhost")).connectHandler(socket -> {
socket.handler(socket::write);
closeSocket.thenAccept(v -> {
socket.close();
});
}).listen(onSuccess(netServer -> {
server.requestHandler(req -> {
vertx.createNetClient(new NetClientOptions()).connect(1235, "localhost", onSuccess(dst -> {
netClient.connect(netServer.actualPort(), "localhost", onSuccess(dst -> {

req.response().setStatusCode(sc);
req.response().setStatusMessage("Connection established");
Expand Down Expand Up @@ -5217,7 +5221,7 @@ protected void testHttpConnect(RequestOptions options, int sc) {
}
});
socket.closeHandler(v -> {
assertEquals(buffer, received);
assertEquals(ByteBufUtil.hexDump(buffer.getBytes()), ByteBufUtil.hexDump(received.getBytes()));
testComplete();
});
socket.write(buffer);
Expand Down
Loading