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
32 changes: 22 additions & 10 deletions src/test/java/io/vertx/core/http/Http2MYRServerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -68,7 +66,7 @@ public void testMYR() throws Exception {
AtomicInteger inflightRequests = new AtomicInteger();
AtomicInteger maxInflightRequests = new AtomicInteger();
AtomicInteger receivedRstFrames = new AtomicInteger();
CompletableFuture<Void> goAway = new CompletableFuture<>();
CompletableFuture<Boolean> goAway = new CompletableFuture<>();

server.requestHandler(req -> {
int val = inflightRequests.incrementAndGet();
Expand Down Expand Up @@ -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();
Expand All @@ -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);
}
}
});
}
};
}
Expand Down Expand Up @@ -178,10 +186,14 @@ public ChannelFuture connect(int port, String host, BiConsumer<ChannelHandlerCon
chctx.flush();
}).sync();

goAway.get(10, TimeUnit.SECONDS);

// Check the number of rst frame received before getting a go away
assertEquals(receivedRstFrames.get(), maxRstFramePerWindow + 1);
assertEquals(maxInflightRequests.get(), maxRstFramePerWindow + 1);
if (goAway.get(20, TimeUnit.SECONDS)) {
assertEquals(receivedRstFrames.get(), maxRstFramePerWindow + 1);
} else {
// Mitigate CI behavior
assertTrue(receivedRstFrames.get() < maxRstFramePerWindow + 1);
}

assertTrue(maxInflightRequests.get() <= 2 * maxRstFramePerWindow );
}
}
Loading