This is an automated email from the ASF dual-hosted git repository. lhotari pushed a commit to branch branch-4.2 in repository https://gitbox.apache.org/repos/asf/pulsar.git
commit 5f10bf0c96fa98e619af599ae208bc5694f1c789 Author: Oneby Wang <[email protected]> AuthorDate: Mon May 25 20:28:47 2026 +0800 [fix][test] Fix flaky ProducerCleanupTest timer cleanup (#25864) (cherry picked from commit 2e02b7830ee14e8d3476dba03f7fa6fd0da175b8) --- .../apache/pulsar/client/api/ProducerCleanupTest.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/client/api/ProducerCleanupTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/client/api/ProducerCleanupTest.java index 2a7fcb3eb17..09c0113c0a1 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/client/api/ProducerCleanupTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/client/api/ProducerCleanupTest.java @@ -20,8 +20,10 @@ package org.apache.pulsar.client.api; import io.netty.util.HashedWheelTimer; import java.util.concurrent.TimeUnit; +import lombok.Cleanup; import org.apache.pulsar.broker.service.SharedPulsarBaseTest; import org.apache.pulsar.client.impl.PulsarClientImpl; +import org.awaitility.Awaitility; import org.testng.Assert; import org.testng.annotations.Test; @@ -29,14 +31,17 @@ import org.testng.annotations.Test; public class ProducerCleanupTest extends SharedPulsarBaseTest { @Test - public void testAllTimerTaskShouldCanceledAfterProducerClosed() throws PulsarClientException, InterruptedException { - Producer<byte[]> producer = pulsarClient.newProducer() + public void testAllTimerTaskShouldCanceledAfterProducerClosed() throws PulsarClientException { + @Cleanup + PulsarClient client = newPulsarClient(); + Producer<byte[]> producer = client.newProducer() .topic(newTopicName()) - .sendTimeout(1, TimeUnit.SECONDS) + .sendTimeout(15, TimeUnit.SECONDS) .create(); producer.close(); - Thread.sleep(2000); - HashedWheelTimer timer = (HashedWheelTimer) ((PulsarClientImpl) pulsarClient).timer(); - Assert.assertEquals(timer.pendingTimeouts(), 0); + HashedWheelTimer timer = (HashedWheelTimer) ((PulsarClientImpl) client).timer(); + Awaitility.await() + .atMost(10, TimeUnit.SECONDS) + .untilAsserted(() -> Assert.assertEquals(timer.pendingTimeouts(), 0)); } }
