You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by lh...@apache.org on 2025/06/19 17:08:07 UTC

(pulsar) 01/03: [improve][test] Fix flaky test SimpleProducerConsumerStatTest#testMsgRateExpired (#20629)

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

lhotari pushed a commit to branch branch-3.0
in repository https://gitbox.apache.org/repos/asf/pulsar.git

commit 5eaf22a6239b605916232e6c2552818507405862
Author: Masahiro Sakamoto <ma...@yahoo-corp.jp>
AuthorDate: Fri Jun 30 12:20:13 2023 +0900

    [improve][test] Fix flaky test SimpleProducerConsumerStatTest#testMsgRateExpired (#20629)
    
    (cherry picked from commit 95263829c1b5cdadb73222e4d5c8173c2b2930fe)
---
 .../client/api/SimpleProducerConsumerStatTest.java    | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/client/api/SimpleProducerConsumerStatTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/client/api/SimpleProducerConsumerStatTest.java
index 89e6c684ee1..40e401d2866 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/client/api/SimpleProducerConsumerStatTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/client/api/SimpleProducerConsumerStatTest.java
@@ -545,18 +545,17 @@ public class SimpleProducerConsumerStatTest extends ProducerConsumerBase {
         admin.topics().expireMessages(topicName, subName, 1);
         pulsar.getBrokerService().updateRates();
 
-        Awaitility.await().ignoreExceptions().timeout(5, TimeUnit.SECONDS)
-                .until(() -> admin.topics().getStats(topicName).getSubscriptions().get(subName).getMsgRateExpired() > 0.001);
+        Awaitility.await().ignoreExceptions().timeout(10, TimeUnit.SECONDS)
+                .until(() -> pulsar.getBrokerService().getTopicStats().get(topicName).getSubscriptions().get(subName).getTotalMsgExpired() > 0);
 
-        Thread.sleep(2000);
-        pulsar.getBrokerService().updateRates();
-
-        Awaitility.await().ignoreExceptions().timeout(5, TimeUnit.SECONDS)
-                .until(() -> admin.topics().getStats(topicName).getSubscriptions().get(subName).getMsgRateExpired() < 0.001);
+        Awaitility.await().ignoreExceptions().timeout(10, TimeUnit.SECONDS).until(() -> {
+            pulsar.getBrokerService().updateRates();
+            return pulsar.getBrokerService().getTopicStats().get(topicName).getSubscriptions().get(subName).getMsgRateExpired() < 0.001;
+        });
 
-        assertEquals(admin.topics().getStats(topicName).getSubscriptions().get(subName).getMsgRateExpired(), 0.0,
-                0.001);
-        assertEquals(admin.topics().getStats(topicName).getSubscriptions().get(subName).getTotalMsgExpired(),
+        assertEquals(pulsar.getBrokerService().getTopicStats().get(topicName).getSubscriptions().get(subName).getMsgRateExpired(),
+                0.0, 0.001);
+        assertEquals(pulsar.getBrokerService().getTopicStats().get(topicName).getSubscriptions().get(subName).getTotalMsgExpired(),
                 numMessages);
 
         log.info("-- Exiting {} test --", methodName);