@Test
public void handlerRemovedWillNotReleaseBufferIfDecodeInProgress() {

    EmbeddedChannel channel = new EmbeddedChannel(new ByteToMessageDecoder() {
        @Override
        protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
            ctx.pipeline().remove(this);
            assertTrue(in.refCnt() != 0);
        }
        @Override
        protected void handlerRemoved0(ChannelHandlerContext ctx) throws Exception {
            assertCumulationReleased(internalBuffer());
        }
    });
    byte[] bytes = new byte[1024];
    PlatformDependent.threadLocalRandom().nextBytes(bytes);
    assertTrue(channel.writeInbound(Unpooled.wrappedBuffer(bytes)));
    assertTrue(channel.finishAndReleaseAll());
}