Skip to content

Commit

Permalink
Improve 0RTT test (java-native-access#541)
Browse files Browse the repository at this point in the history
Motivation:

It seems like the 0RTT test fails sometimes due timeout. Let's add some
more fine-grained latches to make it easier to understand where the
problem is.

Modifications:

Add more CountDownLatch instances

Result:

Allow to debug why test fails
  • Loading branch information
normanmaurer authored Jun 23, 2023
1 parent aea65d1 commit 67480a9
Showing 1 changed file with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,8 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) {
.build();
Channel channel = QuicTestUtils.newClient(QuicTestUtils.newQuicClientBuilder(executor, sslContext)
.sslEngineProvider(q -> sslContext.newEngine(q.alloc(), "localhost", 9999)));
final CountDownLatch activeLatch = new CountDownLatch(1);
final CountDownLatch eventLatch = new CountDownLatch(1);
final CountDownLatch streamLatch = new CountDownLatch(1);
final AtomicReference<Throwable> errorRef = new AtomicReference<>();

Expand Down Expand Up @@ -643,9 +645,16 @@ public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {

quicChannel = QuicTestUtils.newQuicChannelBootstrap(channel)
.handler(new ChannelInboundHandlerAdapter() {
@Override
public void channelActive(ChannelHandlerContext ctx) {
activeLatch.countDown();
ctx.fireChannelActive();
}

@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
if (evt instanceof SslEarlyDataReadyEvent) {
eventLatch.countDown();
((QuicChannel) ctx.channel()).createStream(QuicStreamType.BIDIRECTIONAL,
new ChannelInboundHandlerAdapter()).addListener(f -> {
try {
Expand All @@ -671,10 +680,9 @@ public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
.connect()
.get();

streamLatch.await();
if (errorRef.get() != null) {
throw errorRef.get();
}
awaitAndCheckError(activeLatch, errorRef);
awaitAndCheckError(eventLatch, errorRef);
awaitAndCheckError(streamLatch, errorRef);

quicChannel.closeFuture().sync();
readLatch.await();
Expand All @@ -687,6 +695,14 @@ public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
}
}

private static void awaitAndCheckError(CountDownLatch latch, AtomicReference<Throwable> errorRef) throws Throwable {
while (!latch.await(500, TimeUnit.MILLISECONDS)) {
if (errorRef.get() != null) {
throw errorRef.get();
}
}
}

@ParameterizedTest
@MethodSource("newSslTaskExecutors")
public void testConnectAndStreamPriority(Executor executor) throws Throwable {
Expand Down

0 comments on commit 67480a9

Please sign in to comment.