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 300e807ee6..329038250f 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 @@ -112,17 +112,26 @@ public class Http2ConnectionRoundtripTest { @Test public void stressTest() throws Exception { - Http2Headers headers = + final Http2Headers headers = new DefaultHttp2Headers.Builder().method("GET").scheme("https") .authority("example.org").path("/some/path/resource2").build(); - String text = "hello world"; + final String text = "hello world"; 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, - Unpooled.copiedBuffer(text.getBytes()), 0, true, true, false); - flush(); + final int streamId = nextStream; + clientChannel.eventLoop().execute(new Runnable() { + @Override + public void run() { + try { + http2Client.writeHeaders(ctx(), newPromise(), streamId, headers, 0, + (short) 16, false, 0, false, false); + http2Client.writeData(ctx(), newPromise(), streamId, + Unpooled.copiedBuffer(text.getBytes()), 0, true, true, false); + } catch (Http2Exception e) { + throw new RuntimeException(e); + } + } + }); } // Wait for all frames to be received. @@ -146,10 +155,6 @@ public class Http2ConnectionRoundtripTest { return ctx().newPromise(); } - private void flush() { - ctx().flush(); - } - /** * A decorator around the serverObserver that counts down the latch so that we can await the * completion of the request.