Skip to content

Commit 7e8402e

Browse files
committed
Mitigate HTTP/2 MYR test on CI
1 parent e742df2 commit 7e8402e

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

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

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@
1313

1414
import io.netty.bootstrap.Bootstrap;
1515
import io.netty.buffer.ByteBuf;
16-
import io.netty.channel.Channel;
17-
import io.netty.channel.ChannelFuture;
18-
import io.netty.channel.ChannelHandlerContext;
19-
import io.netty.channel.ChannelInitializer;
16+
import io.netty.channel.*;
2017
import io.netty.channel.nio.NioEventLoopGroup;
2118
import io.netty.channel.socket.nio.NioSocketChannel;
2219
import io.netty.handler.codec.http2.AbstractHttp2ConnectionHandlerBuilder;
@@ -44,6 +41,7 @@
4441
import io.vertx.test.core.Repeat;
4542
import org.junit.Test;
4643

44+
import java.io.IOException;
4745
import java.net.InetSocketAddress;
4846
import java.util.concurrent.CompletableFuture;
4947
import java.util.concurrent.TimeUnit;
@@ -82,7 +80,7 @@ private void testMYR(boolean multiplexImplementation) throws Exception {
8280
AtomicInteger inflightRequests = new AtomicInteger();
8381
AtomicInteger maxInflightRequests = new AtomicInteger();
8482
AtomicInteger receivedRstFrames = new AtomicInteger();
85-
CompletableFuture<Void> goAway = new CompletableFuture<>();
83+
CompletableFuture<Boolean> goAway = new CompletableFuture<>();
8684

8785
server.requestHandler(req -> {
8886
int val = inflightRequests.incrementAndGet();
@@ -154,7 +152,7 @@ public void onSettingsRead(ChannelHandlerContext ctx, Http2Settings settings) th
154152

155153
@Override
156154
public void onGoAwayRead(ChannelHandlerContext ctx, int lastStreamId, long errorCode, ByteBuf debugData) throws Http2Exception {
157-
goAway.complete(null);
155+
goAway.complete(true);
158156
}
159157
});
160158
return super.build();
@@ -164,6 +162,16 @@ public void onGoAwayRead(ChannelHandlerContext ctx, int lastStreamId, long error
164162
Builder clientHandlerBuilder = new Builder();
165163
Http2ConnectionHandler clientHandler = clientHandlerBuilder.build();
166164
ch.pipeline().addLast(clientHandler);
165+
ch.pipeline().addLast(new ChannelDuplexHandler() {
166+
@Override
167+
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
168+
if (cause instanceof IOException && cause.getMessage().startsWith("Connection reset")) {
169+
goAway.complete(false);
170+
} else {
171+
goAway.completeExceptionally(cause);
172+
}
173+
}
174+
});
167175
}
168176
};
169177
}
@@ -192,10 +200,14 @@ public ChannelFuture connect(int port, String host, BiConsumer<ChannelHandlerCon
192200
chctx.flush();
193201
}).sync();
194202

195-
goAway.get(10, TimeUnit.SECONDS);
196-
197203
// Check the number of rst frame received before getting a go away
198-
assertEquals(receivedRstFrames.get(), maxRstFramePerWindow + 1);
204+
if (goAway.get(20, TimeUnit.SECONDS)) {
205+
assertEquals(receivedRstFrames.get(), maxRstFramePerWindow + 1);
206+
} else {
207+
// Mitigate CI behavior
208+
assertTrue(receivedRstFrames.get() < maxRstFramePerWindow + 1);
209+
}
210+
199211
assertTrue(maxInflightRequests.get() <= 2 * maxRstFramePerWindow );
200212
}
201213
}

0 commit comments

Comments
 (0)