[fix][test] Fix flaky ManagedLedgerTest.testNoRetention and testInvalidateReadHandleWhenDeleteLedger#25495
Merged
merlimat merged 2 commits intoapache:masterfrom Apr 8, 2026
Merged
Conversation
…idateReadHandleWhenDeleteLedger testNoRetention: The trimConsumedLedgersInBackground call may be deferred when the managed ledger is in CreatingLedger state (due to an ongoing ledger roll after addEntry). The single trim+join was not sufficient because the trim could complete as a no-op if deferred trimming hadn't finished yet. Use Awaitility to repeatedly trigger trimming and verify the assertions, ensuring the test waits for the async trimming to fully complete. testInvalidateReadHandleWhenDeleteLedger: With maxEntriesPerLedger=1, adding 3 entries triggers 3 ledger rolls. The last roll may not have completed by the time readEntries is called, causing the last entry to be read directly from currentLedger (not via ledgerCache). This results in ledgerCache having only 2 entries instead of the expected 3. Wait for all ledger rolls to complete (ledgers.size() == 4) before reading. Fixes apache#25109
merlimat
approved these changes
Apr 8, 2026
merlimat
added a commit
to merlimat/pulsar
that referenced
this pull request
Apr 10, 2026
The debug log line in testInvalidateReadHandleWhenDeleteLedger was removed on master (apache#25495) while the slog branch had converted it to structured logging. Resolved by taking master's version (removing the line).
merlimat
added a commit
to merlimat/pulsar
that referenced
this pull request
Apr 10, 2026
The debug log line in testInvalidateReadHandleWhenDeleteLedger was removed on master (apache#25495) while the slog branch had converted it to structured logging. Resolved by removing the line.
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 #25109
Motivation
Fix two flaky tests in
ManagedLedgerTestthat fail intermittently on master due to race conditions with async ledger rolls.testNoRetention: After
addEntrywithmaxEntriesPerLedger=1, a ledger roll is triggered asynchronously. WhentrimConsumedLedgersInBackgroundruns while the state isCreatingLedger, the trim is deferred (100ms retry). The original code did a single trim+join, which could complete as a no-op if the ledger roll was still in progress.testInvalidateReadHandleWhenDeleteLedger: With
maxEntriesPerLedger=1and 3 entries, 3 ledger rolls occur. The last roll is async, so whenreadEntries(3)was called immediately, the 3rd entry could be read directly fromcurrentLedger(bypassingledgerCache), resulting inledgerCache.size() == 2instead of 3.Modifications
Awaitility.await().untilAsserted()so the test retries until trimming fully completes.Awaitility.await().untilAsserted(() -> assertEquals(ledger.ledgers.size(), 4))before reading, ensuring all ledger rolls are complete.Verifying this change
This change is already covered by existing tests, such as
ManagedLedgerTest.testNoRetentionandManagedLedgerTest.testInvalidateReadHandleWhenDeleteLedger. Both verified withinvocationCount=10locally (10/10 passes).Does this pull request potentially affect one of the following parts: