This is an automated email from the ASF dual-hosted git repository.

szetszwo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ratis.git


The following commit(s) were added to refs/heads/master by this push:
     new ee5693223 RATIS-2220. Skip further tests after leak detected (#1193)
ee5693223 is described below

commit ee56932231f7e639eab6570a6fc89f5f02074568
Author: Doroszlai, Attila <[email protected]>
AuthorDate: Mon Dec 23 18:56:14 2024 +0100

    RATIS-2220. Skip further tests after leak detected (#1193)
---
 ratis-common/src/main/java/org/apache/ratis/util/LeakDetector.java | 4 ++++
 ratis-common/src/test/java/org/apache/ratis/BaseTest.java          | 5 +++++
 2 files changed, 9 insertions(+)

diff --git a/ratis-common/src/main/java/org/apache/ratis/util/LeakDetector.java 
b/ratis-common/src/main/java/org/apache/ratis/util/LeakDetector.java
index a6b2ec28b..6f1220579 100644
--- a/ratis-common/src/main/java/org/apache/ratis/util/LeakDetector.java
+++ b/ratis-common/src/main/java/org/apache/ratis/util/LeakDetector.java
@@ -156,6 +156,10 @@ public class LeakDetector {
     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.
diff --git a/ratis-common/src/test/java/org/apache/ratis/BaseTest.java 
b/ratis-common/src/test/java/org/apache/ratis/BaseTest.java
index e28978403..af54cafc7 100644
--- a/ratis-common/src/test/java/org/apache/ratis/BaseTest.java
+++ b/ratis-common/src/test/java/org/apache/ratis/BaseTest.java
@@ -22,6 +22,7 @@ import org.apache.ratis.protocol.RaftPeer;
 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;
@@ -30,6 +31,7 @@ import org.junit.After;
 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;
@@ -97,6 +99,9 @@ public abstract class BaseTest {
     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.

Reply via email to