Skip to content

[fix][test] Fix flaky ConsumerBatchReceiveTest.testBatchReceiveAndRedeliveryNonPartitionedTopic#25468

Open
merlimat wants to merge 1 commit intoapache:masterfrom
merlimat:fix/flaky-ConsumerBatchReceiveTest
Open

[fix][test] Fix flaky ConsumerBatchReceiveTest.testBatchReceiveAndRedeliveryNonPartitionedTopic#25468
merlimat wants to merge 1 commit intoapache:masterfrom
merlimat:fix/flaky-ConsumerBatchReceiveTest

Conversation

@merlimat
Copy link
Copy Markdown
Contributor

@merlimat merlimat commented Apr 3, 2026

Motivation

ConsumerBatchReceiveTest.testBatchReceiveAndRedeliveryNonPartitionedTopic is flaky due to two issues:

  1. consumer.acknowledge(messages) is called outside the null check, causing NPE when batchReceive() returns null
  2. Strict equality assertion fails because ack timeout redelivery can cause extra messages beyond the expected count

Stack trace

ConsumerBatchReceiveTest > testBatchReceiveAndRedeliveryNonPartitionedTopic[54] FAILED
    java.lang.AssertionError: expected [202] but found [200]
        at org.testng.Assert.fail(Assert.java:110)
        at org.testng.Assert.failNotEquals(Assert.java:1577)
        at org.testng.Assert.assertEqualsImpl(Assert.java:149)
        at org.testng.Assert.assertEquals(Assert.java:131)
        at ConsumerBatchReceiveTest.batchReceiveAndRedelivery(ConsumerBatchReceiveTest.java:635)

Modifications

  • Move consumer.acknowledge(messages) inside the if (messages != null) block
  • Change assertEquals(expected * 2, messageReceived) to assertTrue(messageReceived >= expected * 2) since redelivery can produce extra messages

Documentation

  • doc-not-needed

…eliveryNonPartitionedTopic

Move consumer.acknowledge(messages) inside the null check to avoid NPE
when batchReceive returns null. Change strict equality assertion to
>= since ack timeout redelivery can cause extra messages to be received.
@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Apr 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/test doc-not-needed Your PR changes do not impact docs ready-to-test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant