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.
This commit is contained in:
Scott Mitchell 2017-08-16 08:00:22 -07:00
parent 5d9a5d3e8d
commit 053e6184f2

View File

@ -23,6 +23,8 @@ import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.CompositeByteBuf; import io.netty.buffer.CompositeByteBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.ChannelInboundHandlerAdapter;
@ -726,6 +728,9 @@ public class SslHandlerTest {
} }
ch.pipeline().addLast(handler); ch.pipeline().addLast(handler);
ch.pipeline().addLast(new ChannelInboundHandlerAdapter() { ch.pipeline().addLast(new ChannelInboundHandlerAdapter() {
private boolean sentData;
private Throwable writeCause;
@Override @Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) { public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
if (evt instanceof SslHandshakeCompletionEvent) { if (evt instanceof SslHandshakeCompletionEvent) {
@ -737,7 +742,15 @@ public class SslHandlerTest {
buf.writerIndex(buf.writerIndex() + singleComponentSize); buf.writerIndex(buf.writerIndex() + singleComponentSize);
content.addComponent(true, buf); 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 { } else {
donePromise.tryFailure(sslEvt.cause()); donePromise.tryFailure(sslEvt.cause());
} }
@ -747,12 +760,14 @@ public class SslHandlerTest {
@Override @Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
donePromise.tryFailure(cause); donePromise.tryFailure(new IllegalStateException("server exception sentData: " +
sentData + " writeCause: " + writeCause, cause));
} }
@Override @Override
public void channelInactive(ChannelHandlerContext ctx) { 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); 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 @Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
donePromise.tryFailure(cause); donePromise.tryFailure(new IllegalStateException("client exception. bytesSeen: " +
bytesSeen, cause));
} }
@Override @Override