Skip to content

Commit

Permalink
Fix race in http2 test (netty#12547)
Browse files Browse the repository at this point in the history
Motivation:

As we access the handler directly we need to ensure we wait until its added to the pipeline to eliminate races.

Modification:

Add latch to ensure we wait until the handlers are added

Result:

No more race in test
  • Loading branch information
normanmaurer authored and franz1981 committed Aug 22, 2022
1 parent 1e7d280 commit 9d3614b
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public class InboundHttp2ToHttpAdapterTest {
private CountDownLatch serverLatch2;
private CountDownLatch clientLatch2;
private CountDownLatch settingsLatch;
private CountDownLatch clientHandlersAddedLatch;
private int maxContentLength;
private HttpResponseDelegator serverDelegator;
private HttpResponseDelegator clientDelegator;
Expand Down Expand Up @@ -663,6 +664,7 @@ private void boostrapEnv(int clientLatchCount, int clientLatchCount2, int server
serverLatch2 = new CountDownLatch(serverLatchCount2);
clientLatch2 = new CountDownLatch(clientLatchCount2);
settingsLatch = new CountDownLatch(settingsLatchCount);
clientHandlersAddedLatch = new CountDownLatch(1);

sb = new ServerBootstrap();
cb = new Bootstrap();
Expand Down Expand Up @@ -735,6 +737,12 @@ public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exc
}
}
});
p.addLast(new ChannelInboundHandlerAdapter() {
@Override
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
clientHandlersAddedLatch.countDown();
}
});
}
});

Expand All @@ -745,6 +753,7 @@ public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exc
clientChannel = ccf.channel();
assertTrue(prefaceWrittenLatch.await(5, SECONDS));
assertTrue(serverChannelLatch.await(5, SECONDS));
assertTrue(clientHandlersAddedLatch.await(5, SECONDS));
}

private void cleanupCapturedRequests() {
Expand Down

0 comments on commit 9d3614b

Please sign in to comment.