Skip to content

[Test][C++] Fix flaky ReaderTest.testAsyncRead#545

Merged
merlimat merged 3 commits intoapache:mainfrom
bigo-sg:fix/issue-542
Mar 4, 2026
Merged

[Test][C++] Fix flaky ReaderTest.testAsyncRead#545
merlimat merged 3 commits intoapache:mainfrom
bigo-sg:fix/issue-542

Conversation

@zhanglistar
Copy link
Contributor

Fixes #542

Motivation

ReaderTest.testAsyncRead was flaky because it assumed the i-th readNextAsync callback would receive the i-th message. With partitioned topics or async scheduling, callbacks can complete in any order, so the assertion content == "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

  • In testAsyncRead, replaced order-dependent assertions with a set-based check: fire 10 readNextAsync calls, collect the 10 message bodies in a fixed array using std::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"}.
  • Removed the assumption that callback completion order matches send order so the test is stable for partitioned and non-partitioned topics.

Verifying this change

  • Make sure that the change passes the CI checks.

This change is already covered by existing tests:

  • Run: ./pulsar-tests --gtest_filter='*testAsyncRead*'
  • Passes for both parameterized cases (single partition and partitioned topic); no flaky failures from callback order.

Documentation

  • doc-not-needed
    Test-only change; no user-facing or API documentation updates required.

@zhanglistar
Copy link
Contributor Author

@merlimat merlimat merged commit 0c6a7c0 into apache:main Mar 4, 2026
22 of 23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Flay test: ReaderTest.testAsyncRead

2 participants