From ca8a23fc32f6e00320dd87b57ee16f49770f2665 Mon Sep 17 00:00:00 2001 From: feynmanlin Date: Fri, 5 Feb 2021 18:56:21 +0800 Subject: [PATCH] Fix flaky test ConsumedLedgersTrimTest.testConsumedLedgersTrimNoSubscriptions (#9420) Fixes #9409 ### Motivation After restarting, it takes time to load the topic, and this admin api will throw an exception when the topic cannot be queried. This problem can easily be triggered when this unit test is called in a loop. Therefore, I added a judgment to determine whether the topic is loaded. After that, I called it 100 times in a loop and no exception was seen. --- .../pulsar/broker/service/ConsumedLedgersTrimTest.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ConsumedLedgersTrimTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ConsumedLedgersTrimTest.java index 9cf2ee7bc539a..cfca2dfbd3f17 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ConsumedLedgersTrimTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ConsumedLedgersTrimTest.java @@ -21,6 +21,8 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotEquals; +import static org.testng.Assert.assertNotNull; + import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; import lombok.Cleanup; @@ -31,6 +33,7 @@ import org.apache.pulsar.client.api.Message; import org.apache.pulsar.client.api.MessageId; import org.apache.pulsar.client.api.Producer; +import org.awaitility.Awaitility; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.testng.Assert; @@ -142,6 +145,8 @@ public void testConsumedLedgersTrimNoSubscriptions() throws Exception { // the lastMessageId is still on the previous ledger restartBroker(); // force load topic + Awaitility.await().ignoreExceptions().untilAsserted(() + -> assertNotNull(pulsar.getBrokerService().getTopicIfExists(topicName).get(3, TimeUnit.SECONDS).get())); pulsar.getAdminClient().topics().getStats(topicName); MessageId messageIdAfterRestart = pulsar.getAdminClient().topics().getLastMessageId(topicName); LOG.info("lastmessageid " + messageIdAfterRestart);