Skip to content

Commit ee56932

Browse files
authored
RATIS-2220. Skip further tests after leak detected (#1193)
1 parent 551b8c9 commit ee56932

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

ratis-common/src/main/java/org/apache/ratis/util/LeakDetector.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ Runnable track(Object leakable, Supplier<String> reportLeak) {
156156
return trackers.add(leakable, queue, reportLeak)::remove;
157157
}
158158

159+
public int getLeakCount() {
160+
return trackers.getNumLeaks(false);
161+
}
162+
159163
public void assertNoLeaks(int maxRetries, TimeDuration retrySleep) throws InterruptedException {
160164
synchronized (leakMessages) {
161165
// leakMessages are all the leaks discovered so far.

ratis-common/src/test/java/org/apache/ratis/BaseTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.apache.ratis.util.ExitUtils;
2323
import org.apache.ratis.util.FileUtils;
2424
import org.apache.ratis.util.JavaUtils;
25+
import org.apache.ratis.util.ReferenceCountedLeakDetector;
2526
import org.apache.ratis.util.Slf4jUtils;
2627
import org.apache.ratis.util.StringUtils;
2728
import org.apache.ratis.util.TimeDuration;
@@ -30,6 +31,7 @@
3031
import org.junit.Rule;
3132
import org.junit.jupiter.api.AfterEach;
3233
import org.junit.jupiter.api.Assertions;
34+
import org.junit.jupiter.api.Assumptions;
3335
import org.junit.jupiter.api.BeforeEach;
3436
import org.junit.jupiter.api.TestInfo;
3537
import org.junit.jupiter.api.Timeout;
@@ -97,6 +99,9 @@ public void setup(TestInfo testInfo) {
9799
testCaseName = testInfo.getTestMethod()
98100
.orElseThrow(() -> new RuntimeException("Exception while getting test name."))
99101
.getName();
102+
103+
final int leaks = ReferenceCountedLeakDetector.getLeakDetector().getLeakCount();
104+
Assumptions.assumeFalse(0 < leaks, () -> "numLeaks " + leaks + " > 0");
100105
}
101106

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

0 commit comments

Comments
 (0)