File tree Expand file tree Collapse file tree
pulsar-common/src/test/java/org/apache/pulsar/common/util Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2626import java .util .concurrent .atomic .AtomicInteger ;
2727import java .util .function .Supplier ;
2828import lombok .Cleanup ;
29+ import org .awaitility .Awaitility ;
2930import org .testng .annotations .Test ;
3031
3132public class RateLimiterTest {
@@ -201,13 +202,13 @@ public void testDispatchRate() throws Exception {
201202 rate .tryAcquire (100 );
202203 assertEquals (rate .getAvailablePermits (), 0 );
203204
204- Thread . sleep ( rateTimeMSec * 2 );
205- // check after two rate-time: acquiredPermits is 100
206- assertEquals ( rate . getAvailablePermits (), 0 );
207-
208- Thread . sleep (rateTimeMSec );
209- // check after three rate-time: acquiredPermits is 0
210- assertTrue ( rate .getAvailablePermits () > 0 );
205+ // Each scheduled renew releases `permits` (100) from acquiredPermits (which starts at 300).
206+ // Wait until the renew task has run enough times to make permits available again. Polling
207+ // avoids flakiness caused by scheduler jitter under CI load that delays fixed- rate ticks.
208+ Awaitility . await ()
209+ . atMost (rateTimeMSec * 10 , TimeUnit . MILLISECONDS )
210+ . pollInterval ( 100 , TimeUnit . MILLISECONDS )
211+ . until (() -> rate .getAvailablePermits () > 0 );
211212
212213 rate .close ();
213214 }
You can’t perform that action at this time.
0 commit comments