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

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


The following commit(s) were added to refs/heads/master by this push:
     new eb6f1c5ba0 fix: replace thread sleeps with CountDownLatch in 
MemoryLimiterTest to improve test stability (#6935)
eb6f1c5ba0 is described below

commit eb6f1c5ba0002ea71e6c41dee5806b5c31f2c98d
Author: Limbo <[email protected]>
AuthorDate: Sat Aug 22 21:56:09 2026 +0800

    fix: replace thread sleeps with CountDownLatch in MemoryLimiterTest to 
improve test stability (#6935)
    
    Co-authored-by: aias00 <[email protected]>
---
 .../apache/shenyu/common/concurrent/MemoryLimiterTest.java  | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git 
a/shenyu-common/src/test/java/org/apache/shenyu/common/concurrent/MemoryLimiterTest.java
 
b/shenyu-common/src/test/java/org/apache/shenyu/common/concurrent/MemoryLimiterTest.java
index d16a991ce9..ef0837e7c1 100644
--- 
a/shenyu-common/src/test/java/org/apache/shenyu/common/concurrent/MemoryLimiterTest.java
+++ 
b/shenyu-common/src/test/java/org/apache/shenyu/common/concurrent/MemoryLimiterTest.java
@@ -22,6 +22,7 @@ import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;
 
 import java.lang.instrument.Instrumentation;
+import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.Future;
@@ -114,8 +115,12 @@ public final class MemoryLimiterTest {
         MemoryLimiter memoryLimiter = new MemoryLimiter(testObjectSize + 1, 
instrumentation);
         memoryLimiter.acquire(testObject);
         ExecutorService executorService = Executors.newFixedThreadPool(1);
-        Future<Boolean> acquireResult = executorService.submit(() -> 
memoryLimiter.acquire(testObject, 4, TimeUnit.SECONDS));
-        Thread.sleep(2000);
+        CountDownLatch readyLatch = new CountDownLatch(1);
+        Future<Boolean> acquireResult = executorService.submit(() -> {
+            readyLatch.countDown();
+            return memoryLimiter.acquire(testObject, 4, TimeUnit.SECONDS);
+        });
+        assertTrue(readyLatch.await(5, TimeUnit.SECONDS));
         memoryLimiter.release(testObject);
         assertTrue(acquireResult.get());
         assertEquals(testObjectSize, memoryLimiter.getCurrentMemory());
@@ -180,7 +185,9 @@ public final class MemoryLimiterTest {
     public void testReleaseInterruptiblyWithTimeWait() throws Exception {
         MemoryLimiter memoryLimiter = new MemoryLimiter(testObjectSize + 1, 
instrumentation);
         ExecutorService executorService = Executors.newFixedThreadPool(1);
+        CountDownLatch readyLatch = new CountDownLatch(1);
         Future<Boolean> acquireResult = executorService.submit(() -> {
+            readyLatch.countDown();
             try {
                 memoryLimiter.releaseInterruptibly(testObject, 4, 
TimeUnit.SECONDS);
                 return Boolean.TRUE;
@@ -188,7 +195,7 @@ public final class MemoryLimiterTest {
                 return Boolean.FALSE;
             }
         });
-        Thread.sleep(2000);
+        assertTrue(readyLatch.await(5, TimeUnit.SECONDS));
         memoryLimiter.acquire(testObject);
         assertTrue(acquireResult.get());
         assertEquals(0, memoryLimiter.getCurrentMemory());

Reply via email to