[Test] Fix flaky test: ReaderSeekTest.testHasMessageAvailableAfterSeekToEnd#549
Open
zhanglistar wants to merge 1 commit intoapache:mainfrom
Open
[Test] Fix flaky test: ReaderSeekTest.testHasMessageAvailableAfterSeekToEnd#549zhanglistar wants to merge 1 commit intoapache:mainfrom
zhanglistar wants to merge 1 commit intoapache:mainfrom
Conversation
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 #528
Motivation
When a reader seeks to
MessageId::latest(), the broker may close the consumer and trigger a reconnect. InseekAsyncInternal, when the seek succeeds but the connection is already expired orreconnectionPending_is true, we only setseekStatus_ = COMPLETEDand did not clear the local receive queue or updatestartMessageId_. As a result,incomingMessages_still held prefetched messages from before the seek untilconnectionOpened()later calledclearReceiveQueue(). During that window,hasMessageAvailable()saw!incomingMessages_.empty()and returned true, causing the flaky testReaderSeekTest.testHasMessageAvailableAfterSeekToEnd.Modifications
ConsumerImpl::seekAsyncInternal, when seek result is OK andgetCnx().expired() || reconnectionPending_(reconnection path), we now perform the same local state updates as the non-reconnection path:ackGroupingTrackerPtr_->flushAndClean()incomingMessages_.clear()lastSeekArg_holds aMessageId, setstartMessageId_from itSo after the seek is acknowledged, stale prefetched messages are cleared immediately and
hasMessageAvailable()no longer returns true from old queue content before reconnect completes.Verifying this change
This change is already covered by existing tests:
ReaderSeekTest.testHasMessageAvailableAfterSeekToEnd(parameterized) – asserts that after seek to latest,hasMessageAvailable()becomes false, then after producing a new message it becomes true and the message can be read; the fix removes the flakiness when the broker triggers reconnect on seek-to-end.Documentation
doc-not-neededBug fix in C++ client implementation only; no API or behavior contract change and no user-facing docs update required.