From e3f5414d261808ba44fc70f1daaefe75b238b375 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Fri, 9 May 2014 08:30:06 +0200 Subject: [PATCH] Fix a race in Http2ConnectionRoundtripTest that could lead to a NPE. --- .../codec/http2/Http2ConnectionRoundtripTest.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2ConnectionRoundtripTest.java b/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2ConnectionRoundtripTest.java index 21b0418ebd..300e807ee6 100644 --- a/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2ConnectionRoundtripTest.java +++ b/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2ConnectionRoundtripTest.java @@ -62,7 +62,8 @@ public class Http2ConnectionRoundtripTest { private Bootstrap cb; private Channel serverChannel; private Channel clientChannel; - private CountDownLatch requestLatch; + private static final int NUM_STREAMS = 1000; + private final CountDownLatch requestLatch = new CountDownLatch(NUM_STREAMS * 2); @Before public void setup() throws Exception { @@ -115,11 +116,8 @@ public class Http2ConnectionRoundtripTest { new DefaultHttp2Headers.Builder().method("GET").scheme("https") .authority("example.org").path("/some/path/resource2").build(); String text = "hello world"; - int numStreams = 1000; - int expectedFrames = numStreams * 2; - requestLatch = new CountDownLatch(expectedFrames); - for (int i = 0, nextStream = 3; i < numStreams; ++i, nextStream += 2) { + for (int i = 0, nextStream = 3; i < NUM_STREAMS; ++i, nextStream += 2) { http2Client.writeHeaders(ctx(), newPromise(), nextStream, headers, 0, (short) 16, false, 0, false, false); http2Client.writeData(ctx(), newPromise(), nextStream, @@ -129,10 +127,10 @@ public class Http2ConnectionRoundtripTest { // Wait for all frames to be received. awaitRequests(); - verify(serverObserver, times(numStreams)).onHeadersRead(any(ChannelHandlerContext.class), + verify(serverObserver, times(NUM_STREAMS)).onHeadersRead(any(ChannelHandlerContext.class), anyInt(), eq(headers), eq(0), eq((short) 16), eq(false), eq(0), eq(false), eq(false)); - verify(serverObserver, times(numStreams)).onDataRead(any(ChannelHandlerContext.class), + verify(serverObserver, times(NUM_STREAMS)).onDataRead(any(ChannelHandlerContext.class), anyInt(), eq(Unpooled.copiedBuffer(text.getBytes())), eq(0), eq(true), eq(true), eq(false)); }