Skip to content

Commit 5f99b55

Browse files
committed
Improve test
1 parent 78e6491 commit 5f99b55

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ private void testMYR(boolean multiplexImplementation) throws Exception {
8181
AtomicInteger inflightRequests = new AtomicInteger();
8282
AtomicInteger maxInflightRequests = new AtomicInteger();
8383
AtomicInteger receivedRstFrames = new AtomicInteger();
84-
CompletableFuture<Void> goAway = new CompletableFuture<>();
84+
CompletableFuture<Boolean> goAway = new CompletableFuture<>();
8585

8686
server.requestHandler(req -> {
8787
int val = inflightRequests.incrementAndGet();
@@ -153,7 +153,7 @@ public void onSettingsRead(ChannelHandlerContext ctx, Http2Settings settings) th
153153

154154
@Override
155155
public void onGoAwayRead(ChannelHandlerContext ctx, int lastStreamId, long errorCode, ByteBuf debugData) throws Http2Exception {
156-
goAway.complete(null);
156+
goAway.complete(true);
157157
}
158158
});
159159
return super.build();
@@ -167,7 +167,7 @@ public void onGoAwayRead(ChannelHandlerContext ctx, int lastStreamId, long error
167167
@Override
168168
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
169169
if (cause instanceof IOException && cause.getMessage().equals("Connection reset by peer")) {
170-
goAway.complete(null);
170+
goAway.complete(false);
171171
} else {
172172
goAway.completeExceptionally(cause);
173173
}
@@ -201,10 +201,13 @@ public ChannelFuture connect(int port, String host, BiConsumer<ChannelHandlerCon
201201
chctx.flush();
202202
}).sync();
203203

204-
goAway.get(20, TimeUnit.SECONDS);
205-
206204
// Check the number of rst frame received before getting a go away
207-
assertEquals(receivedRstFrames.get(), maxRstFramePerWindow + 1);
205+
if (goAway.get(20, TimeUnit.SECONDS)) {
206+
assertEquals(receivedRstFrames.get(), maxRstFramePerWindow + 1);
207+
} else {
208+
assertTrue(receivedRstFrames.get() < maxRstFramePerWindow + 1);
209+
}
210+
208211
assertTrue(maxInflightRequests.get() <= 2 * maxRstFramePerWindow );
209212
}
210213
}

0 commit comments

Comments
 (0)