@Test
public void testServerCloseChannelSameEventLoop() throws Exception {

    final CountDownLatch latch = new CountDownLatch(1);
    ServerBootstrap sb = new ServerBootstrap()
            .group(group2)
            .channel(LocalServerChannel.class)
            .childHandler(new SimpleChannelInboundHandler<Object>() {
                @Override
                protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
                    ctx.close();
                    latch.countDown();
                }
            });
    Channel sc = null;
    Channel cc = null;
    try {
        sc = sb.bind(TEST_ADDRESS).sync().channel();
        Bootstrap b = new Bootstrap()
                .group(group2)
                .channel(LocalChannel.class)
                .handler(new SimpleChannelInboundHandler<Object>() {
                    @Override
                    protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
                        // discard
                    }
                });
        cc = b.connect(sc.localAddress()).sync().channel();
        cc.writeAndFlush(new Object());
        assertTrue(latch.await(5, SECONDS));
    } finally {
        closeChannel(cc);
        closeChannel(sc);
    }
}