Fix flaky test ProducerCloseTest.brokerCloseTopicTest.
@@ -28,6 +28,7 @@ import org.apache.pulsar.client.api.PulsarClientException;
import org.apache.pulsar.client.api.TypedMessageBuilder;
import org.apache.pulsar.common.api.proto.CommandSuccess;
import org.apache.pulsar.common.naming.TopicName;
+import org.awaitility.Awaitility;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
@@ -137,7 +138,7 @@ public class ProducerCloseTest extends ProducerConsumerBase {
.getTopicReference(TopicName.get(topic).getPartitionedTopicName());
Assert.assertTrue(topicOptional.isPresent());
topicOptional.get().close(true).get();
- Assert.assertEquals(producer.getState(), HandlerState.State.Connecting);
+ Awaitility.await().untilAsserted(() -> Assert.assertEquals(producer.getState(), HandlerState.State.Connecting));
if (isAsyncSend) {
producer.newMessage().value("test".getBytes()).sendAsync().get();
} else {
