Skip to content

Commit

Permalink
Fix flaky test SimpleProducerConsumerStatTest#testMsgRateExpired
Browse files Browse the repository at this point in the history
  • Loading branch information
Masahiro Sakamoto committed Jun 21, 2023
1 parent 7ab9c70 commit b2a9eb3
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -545,18 +545,19 @@ public void testMsgRateExpired() throws Exception {
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);
Expand Down

0 comments on commit b2a9eb3

Please sign in to comment.