diff --git a/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2ControlFrameLimitEncoderTest.java b/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2ControlFrameLimitEncoderTest.java index b8144665bdd1..bbae3af5aeb4 100644 --- a/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2ControlFrameLimitEncoderTest.java +++ b/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2ControlFrameLimitEncoderTest.java @@ -38,6 +38,9 @@ import org.mockito.stubbing.Answer; +import java.util.ArrayDeque; +import java.util.Queue; + import static io.netty.handler.codec.http2.Http2CodecUtil.*; import static io.netty.handler.codec.http2.Http2Error.CANCEL; import static io.netty.handler.codec.http2.Http2Error.ENHANCE_YOUR_CALM; @@ -71,6 +74,8 @@ public class Http2ControlFrameLimitEncoderTest { private int numWrites; + private Queue goAwayPromises = new ArrayDeque(); + /** * Init fields and do mocking. */ @@ -116,7 +121,9 @@ public ChannelFuture answer(InvocationOnMock invocationOnMock) { @Override public ChannelFuture answer(InvocationOnMock invocationOnMock) { ReferenceCountUtil.release(invocationOnMock.getArgument(3)); - return handlePromise(invocationOnMock, 4); + ChannelPromise promise = invocationOnMock.getArgument(4); + goAwayPromises.offer(promise); + return promise; } }); Http2Connection connection = new DefaultHttp2Connection(false); @@ -168,6 +175,16 @@ private ChannelPromise handlePromise(InvocationOnMock invocationOnMock, int prom public void teardown() { // Close and release any buffered frames. encoder.close(); + + // Notify all goAway ChannelPromise instances now as these will also release the retained ByteBuf for the + // debugData. + for (;;) { + ChannelPromise promise = goAwayPromises.poll(); + if (promise == null) { + break; + } + promise.setSuccess(); + } } @Test @@ -254,12 +271,6 @@ private void verifyFlushAndClose(int invocations, boolean failed) { } } - private static void assertWriteFailure(ChannelFuture future) { - Http2Exception exception = (Http2Exception) future.cause(); - assertEquals(ShutdownHint.HARD_SHUTDOWN, exception.shutdownHint()); - assertEquals(Http2Error.ENHANCE_YOUR_CALM, exception.error()); - } - private ChannelPromise newPromise() { return new DefaultChannelPromise(channel, ImmediateEventExecutor.INSTANCE); }