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 committed by GitHub
parent a31a3e31da
commit 35862cad7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 3 deletions

View File

@ -464,6 +464,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
@ -471,6 +472,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 {
@ -517,8 +519,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

@ -328,10 +328,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());