From 3337d253a6fe46b169ef94ba0c5c7df641ef8f2f Mon Sep 17 00:00:00 2001 From: Clebert Suconic Date: Fri, 18 Dec 2020 09:24:29 -0500 Subject: [PATCH] NO-JIRA Fixing Intermittent failures --- .../artemis/tests/util/ActiveMQTestBase.java | 36 +++++++++---------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/ActiveMQTestBase.java b/artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/ActiveMQTestBase.java index 2e195f1db6..85dd47f172 100644 --- a/artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/ActiveMQTestBase.java +++ b/artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/ActiveMQTestBase.java @@ -44,6 +44,7 @@ import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -336,7 +337,7 @@ public abstract class ActiveMQTestBase extends Assert { closeAllOtherComponents(); - ArrayList exceptions; + List exceptions; try { exceptions = checkCsfStopped(); } finally { @@ -355,7 +356,6 @@ public abstract class ActiveMQTestBase extends Assert { exception.printStackTrace(System.out); } System.out.println(threadDump("Thread dump with reconnects happening")); - fail("Client Session Factories still trying to reconnect, see above to see where created"); } Map threadMap = Thread.getAllStackTraces(); for (Map.Entry entry : threadMap.entrySet()) { @@ -2009,29 +2009,25 @@ public abstract class ActiveMQTestBase extends Assert { } } - private ArrayList checkCsfStopped() { - long time = System.currentTimeMillis(); - long waitUntil = time + 5000; - while (!ClientSessionFactoryImpl.CLOSE_RUNNABLES.isEmpty() && time < waitUntil) { - try { - Thread.sleep(50); - } catch (InterruptedException e) { - //ignore - } - time = System.currentTimeMillis(); - } - List closeRunnables = new ArrayList<>(ClientSessionFactoryImpl.CLOSE_RUNNABLES); - ArrayList exceptions = new ArrayList<>(); + private List checkCsfStopped() throws Exception { + if (!Wait.waitFor(ClientSessionFactoryImpl.CLOSE_RUNNABLES::isEmpty, 5_000)) { + List closeRunnables = new ArrayList<>(ClientSessionFactoryImpl.CLOSE_RUNNABLES); + ArrayList exceptions = new ArrayList<>(); - if (!closeRunnables.isEmpty()) { - for (ClientSessionFactoryImpl.CloseRunnable closeRunnable : closeRunnables) { - if (closeRunnable != null) { - exceptions.add(closeRunnable.stop().createTrace); + if (!closeRunnables.isEmpty()) { + for (ClientSessionFactoryImpl.CloseRunnable closeRunnable : closeRunnables) { + if (closeRunnable != null) { + exceptions.add(closeRunnable.stop().createTrace); + } } } + return exceptions; } - return exceptions; + return Collections.EMPTY_LIST; + + + } private void assertAllClientProducersAreClosed() {