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 e95b4a5034 fix(test): fix ZeroPrefetchConsumerTest flakiness caused by
receiveNoWait() race (#1741)
e95b4a5034 is described below
commit e95b4a5034d328c82924171e5c4efd35b282fd76
Author: JB Onofré <[email protected]>
AuthorDate: Mon Mar 9 14:24:22 2026 +0100
fix(test): fix ZeroPrefetchConsumerTest flakiness caused by receiveNoWait()
race (#1741)
Replace receiveNoWait() with receive(5000) in doTestRecvRecvCommit and
testTwoConsumers where messages are expected to be present. With zero
prefetch, receiveNoWait() sends a MessagePull with timeout=-1 which
causes the broker to send NULL_MESSAGE immediately if dest.iterate()
cannot dispatch in time (race with ack processing of the previous
message). Using receive(timeout) allows the broker to retry dispatch
before timing out.
---
.../test/java/org/apache/activemq/ZeroPrefetchConsumerTest.java | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git
a/activemq-unit-tests/src/test/java/org/apache/activemq/ZeroPrefetchConsumerTest.java
b/activemq-unit-tests/src/test/java/org/apache/activemq/ZeroPrefetchConsumerTest.java
index d4de2ee84a..e06dc3e1f5 100644
---
a/activemq-unit-tests/src/test/java/org/apache/activemq/ZeroPrefetchConsumerTest.java
+++
b/activemq-unit-tests/src/test/java/org/apache/activemq/ZeroPrefetchConsumerTest.java
@@ -139,9 +139,9 @@ public class ZeroPrefetchConsumerTest extends
EmbeddedBrokerTestSupport {
}
// now lets receive it
MessageConsumer consumer = session.createConsumer(queue);
- TextMessage answer = (TextMessage)consumer.receiveNoWait();
+ TextMessage answer = (TextMessage)consumer.receive(5000);
assertEquals("Should have received a message!", answer.getText(),
"Msg1");
- answer = (TextMessage)consumer.receiveNoWait();
+ answer = (TextMessage)consumer.receive(5000);
assertEquals("Should have received a message!", answer.getText(),
"Msg2");
if (transacted) {
session.commit();
@@ -160,9 +160,9 @@ public class ZeroPrefetchConsumerTest extends
EmbeddedBrokerTestSupport {
// now lets receive it
MessageConsumer consumer1 = session.createConsumer(queue);
MessageConsumer consumer2 = session.createConsumer(queue);
- TextMessage answer = (TextMessage)consumer1.receiveNoWait();
+ TextMessage answer = (TextMessage)consumer1.receive(5000);
assertEquals("Should have received a message!", answer.getText(),
"Msg1");
- answer = (TextMessage)consumer2.receiveNoWait();
+ answer = (TextMessage)consumer2.receive(5000);
assertEquals("Should have received a message!", answer.getText(),
"Msg2");
answer = (TextMessage)consumer2.receiveNoWait();
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information, visit: https://activemq.apache.org/contact