Skip to content

Commit 6adc875

Browse files
authored
fix(test): avoid race condition in TwoBrokerVirtualTopicSelectorAwareForwardingTest (#1951)
Replace bare assertEquals with Wait.waitFor for the queue depth check in testSelectorAwareForwarding. The broker decrements its messages counter only after processing the MessageAck asynchronously, so asserting immediately after waitForMessagesToArrive could fire before the ACK is processed on a loaded CI runner.
1 parent 0df19ae commit 6adc875

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

activemq-unit-tests/src/test/java/org/apache/activemq/usecases/TwoBrokerVirtualTopicSelectorAwareForwardingTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -520,10 +520,11 @@ public void testSelectorAwareForwarding() throws Exception {
520520
assertEquals(2, msgsB.getMessageCount());
521521

522522

523-
// queue should be drained
524-
assertEquals(0, brokerB.getDestination(new ActiveMQQueue("Consumer.B.VirtualTopic.tempTopic"))
525-
.getDestinationStatistics().getMessages().getCount());
526-
// and the enqueue count for the remote queue should only be 1
523+
// queue should be drained - use Wait.waitFor to allow broker ACK processing to complete
524+
assertTrue("queue should be drained after consumer ACKs", Wait.waitFor(() ->
525+
brokerB.getDestination(new ActiveMQQueue("Consumer.B.VirtualTopic.tempTopic"))
526+
.getDestinationStatistics().getMessages().getCount() == 0, 5000, 100));
527+
// and the enqueue count for the remote queue should only be 3
527528
assertEquals(3, brokerB.getDestination(new ActiveMQQueue("Consumer.B.VirtualTopic.tempTopic"))
528529
.getDestinationStatistics().getEnqueues().getCount());
529530

0 commit comments

Comments
 (0)