Skip to content

Commit

Permalink
RATIS-2220. Skip further tests after leak detected (#1193)
Browse files Browse the repository at this point in the history
  • Loading branch information
adoroszlai authored Dec 23, 2024
1 parent 551b8c9 commit ee56932
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ Runnable track(Object leakable, Supplier<String> reportLeak) {
return trackers.add(leakable, queue, reportLeak)::remove;
}

public int getLeakCount() {
return trackers.getNumLeaks(false);
}

public void assertNoLeaks(int maxRetries, TimeDuration retrySleep) throws InterruptedException {
synchronized (leakMessages) {
// leakMessages are all the leaks discovered so far.
Expand Down
5 changes: 5 additions & 0 deletions ratis-common/src/test/java/org/apache/ratis/BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.ratis.util.ExitUtils;
import org.apache.ratis.util.FileUtils;
import org.apache.ratis.util.JavaUtils;
import org.apache.ratis.util.ReferenceCountedLeakDetector;
import org.apache.ratis.util.Slf4jUtils;
import org.apache.ratis.util.StringUtils;
import org.apache.ratis.util.TimeDuration;
Expand All @@ -30,6 +31,7 @@
import org.junit.Rule;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.Timeout;
Expand Down Expand Up @@ -97,6 +99,9 @@ public void setup(TestInfo testInfo) {
testCaseName = testInfo.getTestMethod()
.orElseThrow(() -> new RuntimeException("Exception while getting test name."))
.getName();

final int leaks = ReferenceCountedLeakDetector.getLeakDetector().getLeakCount();
Assumptions.assumeFalse(0 < leaks, () -> "numLeaks " + leaks + " > 0");
}

// @After annotation is retained to support junit 4 tests.
Expand Down

0 comments on commit ee56932

Please sign in to comment.