From 053e6184f2d6fb2847338d807730d2edf7cfc94a Mon Sep 17 00:00:00 2001 From: Scott Mitchell Date: Wed, 16 Aug 2017 08:00:22 -0700 Subject: [PATCH] Increase visibility for SslHandlerTest#testCompositeBufSizeEstimationGuaranteesSynchronousWrite Motivation: SslHandlerTest#testCompositeBufSizeEstimationGuaranteesSynchronousWrite has been observed to fail on CI servers, but it is not clear why. Modifications: - Add more visibility into what the state was and what the condition that caused the failure was. Result: More visibility when the test fails. --- .../io/netty/handler/ssl/SslHandlerTest.java | 34 ++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/handler/src/test/java/io/netty/handler/ssl/SslHandlerTest.java b/handler/src/test/java/io/netty/handler/ssl/SslHandlerTest.java index 15ea3650be..a1f81d276f 100644 --- a/handler/src/test/java/io/netty/handler/ssl/SslHandlerTest.java +++ b/handler/src/test/java/io/netty/handler/ssl/SslHandlerTest.java @@ -23,6 +23,8 @@ import io.netty.buffer.ByteBufAllocator; import io.netty.buffer.CompositeByteBuf; import io.netty.buffer.Unpooled; import io.netty.channel.Channel; +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; @@ -726,6 +728,9 @@ public class SslHandlerTest { } ch.pipeline().addLast(handler); ch.pipeline().addLast(new ChannelInboundHandlerAdapter() { + private boolean sentData; + private Throwable writeCause; + @Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) { if (evt instanceof SslHandshakeCompletionEvent) { @@ -737,7 +742,15 @@ public class SslHandlerTest { buf.writerIndex(buf.writerIndex() + singleComponentSize); content.addComponent(true, buf); } - ctx.writeAndFlush(content); + ctx.writeAndFlush(content).addListener(new ChannelFutureListener() { + @Override + public void operationComplete(ChannelFuture future) throws Exception { + writeCause = future.cause(); + if (writeCause == null) { + sentData = true; + } + } + }); } else { donePromise.tryFailure(sslEvt.cause()); } @@ -747,12 +760,14 @@ public class SslHandlerTest { @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { - donePromise.tryFailure(cause); + donePromise.tryFailure(new IllegalStateException("server exception sentData: " + + sentData + " writeCause: " + writeCause, cause)); } @Override public void channelInactive(ChannelHandlerContext ctx) { - donePromise.tryFailure(new IllegalStateException("server closed")); + donePromise.tryFailure(new IllegalStateException("server closed sentData: " + + sentData + " writeCause: " + writeCause)); } }); } @@ -782,9 +797,20 @@ public class SslHandlerTest { ReferenceCountUtil.release(msg); } + @Override + public void userEventTriggered(ChannelHandlerContext ctx, Object evt) { + if (evt instanceof SslHandshakeCompletionEvent) { + SslHandshakeCompletionEvent sslEvt = (SslHandshakeCompletionEvent) evt; + if (!sslEvt.isSuccess()) { + donePromise.tryFailure(sslEvt.cause()); + } + } + } + @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { - donePromise.tryFailure(cause); + donePromise.tryFailure(new IllegalStateException("client exception. bytesSeen: " + + bytesSeen, cause)); } @Override