diff --git a/src/test/java/io/vertx/core/http/Http2MYRServerTest.java b/src/test/java/io/vertx/core/http/Http2MYRServerTest.java index 5deb3a8b6bc..0bd22a9a2b0 100644 --- a/src/test/java/io/vertx/core/http/Http2MYRServerTest.java +++ b/src/test/java/io/vertx/core/http/Http2MYRServerTest.java @@ -12,10 +12,7 @@ import io.netty.bootstrap.Bootstrap; import io.netty.buffer.ByteBuf; -import io.netty.channel.Channel; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelInitializer; +import io.netty.channel.*; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.handler.codec.http2.AbstractHttp2ConnectionHandlerBuilder; @@ -40,6 +37,7 @@ import io.netty.handler.codec.http2.Http2Settings; import org.junit.Test; +import java.io.IOException; import java.net.InetSocketAddress; import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; @@ -68,7 +66,7 @@ public void testMYR() throws Exception { AtomicInteger inflightRequests = new AtomicInteger(); AtomicInteger maxInflightRequests = new AtomicInteger(); AtomicInteger receivedRstFrames = new AtomicInteger(); - CompletableFuture goAway = new CompletableFuture<>(); + CompletableFuture goAway = new CompletableFuture<>(); server.requestHandler(req -> { int val = inflightRequests.incrementAndGet(); @@ -140,7 +138,7 @@ public void onSettingsRead(ChannelHandlerContext ctx, Http2Settings settings) th @Override public void onGoAwayRead(ChannelHandlerContext ctx, int lastStreamId, long errorCode, ByteBuf debugData) throws Http2Exception { - goAway.complete(null); + goAway.complete(true); } }); return super.build(); @@ -150,6 +148,16 @@ public void onGoAwayRead(ChannelHandlerContext ctx, int lastStreamId, long error Builder clientHandlerBuilder = new Builder(); Http2ConnectionHandler clientHandler = clientHandlerBuilder.build(); ch.pipeline().addLast(clientHandler); + ch.pipeline().addLast(new ChannelDuplexHandler() { + @Override + public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { + if (cause instanceof IOException && cause.getMessage().startsWith("Connection reset")) { + goAway.complete(false); + } else { + goAway.completeExceptionally(cause); + } + } + }); } }; } @@ -178,10 +186,14 @@ public ChannelFuture connect(int port, String host, BiConsumer