Skip to content

[fix][test] Fix flaky ConsumedLedgersTrimTest.testAdminTrimLedgers#25360

Merged
lhotari merged 1 commit intoapache:masterfrom
merlimat:fix/flaky-ConsumedLedgersTrimTest-v2
Mar 19, 2026
Merged

[fix][test] Fix flaky ConsumedLedgersTrimTest.testAdminTrimLedgers#25360
lhotari merged 1 commit intoapache:masterfrom
merlimat:fix/flaky-ConsumedLedgersTrimTest-v2

Conversation

@merlimat
Copy link
Copy Markdown
Contributor

Flaky test failure

org.awaitility.core.ConditionTimeoutException: Assertion condition expected [1] but found [2] within 10 seconds.
	at org.apache.pulsar.broker.service.ConsumedLedgersTrimTest.testAdminTrimLedgers

Also reproduces as producer timeout when running with invocationCount>1.

Summary

Follow-up to #25342. Three issues causing flakiness:

  1. Fixed producer name "producer-name" causes 30s timeout when running with invocationCount>1 because the previous invocation's partitioned producer (3 sub-producers) may not have fully disconnected yet, and the new producer with the same name waits for the old one.

    • Fix: remove the fixed producerName so each invocation gets a unique auto-generated name.
  2. Assertion too strict — expects exactly 1 ledger after trim, but with maxEntriesPerLedger=2, if partition-0 receives an even number of messages, the last ledger is full and a new empty active ledger is created. After trimming, 2 ledgers remain.

    • Fix: assert <= 2 instead of == 1.
  3. Trim is asyncadmin.topics().trimTopic() returns immediately but the actual ledger deletion happens in the background. The mark-delete position may not be persisted yet when the first trim runs.

    • Fix: re-trigger trimConsumedLedgersInBackground() inside the Awaitility loop.

Documentation

  • doc-not-needed
    (Your PR doesn't need any doc update)

Matching PR in forked repository

No response

Tip

Add the labels ready-to-test and area/test to trigger the CI.

Two issues causing flakiness:

1. Fixed producer name "producer-name" causes timeout when running
   with invocationCount>1 because the previous invocation's
   partitioned producer may not have fully disconnected yet.
   Fix: remove the fixed producerName so each invocation gets a
   unique auto-generated name.

2. The assertion expects exactly 1 ledger after trim, but with
   maxEntriesPerLedger=2, if partition-0 receives an even number
   of messages, the last ledger is full and a new empty active
   ledger is created. After trimming, 2 ledgers remain: one with
   the last confirmed entry and the empty active ledger.
   Fix: assert <= 2 instead of == 1.

3. The trim operation is async. The admin.topics().trimTopic() call
   returns immediately but the actual ledger deletion happens in
   the background. The mark-delete position may not be persisted
   yet when the first trim runs.
   Fix: re-trigger trimConsumedLedgersInBackground() inside the
   Awaitility loop.
@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Mar 19, 2026
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.75%. Comparing base (74f4e5a) to head (c62dd52).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #25360      +/-   ##
============================================
+ Coverage     72.73%   72.75%   +0.02%     
+ Complexity    34264    33876     -388     
============================================
  Files          1954     1954              
  Lines        154792   154792              
  Branches      17731    17731              
============================================
+ Hits         112586   112622      +36     
+ Misses        33170    33157      -13     
+ Partials       9036     9013      -23     
Flag Coverage Δ
inttests 25.72% <ø> (-0.19%) ⬇️
systests 22.56% <ø> (+0.08%) ⬆️
unittests 73.73% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.
see 82 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@lhotari lhotari merged commit 2144968 into apache:master Mar 19, 2026
150 of 156 checks passed
@lhotari lhotari added this to the 4.2.0 milestone Mar 24, 2026
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 ready-to-test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants