[fix][test] Fix flaky PersistentStickyKeyDispatcherMultipleConsumersClassicTest.testSkipRedeliverTemporally#25385
Merged
merlimat merged 1 commit intoapache:masterfrom Mar 23, 2026
Conversation
…stic cursor behavior The test was flaky because the asyncReadEntriesOrWait mock returned the same entries indefinitely (entries for the slow consumer were never added to alreadySent since they couldn't be delivered). This created an infinite normal-read loop where the isDispatcherStuckOnReplays flag prevented replay reads from ever being attempted. In a real cursor, asyncReadEntriesOrWait advances the read position - entries can only be re-read through asyncReplayEntries. The fix makes the mock track already-returned entries and simulate "wait" behavior when no new entries are available (by not calling the callback). Additionally, after setting the slow consumer's permits, the test now explicitly triggers readMoreEntriesAsync() to kick off a new dispatch cycle, which is what consumerFlow does in production when a consumer sends more permits. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
merlimat
approved these changes
Mar 22, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #25385 +/- ##
============================================
- Coverage 72.81% 72.75% -0.07%
- Complexity 33791 33887 +96
============================================
Files 1954 1954
Lines 154793 154857 +64
Branches 17731 17740 +9
============================================
- Hits 112716 112662 -54
- Misses 33066 33129 +63
- Partials 9011 9066 +55
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
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.
Motivation
Fix flaky
testSkipRedeliverTemporallyinPersistentStickyKeyDispatcherMultipleConsumersClassicTest.The test was flaky because the
asyncReadEntriesOrWaitmock returned the same entries (msg1, msg2 for the slow consumer) indefinitely, creating an infinite normal-read loop. Normal reads couldn't deliver to the slow consumer becausegetRestrictedMaxEntriesForConsumerreturns 0 whenreadType==Normaland thestickyKeyHashesare inredeliveryMessages. Only replay reads can deliver these messages, but theisDispatcherStuckOnReplaysflag prevented replay reads from being attempted.In a real cursor,
asyncReadEntriesOrWaitadvances the read position — entries can only be re-read throughasyncReplayEntries. The mock didn't simulate this behavior.Modifications
Realistic cursor mock —
asyncReadEntriesOrWaitnow tracks which entries it has already returned and doesn't return them again (simulating cursor read position advancement). When no new entries exist, it doesn't call the callback (simulating "OrWait" behavior), which stops the infinite normal-read loop.Explicit
readMoreEntriesAsync()call — After setting the slow consumer's permits, the test triggers a new dispatch cycle. This mimics whatconsumerFlowdoes in production when a consumer sends more permits. With the loop stopped andisDispatcherStuckOnReplaysnever set, the dispatcher correctly enters the replay read path and delivers messages to the slow consumer.Verifying this change
This change is already covered by existing tests:
PersistentStickyKeyDispatcherMultipleConsumersClassicTest.testSkipRedeliverTemporally— the test itself, verified passing 5/5 consecutive runsPersistentStickyKeyDispatcherMultipleConsumersClassicTestpassDoes this pull request potentially affect one of the following parts:
Documentation
doc-not-neededMatching PR in forked repository
PR in forked repository: