@Test
public void testCloseOnInvalid() {

    ChannelFuture closeFuture = ch.closeFuture();
    String header = "GET / HTTP/1.1\r\n";
    try {
        ch.writeInbound(copiedBuffer(header, CharsetUtil.US_ASCII));
    } catch (HAProxyProtocolException ppex) {
        // swallow this exception since we're just testing to be sure the channel was closed
    }
    boolean isComplete = closeFuture.awaitUninterruptibly(5000);
    if (!isComplete || !closeFuture.isDone() || !closeFuture.isSuccess()) {
        fail("Expected channel close");
    }
}