[fix][flaky-test] Fix BacklogQuotaManagerTest.testConsumerBacklogEvictionTimeQuotaWithEmptyLedger
@@ -541,22 +541,19 @@ public class BacklogQuotaManagerTest {
consumer.receive();
admin.topics().unload(topic);
- Awaitility.await().until(consumer::isConnected);
+
+ Awaitility.await().untilAsserted(() -> {
PersistentTopicInternalStats internalStats = admin.topics().getInternalStats(topic);
assertEquals(internalStats.ledgers.size(), 2);
assertEquals(internalStats.ledgers.get(1).entries, 0);
+ });
TopicStats stats = getTopicStats(topic);
assertEquals(stats.getSubscriptions().get(subName).getMsgBacklog(), 1);
- TimeUnit.SECONDS.sleep(TIME_TO_CHECK_BACKLOG_QUOTA);
-
- Awaitility.await()
- .pollInterval(Duration.ofSeconds(1))
- .atMost(Duration.ofSeconds(TIME_TO_CHECK_BACKLOG_QUOTA))
- .untilAsserted(() -> {
rolloverStats();
+ Awaitility.await().untilAsserted(() -> {
// Cause the last ledger is empty, it is not possible to skip first ledger,
// so the number of ledgers will keep unchanged, and backlog is clear
PersistentTopicInternalStats latestInternalStats = admin.topics().getInternalStats(topic);
