This is an automated email from the ASF dual-hosted git repository.

jbonofre pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/activemq.git


The following commit(s) were added to refs/heads/main by this push:
     new ca34bcd387 Fix flaky DurableSubInBrokerNetworkTest by replacing fixed 
sleeps with Wait.waitFor polling (#1906)
ca34bcd387 is described below

commit ca34bcd387156b7bacb8abc382c768354c48d730
Author: gurpartap3697 <[email protected]>
AuthorDate: Thu Apr 16 02:18:39 2026 +0530

    Fix flaky DurableSubInBrokerNetworkTest by replacing fixed sleeps with 
Wait.waitFor polling (#1906)
    
    * replace Thread.sleep() with waitfor() to fix flakiness in 
DurableSubInBrokerNetworkTest
    
    * update polling time of Wait.waitFor()
---
 .../usecases/DurableSubInBrokerNetworkTest.java    | 57 ++++++++++------------
 1 file changed, 27 insertions(+), 30 deletions(-)

diff --git 
a/activemq-unit-tests/src/test/java/org/apache/activemq/usecases/DurableSubInBrokerNetworkTest.java
 
b/activemq-unit-tests/src/test/java/org/apache/activemq/usecases/DurableSubInBrokerNetworkTest.java
index b617dfce67..000495d5c8 100644
--- 
a/activemq-unit-tests/src/test/java/org/apache/activemq/usecases/DurableSubInBrokerNetworkTest.java
+++ 
b/activemq-unit-tests/src/test/java/org/apache/activemq/usecases/DurableSubInBrokerNetworkTest.java
@@ -30,6 +30,7 @@ import org.apache.activemq.ActiveMQConnectionFactory;
 import org.apache.activemq.network.DiscoveryNetworkConnector;
 import org.apache.activemq.network.NetworkConnector;
 import org.apache.activemq.network.NetworkTestSupport;
+import org.apache.activemq.util.Wait;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.junit.experimental.categories.Category;
@@ -59,6 +60,9 @@ public class DurableSubInBrokerNetworkTest extends 
NetworkTestSupport {
         nc.setDuplex(true);
         remoteBroker.addNetworkConnector(nc);
         nc.start();
+
+        assertTrue("Network bridge did not establish in time",
+                Wait.waitFor(() -> !nc.activeBridges().isEmpty(), 15000, 100));
     }
 
     protected void tearDown() throws Exception {
@@ -92,28 +96,25 @@ public class DurableSubInBrokerNetworkTest extends 
NetworkTestSupport {
         Destination dest = session.createTopic(topicName);
         TopicSubscriber sub = session.createDurableSubscriber((Topic)dest, 
subName);
         LOG.info("Durable subscription of name " + subName + "created.");
-        Thread.sleep(100);
 
         // query durable sub on local and remote broker
         // raise an error if not found
-
-        assertTrue(foundSubInLocalBroker(subName));
-
-
-        assertTrue(foundSubInRemoteBrokerByTopicName(topicName));
+        assertTrue("Durable subscription not found in local broker",
+                Wait.waitFor(() -> foundSubInLocalBroker(subName), 15000, 
100));
+        assertTrue("Durable subscription not propagated to remote broker",
+                Wait.waitFor(() -> 
foundSubInRemoteBrokerByTopicName(topicName), 15000, 100));
 
         // unsubscribe from durable sub
         sub.close();
         session.unsubscribe(subName);
         LOG.info("Unsubscribed from durable subscription.");
-        Thread.sleep(100);
 
         // query durable sub on local and remote broker
         // raise an error if its not removed from both brokers
-        assertFalse(foundSubInLocalBroker(subName));
-
-        assertFalse("Durable subscription not unregistered on remote broker",
-                foundSubInRemoteBrokerByTopicName(topicName));
+        assertTrue("Durable subscription not removed from local broker",
+                Wait.waitFor(() -> !foundSubInLocalBroker(subName), 15000, 
100));
+        assertTrue("Durable subscription not unregistered on remote broker",
+                Wait.waitFor(() -> 
!foundSubInRemoteBrokerByTopicName(topicName), 15000, 100));
 
 
     }
@@ -131,39 +132,35 @@ public class DurableSubInBrokerNetworkTest extends 
NetworkTestSupport {
         TopicSubscriber sub2 = session.createDurableSubscriber((Topic) dest, 
subName2);
         LOG.info("Durable subscription of name " + subName2 + "created.");
 
-        Thread.sleep(100);
-
         // query durable sub on local and remote broker
         // raise an error if not found
-
-        assertTrue(foundSubInLocalBroker(subName));
-        assertTrue(foundSubInLocalBroker(subName2));
-
-
-        assertTrue(foundSubInRemoteBrokerByTopicName(topicName));
+        assertTrue("Subscription1 not found in local broker",
+                Wait.waitFor(() -> foundSubInLocalBroker(subName), 15000, 
100));
+        assertTrue("Subscription2 not found in local broker",
+                Wait.waitFor(() -> foundSubInLocalBroker(subName2), 15000, 
100));
+        assertTrue("Durable subscription not propagated to remote broker",
+                Wait.waitFor(() -> 
foundSubInRemoteBrokerByTopicName(topicName), 15000, 100));
 
         // unsubscribe from durable sub
         sub.close();
         session.unsubscribe(subName);
         LOG.info("Unsubscribed from durable subscription.");
-        Thread.sleep(100);
 
         // query durable sub on local and remote broker
-        assertFalse(foundSubInLocalBroker(subName));
-        assertTrue(foundSubInLocalBroker(subName2));
-
+        assertTrue("Subscription1 not removed from local broker",
+                Wait.waitFor(() -> !foundSubInLocalBroker(subName), 15000, 
100));
+        assertTrue("Subscription2 should still be in local broker",
+                Wait.waitFor(() -> foundSubInLocalBroker(subName2), 15000, 
100));
         assertTrue("Durable subscription should still be on remote broker",
-                foundSubInRemoteBrokerByTopicName(topicName));
+                Wait.waitFor(() -> 
foundSubInRemoteBrokerByTopicName(topicName), 15000, 100));
 
         sub2.close();
         session.unsubscribe(subName2);
 
-        Thread.sleep(100);
-
-        assertFalse(foundSubInLocalBroker(subName2));
-
-        assertFalse("Durable subscription not unregistered on remote broker",
-                foundSubInRemoteBrokerByTopicName(topicName));
+        assertTrue("Subscription2 not removed from local broker",
+                Wait.waitFor(() -> !foundSubInLocalBroker(subName2), 15000, 
100));
+        assertTrue("Durable subscription not unregistered on remote broker",
+                Wait.waitFor(() -> 
!foundSubInRemoteBrokerByTopicName(topicName), 15000, 100));
 
     }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information, visit: https://activemq.apache.org/contact


Reply via email to