Fix SSL tests that use SslProvider.OPENSSL_REFCNT (#9649)

Motivation:

031c2e2e88 introduced some change to reduce the risk of have the `ReferenceCountedOpenSslContext` be destroyed while the `ReferenceCountedSslEngine` is still in us. Unfortunaly it missed to adjust a few tests which make assumptions about the refCnt of the context.

Modifications:

Adjust tests to take new semenatics into acount.

Result:

No more tests failures
This commit is contained in:
Norman Maurer 2019-10-10 10:40:45 +04:00
parent 94598588bc
commit d794365411
2 changed files with 7 additions and 3 deletions

View File

@ -461,6 +461,7 @@ public class SniHandlerTest {
boolean success = false;
try {
assertEquals(1, ((ReferenceCountedOpenSslContext) sslContext).refCnt());
// The SniHandler's replaceHandler() method allows us to implement custom behavior.
// As an example, we want to release() the SslContext upon channelInactive() or rather
// when the SslHandler closes it's SslEngine. If you take a close look at SslHandler
@ -468,6 +469,7 @@ public class SniHandlerTest {
SSLEngine sslEngine = sslContext.newEngine(ctx.alloc());
try {
assertEquals(2, ((ReferenceCountedOpenSslContext) sslContext).refCnt());
SslHandler customSslHandler = new CustomSslHandler(sslContext, sslEngine) {
@Override
public void handlerRemoved0(ChannelHandlerContext ctx) throws Exception {
@ -514,8 +516,9 @@ public class SniHandlerTest {
cc.writeAndFlush(Unpooled.wrappedBuffer("Hello, World!".getBytes()))
.syncUninterruptibly();
// Notice how the server's SslContext refCnt is 1
assertEquals(1, ((ReferenceCounted) sslServerContext).refCnt());
// Notice how the server's SslContext refCnt is 2 as it is incremented when the SSLEngine is created
// and only decremented once it is destroyed.
assertEquals(2, ((ReferenceCounted) sslServerContext).refCnt());
// The client disconnects
cc.close().syncUninterruptibly();

View File

@ -329,10 +329,11 @@ public class SslHandlerTest {
.sslProvider(SslProvider.OPENSSL)
.build();
try {
assertEquals(1, ((ReferenceCounted) sslContext).refCnt());
SSLEngine sslEngine = sslContext.newEngine(ByteBufAllocator.DEFAULT);
EmbeddedChannel ch = new EmbeddedChannel(new SslHandler(sslEngine));
assertEquals(1, ((ReferenceCounted) sslContext).refCnt());
assertEquals(2, ((ReferenceCounted) sslContext).refCnt());
assertEquals(1, ((ReferenceCounted) sslEngine).refCnt());
assertTrue(ch.finishAndReleaseAll());