Skip to content

test: Make Drop50 message drop deterministic in LedgerReplayer test - #7964

Open
pratikmankawde wants to merge 2 commits into
developfrom
pratik/fix-ledgerreplay-flaky-test
Open

test: Make Drop50 message drop deterministic in LedgerReplayer test#7964
pratikmankawde wants to merge 2 commits into
developfrom
pratik/fix-ledgerreplay-flaky-test

Conversation

@pratikmankawde

@pratikmankawde pratikmankawde commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

High Level Overview of Change

Fix flaky xrpl.app.LedgerReplayer test.

Context of Change

The "network drops 50% messages" testcase used randInt to drop each request independently. A subtask fails after 11 consecutive drops, creating a ~1/512 failure rate per run.

Changed to drop every other message via counter. Still exercises timeout/retry but guarantees eventual progress.

API Impact

None.

The 'network drops 50% messages' testcase dropped each request with an
independent random 50% probability. A subtask permanently fails after
1 + kSubTaskMaxTimeouts (11) consecutive dropped sends, so each run had
a ~1/512 chance of failure, causing intermittent CI failures at
LedgerReplay_test.cpp(1340) and (1342).

Drop every other message via a counter instead. This still exercises
the timeout/retry path but guarantees every subtask eventually gets a
reply.

@xrplf-ai-reviewer xrplf-ai-reviewer Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Straightforward fix: replaces the random 50% drop with a deterministic alternating counter, which correctly maintains an invariant (each subtask's send sequence starts at an even/dropped position, since prior subtasks consume an even number of total sends) so no subtask should hit 11 consecutive drops. The only point worth double-checking is why the counter was made atomic, since that implies concurrent callers, which could undermine the new determinism guarantee.

@pratikmankawde pratikmankawde added the Full CI build Run all CI configurations, no matter what label Aug 6, 2026
@codecov

codecov Bot commented Aug 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Signed-off-by: Pratik Mankawde <3397372+pratikmankawde@users.noreply.github.com>
@pratikmankawde
pratikmankawde requested a review from a team August 7, 2026 10:26

@xrplf-ai-reviewer xrplf-ai-reviewer Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Straightforward, well-targeted fix: replaces the random randInt-based 50% drop with a deterministic atomic counter that drops every other Drop50 message, removing the ~1/512 flaky failure mode while still exercising the timeout/retry path. The std::atomic<int> counter is correctly used (single read-modify-write via post-increment), the unused random.h include was removed, and <atomic> was added. No correctness, security, or style issues found in the changed lines.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a flaky xrpl.app.LedgerReplayer unit test by replacing probabilistic message dropping (via RNG) with deterministic alternating drops, preserving coverage of the retry/timeout behavior while eliminating the ~1/512 failure mode from long consecutive drops.

Changes:

  • Remove RNG-based 50% drop simulation and implement deterministic “drop every other message” logic for PeerSetBehavior::Drop50.
  • Add a per-TestPeerSet std::atomic<int> counter to support deterministic dropping under potential concurrency.
  • Remove the now-unused random.h include and add the required <atomic> include.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mathbunnyru mathbunnyru left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should rename it to DropEverySecond.

Also, as an alternative, maybe we should increase number of messages and fail after more drops, practically making probability zero?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Full CI build Run all CI configurations, no matter what

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants