diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/PatternTopicsConsumerImplTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/PatternTopicsConsumerImplTest.java index 51a6222a23f761..65c05341b77264 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/PatternTopicsConsumerImplTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/PatternTopicsConsumerImplTest.java @@ -45,6 +45,7 @@ import org.apache.pulsar.client.api.SubscriptionType; import org.apache.pulsar.common.naming.NamespaceName; import org.apache.pulsar.common.policies.data.TenantInfoImpl; +import org.awaitility.Awaitility; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.testng.annotations.AfterMethod; @@ -587,10 +588,11 @@ public void testAutoSubscribePatternConsumer() throws Exception { log.debug("recheck topics change"); PatternMultiTopicsConsumerImpl consumer1 = ((PatternMultiTopicsConsumerImpl) consumer); consumer1.run(consumer1.getRecheckPatternTimeout()); - Thread.sleep(100); - assertEquals(((PatternMultiTopicsConsumerImpl) consumer).getPartitions().size(), 10); - assertEquals(((PatternMultiTopicsConsumerImpl) consumer).getConsumers().size(), 10); - assertEquals(((PatternMultiTopicsConsumerImpl) consumer).getPartitionedTopics().size(), 3); + Awaitility.await().untilAsserted(() -> { + assertEquals(((PatternMultiTopicsConsumerImpl) consumer).getPartitions().size(), 10); + assertEquals(((PatternMultiTopicsConsumerImpl) consumer).getConsumers().size(), 10); + assertEquals(((PatternMultiTopicsConsumerImpl) consumer).getPartitionedTopics().size(), 3); + }); // 8. produce data to topic3 and topic4, verify should receive all the message for (int i = 0; i < totalMessages / 2; i++) {