Skip to content

Commit

Permalink
ARTEMIS-4509: fail if LibaioContext check fouls before class, nicer i…
Browse files Browse the repository at this point in the history
…n CI than just logging and failing after anyway
  • Loading branch information
gemmellr committed Nov 16, 2023
1 parent 766e81d commit 54c1ae6
Showing 1 changed file with 25 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<>();
Expand Down Expand Up @@ -315,7 +315,6 @@ protected void clearServers() {
public TestRule watcher = new TestWatcher() {
@Override
protected void starting(Description description) {
testClassName = description.getClassName();
logger.info("**** start #test {}() ***", description.getMethodName());
}

Expand All @@ -325,6 +324,14 @@ protected void finished(Description description) {
}
};

@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";

Expand Down Expand Up @@ -2225,37 +2232,41 @@ private void closeAllOtherComponents() {

@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;
}

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) {
Expand Down

0 comments on commit 54c1ae6

Please sign in to comment.