[Test][C++] Fix flaky ReaderTest.testAsyncRead#545
Merged
merlimat merged 3 commits intoapache:mainfrom Mar 4, 2026
Merged
Conversation
added 3 commits
March 4, 2026 16:07
Contributor
Author
merlimat
approved these changes
Mar 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #542
Motivation
ReaderTest.testAsyncReadwas flaky because it assumed the i-threadNextAsynccallback would receive the i-th message. With partitioned topics or async scheduling, callbacks can complete in any order, so the assertioncontent == "my-message-" + std::to_string(i)sometimes failed (e.g. expected "my-message-8" but got "my-message-9"). This change makes the test order-independent so it passes for both single- and multi-partition topics.Modifications
testAsyncRead, replaced order-dependent assertions with a set-based check: fire 10readNextAsynccalls, collect the 10 message bodies in a fixed array usingstd::atomic<int>for the index (no mutex), wait until 10 messages are received, then assert that the set of received strings equals{"my-message-0", ..., "my-message-9"}.Verifying this change
This change is already covered by existing tests:
./pulsar-tests --gtest_filter='*testAsyncRead*'Documentation
doc-not-neededTest-only change; no user-facing or API documentation updates required.