Skip to content

[fix][test] Fix flaky ManagedLedgerTest.testCursorPointsToDeletedLedgerAfterTrim#25476

Merged
nodece merged 1 commit intoapache:masterfrom
merlimat:fix/flaky-ManagedLedgerTest-cursorTrim
Apr 7, 2026
Merged

[fix][test] Fix flaky ManagedLedgerTest.testCursorPointsToDeletedLedgerAfterTrim#25476
nodece merged 1 commit intoapache:masterfrom
merlimat:fix/flaky-ManagedLedgerTest-cursorTrim

Conversation

@merlimat
Copy link
Copy Markdown
Contributor

@merlimat merlimat commented Apr 5, 2026

Motivation

ManagedLedgerTest.testCursorPointsToDeletedLedgerAfterTrim is flaky because it injects a 30s BK write delay and then asserts the persistent position hasn't advanced. However, the outcome is timing-dependent: sometimes the delayed persistence completes before the trim checks cursor positions, sometimes not.

The test's assertions were also incorrect — maybeUpdateCursorBeforeTrimmingConsumedLedger() is designed to advance the cursor past fully consumed ledgers, and it's perfectly fine for the persistent position to advance. The old assertions expected the persistent position to remain at the old value.

Stack trace

ManagedLedgerTest > testCursorPointsToDeletedLedgerAfterTrim FAILED
    java.lang.AssertionError: Persistent position should not have advanced (delayed)
        expected [3:0] but found [4:-1]
        at ManagedLedgerTest.testCursorPointsToDeletedLedgerAfterTrim(ManagedLedgerTest.java:4823)

Modifications

Simplify the test by removing the 30s BK write delay and the complex out-of-order deletion pattern. The test now straightforwardly verifies that maybeUpdateCursorBeforeTrimmingConsumedLedger advances the cursor past a fully consumed ledger, and trimming correctly deletes it.

Documentation

  • doc-not-needed

…erAfterTrim

The test used a 30s BK write delay to simulate slow persistence, but
this made the outcome timing-dependent: sometimes persistence completed
before trim checked positions, sometimes not.

Simplify the test to verify the correct behavior without artificial
delays: maybeUpdateCursorBeforeTrimmingConsumedLedger advances the
cursor past fully consumed ledgers, and trim cleans them up.
@github-actions github-actions Bot added the doc-not-needed Your PR changes do not impact docs label Apr 5, 2026
@nodece nodece merged commit 7ec0f09 into apache:master Apr 7, 2026
45 of 46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/test doc-not-needed Your PR changes do not impact docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants