From 7bf2dfa3b1a1bb324cc6cb802964ddb13d188d2d Mon Sep 17 00:00:00 2001 From: Clint Wylie Date: Wed, 8 Apr 2020 10:07:06 -0700 Subject: [PATCH] fix flaky jetty test (#9633) --- .../apache/druid/server/initialization/JettyTest.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/server/src/test/java/org/apache/druid/server/initialization/JettyTest.java b/server/src/test/java/org/apache/druid/server/initialization/JettyTest.java index 64ccd148769..206c3186e02 100644 --- a/server/src/test/java/org/apache/druid/server/initialization/JettyTest.java +++ b/server/src/test/java/org/apache/druid/server/initialization/JettyTest.java @@ -78,6 +78,7 @@ import java.util.Map; import java.util.concurrent.CountDownLatch; import java.util.concurrent.Executor; import java.util.concurrent.Executors; +import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; import java.util.zip.GZIPInputStream; @@ -186,6 +187,8 @@ public class JettyTest extends BaseJettyTest throw new RuntimeException(e); } + final int ephemeralPort = ThreadLocalRandom.current().nextInt(49152, 65535); + latchedRequestState = new LatchedRequestStateHolder(); injector = Initialization.makeInjectorWithModules( GuiceInjectors.makeStartupInjector(), @@ -198,7 +201,7 @@ public class JettyTest extends BaseJettyTest JsonConfigProvider.bindInstance( binder, Key.get(DruidNode.class, Self.class), - new DruidNode("test", "localhost", false, 9988, 9999, true, true) + new DruidNode("test", "localhost", false, ephemeralPort, ephemeralPort + 1, true, true) ); binder.bind(TLSServerConfig.class).toInstance(tlsConfig); binder.bind(JettyServerInitializer.class).to(JettyServerInit.class).in(LazySingleton.class); @@ -450,6 +453,7 @@ public class JettyTest extends BaseJettyTest JettyServerModule jsm = injector.getInstance(JettyServerModule.class); latchedRequestState.reset(); + waitForJettyServerModuleActiveConnectionsZero(jsm); Assert.assertEquals(0, jsm.getActiveConnections()); ListenableFuture go = client.go( @@ -489,6 +493,7 @@ public class JettyTest extends BaseJettyTest JettyServerModule jsm = injector.getInstance(JettyServerModule.class); latchedRequestState.reset(); + waitForJettyServerModuleActiveConnectionsZero(jsm); Assert.assertEquals(0, jsm.getActiveConnections()); ListenableFuture go = client.go( request, @@ -511,5 +516,8 @@ public class JettyTest extends BaseJettyTest while (jsm.getActiveConnections() > 0 && count++ < totalSleeps) { Thread.sleep(sleepTimeMills); } + if (jsm.getActiveConnections() > 0) { + throw new RuntimeException("Connections greater than 0"); + } } }