Skip to content

Refactor exponential backoff test to remove sleeps#443

Merged
leynos merged 2 commits intomainfrom
refactor-backoff-test-remove-sleeps-v0tv4x
Feb 5, 2026
Merged

Refactor exponential backoff test to remove sleeps#443
leynos merged 2 commits intomainfrom
refactor-backoff-test-remove-sleeps-v0tv4x

Conversation

@leynos
Copy link
Copy Markdown
Owner

@leynos leynos commented Feb 5, 2026

Summary

  • Removes real-time sleeps from exponential backoff test
  • Uses deterministic backoff sequence and exact assertions

Changes

Testing

  • Replaced sleep-based timing with a deterministic backoff_sequence
  • Added backoff_sequence helper to compute the progression
  • Updated tests to assert exact sequence equality against expected delays
  • Used saturating_mul to cap doubling at max

Cleanup

  • Removed unused imports (thread, Instant) from the test module
  • Cleaned up related timing code

Rationale

  • Eliminates flakiness caused by thread sleeps and timing precision
  • Speeds up test suite by removing sleeps

Test plan

  • Run cargo test for the crate; specifically tests in src/server/config/tests.rs
  • Verify test passes deterministically and sequence matches expected values

◳ Generated by DevBoxer


ℹ️ Tag @devboxerhub to ask questions and address PR feedback

📎 Task: https://www.devboxer.com/task/d1f32386-87da-4e75-b33d-90e24e2aa122

📝 Closes #310

Summary by Sourcery

Refactor exponential backoff configuration test to use a deterministic delay sequence instead of real-time sleeping.

Enhancements:

  • Use saturating_mul when calculating exponential backoff steps to safely cap delay growth.

Tests:

  • Replace sleep-based timing assertions in exponential backoff test with deterministic sequence comparison.
  • Introduce a reusable backoff_sequence helper to generate capped exponential delay progressions for tests.

…g backoff_sequence helper

Replaced manual timing and thread sleeps with a utility function `backoff_sequence` to generate expected backoff durations. This change improves test clarity and determinism by removing reliance on actual waiting times in the test `test_accept_exponential_backoff_doubles_and_caps`.

Co-authored-by: devboxerhub[bot] <devboxerhub[bot]@users.noreply.github.com>
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Feb 5, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Refactors the exponential backoff configuration test to remove real-time sleeps by introducing a deterministic backoff_sequence helper and asserting exact delay sequences, while cleaning up unused timing imports and using saturating_mul to safely cap delay doubling.

File-Level Changes

Change Details Files
Make the exponential backoff test deterministic by replacing sleep-based timing with a computed delay sequence and exact equality assertions.
  • Remove use of thread::sleep and Instant-based timing from the exponential backoff test.
  • Compute the backoff progression using a helper that generates a sequence of Duration values based on initial, max, and attempts.
  • Change test expectations from range-based timing checks to an assert_eq! comparison between the generated sequence and expected delays.
  • Use saturating_mul when computing expected doubled delays to avoid overflow and cap them at max.
src/server/config/tests.rs

Assessment against linked issues

Issue Objective Addressed Explanation
#310 Remove wall-clock sleeps and timing-dependent logic from the test_accept_exponential_backoff_doubles_and_caps unit test to eliminate flakiness and speed up tests.
#310 Refactor the exponential backoff verification into a deterministic, pure computation of the backoff sequence (e.g., via a helper function) and assert the expected doubling-and-capping behavior.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 5, 2026

Summary by CodeRabbit

  • Tests
    • Improved backoff timing test reliability by replacing time-dependent assertions with deterministic sequence validation, removing reliance on real elapsed time measurements.

Walkthrough

Refactor the exponential backoff test to remove wall‑clock timing. Replace thread sleeps and Instant measurements with a deterministic backoff_sequence(initial, max, attempts) helper and assert the generated sequence equals the expected saturating‑multiply-and‑cap sequence.

Changes

Cohort / File(s) Summary
Exponential Backoff Test Refactoring
src/server/config/tests.rs
Remove timing-based code (thread::sleep, Instant measurements) and per-iteration delay assertions. Add a pure backoff_sequence helper that builds delays using saturating_mul(2) and min(..., max). Replace runtime waits with a direct equality check between generated sequence and expected delays.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

Sleeps and timing slips away, 🛏️✨
Pure logic now will lead the way,
No flaky waits to mar the day,
Deterministic tests hold sway! 🎯

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarises the main change: removing sleeps from the exponential backoff test, which directly matches the primary objective.
Description check ✅ Passed The description comprehensively outlines the changes made, including replacement of sleep-based timing with deterministic sequence comparison and the addition of a backoff_sequence helper.
Linked Issues check ✅ Passed The PR successfully addresses all coding requirements from issue #310: eliminates wall-clock sleeps, extracts a pure backoff_sequence helper, validates exponential doubling with saturating cap, and achieves deterministic testing.
Out of Scope Changes check ✅ Passed All changes remain strictly within scope of the linked issue #310: refactoring the backoff test to remove sleeps and use deterministic sequence validation, with cleanup of related timing imports.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor-backoff-test-remove-sleeps-v0tv4x

Comment @coderabbitai help to get the list of available commands and usage tips.

@leynos leynos marked this pull request as ready for review February 5, 2026 12:02
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/server/config/tests.rs`:
- Around line 299-309: The test helper backoff_sequence currently uses backoff =
std::cmp::min(backoff.saturating_mul(2), max) which differs from production's
doubling semantics; update backoff_sequence (function backoff_sequence) to
double using Duration's multiplication (e.g. backoff = (backoff * 2).min(max) or
equivalent std::cmp::min(backoff * 2, max)) so the test mirrors production
behavior and will panic on extreme overflow the same way.

Comment thread src/server/config/tests.rs
…ting_mul misuse

Replaced saturating_mul with direct multiplication in backoff sequence calculation to fix incorrect backoff timing logic in tests.

Co-authored-by: devboxerhub[bot] <devboxerhub[bot]@users.noreply.github.com>
@leynos
Copy link
Copy Markdown
Owner Author

leynos commented Feb 5, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 5, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@leynos leynos merged commit a9c7b45 into main Feb 5, 2026
6 checks passed
@leynos leynos deleted the refactor-backoff-test-remove-sleeps-v0tv4x branch February 5, 2026 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove wall-clock sleeps from exponential backoff unit test

1 participant