Skip to content

test: fix flaky backend cache timing - #538

Merged
uniqueg merged 1 commit into
devfrom
test/flaky-cache-timing
Oct 27, 2026
Merged

uniqueg merged 1 commit into
devfrom
test/flaky-cache-timing

Conversation

@uniqueg

@uniqueg uniqueg commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Summary

test_cache compared cache._next_read - cache._last_read with pytest.approx(RETRY_INTERVAL). After a failed read, the retry counts from the end of the read, while _last_read is its start, so the gap exceeds RETRY_INTERVAL by the read time and failed on slow runners (30.000030635 vs 30 ± 3e-05 on "Test (Python 3.15, lowest dependencies)").

The test now reads the clock before and after the call and checks that the next read lies between start + RETRY_INTERVAL and end + RETRY_INTERVAL, which is exact and timing-independent. No other pytest.approx on clock differences exists in the tests.

Closes #537

Verification

  • pytest tests/plugins: 405 passed, 20 of 20 repeated runs
  • pytest -m "not mongodb": 2836 passed, 1 skipped, 131 deselected
  • ruff check, ruff format --check, mypy: clean
  • CI: all checks passed, including CI passed and both lowest-dependency test jobs

Review

Light lane: test-only change of one assertion, no behaviour or CI change; diff reviewed by hand.

🤖 Generated with Claude Code

Summary by Sourcery

Stabilize the backend cache retry timing test by making its assertion independent of the duration of failed reads.

Bug Fixes:

  • Make the backend cache timing test robust to read-duration variability and slow test environments.

Tests:

  • Update the cache retry assertion to validate the retry window using clock bounds instead of an exact timing approximation.

Retries after failed registry reads count from the end of the read, so
the gap between the last read start and the next read exceeds
RETRY_INTERVAL by the read time. Bound the next read by clock reads
taken before and after the call instead of comparing with approx.

Closes #537

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sourcery-ai

sourcery-ai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

The PR updates the backend cache test to account for retries being scheduled at the end of a failed read, using monotonic-clock bounds instead of comparing timestamps with pytest.approx. This is a test-only change that removes timing flakiness without altering cache behavior.

File-Level Changes

Change Details Files
Make the cache retry timing assertion independent of read duration.
  • Capture monotonic time immediately before and after the failed cache read.
  • Assert the scheduled retry falls within the interval offset from both clock readings.
  • Replace the flaky approximate clock-difference comparison with deterministic bounds.
tests/plugins/test_plugin_backends.py

Assessment against linked issues

Issue Objective Addressed Explanation
#537 Make the backend cache retry timing test robust to the read duration and separate clock reads, avoiding the overly tight pytest.approx comparison that caused flaky failures. ✅

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

@codecov

codecov Bot commented Oct 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (1f86561) to head (5b8b96c).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #538   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           55        55           
  Lines         6667      6667           
=========================================
  Hits          6667      6667           
Flag Coverage Δ
test_unit 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@uniqueg
uniqueg marked this pull request as ready for review October 27, 2026 00:45

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

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 assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@uniqueg
uniqueg merged commit 1098fa6 into dev Oct 27, 2026
30 checks passed
@uniqueg
uniqueg deleted the test/flaky-cache-timing branch October 27, 2026 00:49
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.

test: fix flaky backend cache retry timing

1 participant