From 584d674acdd1c03209c7b6de2e4e1d4939d648d6 Mon Sep 17 00:00:00 2001 From: Chris Vest Date: Wed, 5 May 2021 15:14:23 +0200 Subject: [PATCH] Bump initial timeouts in SSLEngineTest (#11221) Motivation: We've seen (very rare) flaky test failures due to timeouts. They are too rare to analyse properly, but a theory is that on overloaded, small cloud CI instances, it can sometimes take a surprising amount of time to start a thread. It could be that the event loop thread is getting an unlucky schedule, and takes seconds to start, causing the timeouts to elapse. Modification: Increase the initial timeouts in the SSLEngineTest, that could end up waiting for the event loop thread to start. Also fix a few simple warnings from Intellij. Result: Hopefully we will not see these tests be flaky again. --- .../io/netty/handler/ssl/SSLEngineTest.java | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/handler/src/test/java/io/netty/handler/ssl/SSLEngineTest.java b/handler/src/test/java/io/netty/handler/ssl/SSLEngineTest.java index 91716e44c3..94c1caf9cd 100644 --- a/handler/src/test/java/io/netty/handler/ssl/SSLEngineTest.java +++ b/handler/src/test/java/io/netty/handler/ssl/SSLEngineTest.java @@ -605,7 +605,7 @@ public abstract class SSLEngineTest { // Client trusts server but server only trusts itself mySetupMutualAuth(serverCrtFile, serverKeyFile, serverCrtFile, serverKeyPassword, serverCrtFile, clientKeyFile, clientCrtFile, clientKeyPassword); - assertTrue(serverLatch.await(2, TimeUnit.SECONDS)); + assertTrue(serverLatch.await(10, TimeUnit.SECONDS)); assertTrue(serverException instanceof SSLHandshakeException); } @@ -620,7 +620,7 @@ public abstract class SSLEngineTest { // Server trusts client but client only trusts itself mySetupMutualAuth(clientCrtFile, serverKeyFile, serverCrtFile, serverKeyPassword, clientCrtFile, clientKeyFile, clientCrtFile, clientKeyPassword); - assertTrue(clientLatch.await(2, TimeUnit.SECONDS)); + assertTrue(clientLatch.await(10, TimeUnit.SECONDS)); assertTrue(clientException instanceof SSLHandshakeException); } @@ -665,7 +665,7 @@ public abstract class SSLEngineTest { mySetupMutualAuth(serverKeyManagerFactory, commonCertChain, clientKeyManagerFactory, commonCertChain, auth, false, false); - assertTrue(clientLatch.await(5, TimeUnit.SECONDS)); + assertTrue(clientLatch.await(10, TimeUnit.SECONDS)); assertNull(clientException); assertTrue(serverLatch.await(5, TimeUnit.SECONDS)); assertNull(serverException); @@ -692,7 +692,7 @@ public abstract class SSLEngineTest { mySetupMutualAuth(serverKeyManagerFactory, commonCertChain, clientKeyManagerFactory, commonCertChain, auth, true, serverInitEngine); - assertTrue(clientLatch.await(5, TimeUnit.SECONDS)); + assertTrue(clientLatch.await(10, TimeUnit.SECONDS)); assertTrue("unexpected exception: " + clientException, mySetupMutualAuthServerIsValidClientException(clientException)); assertTrue(serverLatch.await(5, TimeUnit.SECONDS)); @@ -856,25 +856,25 @@ public abstract class SSLEngineTest { } @Test - public void testClientHostnameValidationSuccess() throws InterruptedException, SSLException { + public void testClientHostnameValidationSuccess() throws Exception { mySetupClientHostnameValidation(ResourcesUtil.getFile(getClass(), "localhost_server.pem"), ResourcesUtil.getFile(getClass(), "localhost_server.key"), ResourcesUtil.getFile(getClass(), "mutual_auth_ca.pem"), false); - assertTrue(clientLatch.await(5, TimeUnit.SECONDS)); + assertTrue(clientLatch.await(10, TimeUnit.SECONDS)); assertNull(clientException); assertTrue(serverLatch.await(5, TimeUnit.SECONDS)); assertNull(serverException); } @Test - public void testClientHostnameValidationFail() throws InterruptedException, SSLException { + public void testClientHostnameValidationFail() throws Exception { Future clientWriteFuture = mySetupClientHostnameValidation(ResourcesUtil.getFile(getClass(), "notlocalhost_server.pem"), ResourcesUtil.getFile(getClass(), "notlocalhost_server.key"), ResourcesUtil.getFile(getClass(), "mutual_auth_ca.pem"), true); - assertTrue(clientLatch.await(5, TimeUnit.SECONDS)); + assertTrue(clientLatch.await(10, TimeUnit.SECONDS)); assertTrue("unexpected exception: " + clientException, mySetupMutualAuthServerIsValidClientException(clientException)); assertTrue(serverLatch.await(5, TimeUnit.SECONDS)); @@ -1231,7 +1231,7 @@ public abstract class SSLEngineTest { MessageReceiver receiver) throws Exception { List dataCapture = null; try { - assertTrue(sendChannel.writeAndFlush(message).await(5, TimeUnit.SECONDS)); + assertTrue(sendChannel.writeAndFlush(message).await(10, TimeUnit.SECONDS)); receiverLatch.await(5, TimeUnit.SECONDS); message.readerIndex(0); ArgumentCaptor captor = ArgumentCaptor.forClass(ByteBuf.class); @@ -1379,8 +1379,7 @@ public abstract class SSLEngineTest { } @Test(timeout = 30000) - public void clientInitiatedRenegotiationWithFatalAlertDoesNotInfiniteLoopServer() - throws CertificateException, SSLException, InterruptedException, ExecutionException { + public void clientInitiatedRenegotiationWithFatalAlertDoesNotInfiniteLoopServer() throws Exception { assumeTrue(PlatformDependent.javaVersion() >= 11); final SelfSignedCertificate ssc = new SelfSignedCertificate(); serverSslCtx = wrapContext(SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()) @@ -3911,7 +3910,7 @@ public abstract class SSLEngineTest { } } - private KeyManagerFactory newKeyManagerFactory(SelfSignedCertificate ssc) + private static KeyManagerFactory newKeyManagerFactory(SelfSignedCertificate ssc) throws UnrecoverableKeyException, KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException { return SslContext.buildKeyManagerFactory(