Skip to content

Commit 8235168

Browse files
pradeep85841mattrpav
authored andcommitted
Fix flaky NetworkAdvancedStatisticsTest race condition
1 parent 9db2707 commit 8235168

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

activemq-unit-tests/src/test/java/org/apache/activemq/network/NetworkAdvancedStatisticsTest.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,15 @@ public void onMessage(Message message) {
165165
assertTrue(Wait.waitFor(new Condition() {
166166
@Override
167167
public boolean isSatisified() throws Exception {
168-
// The number of message that remain is due to the exclude queue
169-
return receivedMessages.size() == MESSAGE_COUNT;
168+
// Check if messages arrived at the consumer
169+
boolean messagesReceived = receivedMessages.size() == MESSAGE_COUNT;
170+
171+
// Check if the asynchronous broker statistics have settled
172+
long localDequeues = localBroker.getDestination(includedDestination).getDestinationStatistics().getDequeues().getCount();
173+
long remoteEnqueues = remoteBroker.getDestination(includedDestination).getDestinationStatistics().getEnqueues().getCount();
174+
175+
// The test can only proceed when BOTH the messages are received and the stats match
176+
return messagesReceived && localDequeues == MESSAGE_COUNT && remoteEnqueues == MESSAGE_COUNT;
170177
}
171178
}, 30000, 500));
172179

0 commit comments

Comments
 (0)