ARTEMIS-4509: fail if LibaioContext check fouls before class, nicer in CI than just logging and failing after anyway

This commit is contained in:
Robbie Gemmell 2023-11-16 10:43:07 +00:00
parent 766e81d26e
commit 54c1ae630c
1 changed files with 25 additions and 14 deletions

View File

@ -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<Thread> 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) {