From 54c1ae630cffea20cfcce42d9d7e5b7834ffa6f0 Mon Sep 17 00:00:00 2001 From: Robbie Gemmell Date: Thu, 16 Nov 2023 10:43:07 +0000 Subject: [PATCH] ARTEMIS-4509: fail if LibaioContext check fouls before class, nicer in CI than just logging and failing after anyway --- .../artemis/tests/util/ActiveMQTestBase.java | 39 ++++++++++++------- 1 file changed, 25 insertions(+), 14 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 2e13383dc5..f3816afde7 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 @@ -220,7 +220,7 @@ public abstract class ActiveMQTestBase extends Assert { protected static final long WAIT_TIMEOUT = 30000; private static String testClassName = "not-yet-set"; - private static String failingTotalMaxIoMessage; + private static String previouslyFailedTotalMaxIoMessage; // There is a verification about thread leakages. We only fail a single thread when this happens private static Set alreadyFailedThread = new HashSet<>(); @@ -315,7 +315,6 @@ public abstract class ActiveMQTestBase extends Assert { public TestRule watcher = new TestWatcher() { @Override protected void starting(Description description) { - testClassName = description.getClassName(); logger.info("**** start #test {}() ***", description.getMethodName()); } @@ -325,6 +324,14 @@ public abstract class ActiveMQTestBase extends Assert { } }; + @ClassRule + public static TestRule classWatcher = new TestWatcher() { + @Override + protected void starting(Description description) { + testClassName = description.getClassName(); + } + }; + // Static variable used by dropDerby private static final String EXPECTED_DERBY_DROP_STATE = "08006"; @@ -2225,20 +2232,20 @@ public abstract class ActiveMQTestBase extends Assert { @BeforeClass public static void checkLibaioBeforeClass() throws Throwable { - if (failingTotalMaxIoMessage != null) { + if (previouslyFailedTotalMaxIoMessage != null) { // Fail immediately if this is already set. - fail(failingTotalMaxIoMessage); + fail(previouslyFailedTotalMaxIoMessage); } long totalMaxIO = LibaioContext.getTotalMaxIO(); if (totalMaxIO != 0) { - logger.error("LibaioContext TotalMaxIO > 0 before beginning test class. Issue presumably arose in a preceding class (not possible to be sure of which here). TotalMaxIO = {}", totalMaxIO); + failDueToLibaioContextCheck("LibaioContext TotalMaxIO > 0 leak detected BEFORE class %s, TotalMaxIO=%s. Check prior test classes for issue (not possible to be sure of which here).", totalMaxIO); } } @AfterClass - public static void checkLibaio() throws Throwable { - if (failingTotalMaxIoMessage != null) { + public static void checkLibaioAfterClass() throws Throwable { + if (previouslyFailedTotalMaxIoMessage != null) { // Test class was already failed if this is set, nothing to do here. return; } @@ -2246,16 +2253,20 @@ public abstract class ActiveMQTestBase extends Assert { if (!Wait.waitFor(() -> LibaioContext.getTotalMaxIO() == 0)) { long totalMaxIO = LibaioContext.getTotalMaxIO(); - // Set messsage to fail subsequent runs with - failingTotalMaxIoMessage = String.format("Aborting, LibaioContext TotalMaxIO > 0 issue previously detected by test class %s(), see its output.", testClassName); - - // Now fail this run - String message = String.format("LibaioContext TotalMaxIO > 0 leak detected after class %s(), TotalMaxIO=%s(). Check output to determine if occurred before/during.", testClassName, totalMaxIO); - logger.error(message); - Assert.fail(message); + failDueToLibaioContextCheck("LibaioContext TotalMaxIO > 0 leak detected AFTER class %s, TotalMaxIO=%s.", totalMaxIO); } } + private static void failDueToLibaioContextCheck(String currentFailureMessageFormat, long totalMaxIO) { + // Set message to immediately-fail subsequent tests with + previouslyFailedTotalMaxIoMessage = String.format("Aborting, LibaioContext TotalMaxIO > 0 issue previously detected by test class %s, see its output.", testClassName); + + // Now fail this run + String message = String.format(currentFailureMessageFormat, testClassName, totalMaxIO); + logger.error(message); + Assert.fail(message); + } + private void checkFilesUsage() throws Exception { int invmSize = InVMRegistry.instance.size(); if (invmSize > 0) {