Skip to content

Fix flaky cache-timing test with a ratio-based assertion#220

Merged
derek73 merged 1 commit into
masterfrom
fix/flaky-cache-timing-test
Jul 5, 2026
Merged

Fix flaky cache-timing test with a ratio-based assertion#220
derek73 merged 1 commit into
masterfrom
fix/flaky-cache-timing-test

Conversation

@derek73

@derek73 derek73 commented Jul 5, 2026

Copy link
Copy Markdown
Owner

Summary

  • test_repeated_access_is_cached compared 10,000 cached-property accesses against a fixed 10ms wall-clock budget, which flaked on CI runners (observed 10.0-10.2ms in PR Add Codecov coverage reporting and README badges #219 on both Python 3.10 and 3.13)
  • Replaced the fixed budget with a ratio-based check: measure the uncached build cost on the same machine (via fresh Constants() instances) and assert cached access is at least an order of magnitude faster
  • This scales with runner speed instead of racing a fixed clock, while still failing if caching is actually broken

Test plan

  • uv run pytest tests/test_constants.py::SuffixesPrefixesTitlesPerformanceTests -v passes
  • Full suite passes: uv run pytest (1310 passed, 22 xfailed)
  • Verified the test still has teeth: temporarily stubbed out the _pst cache in nameparser/config/__init__.py and confirmed the test fails (caught by the pre-existing identity assertion), then reverted

test_repeated_access_is_cached compared against a fixed 10ms wall-clock
budget, which flaked on CI runners where cached access alone took
~10.0-10.2ms (PR #219). Instead, measure the uncached build cost on the
same machine and assert cached access is an order of magnitude faster,
so the test scales with runner speed instead of racing a fixed clock.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@derek73 derek73 self-assigned this Jul 5, 2026
@derek73 derek73 added this to the v1.3.0 milestone Jul 5, 2026
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.11%. Comparing base (14b7098) to head (7a51c01).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #220   +/-   ##
=======================================
  Coverage   97.11%   97.11%           
=======================================
  Files          13       13           
  Lines         797      797           
=======================================
  Hits          774      774           
  Misses         23       23           

☔ 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.

@derek73 derek73 merged commit e518479 into master Jul 5, 2026
8 checks passed
@derek73 derek73 deleted the fix/flaky-cache-timing-test branch July 5, 2026 05:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants