test: fix flaky test_service_browser_expire_callbacks - #1879
Merged
Merged
Conversation
|
Thanks for contributing! A quick note: this project is in the process of moving from LGPL-2.1 to Apache 2.0, see #1835. By continuing with this pull request you are okay with your contribution, and your previous contributions to this repository, being offered under Apache 2.0. If that does not work for you, no hard feelings; reply with the exact phrase |
bdraco
force-pushed
the
fix_expire_callbacks_flake
branch
from
August 29, 2026 23:00
b77017f to
21c04fd
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1879 +/- ##
=======================================
Coverage 99.87% 99.87%
=======================================
Files 33 33
Lines 3882 3882
Branches 567 567
=======================================
Hits 3877 3877
Misses 3 3
Partials 2 2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
test_service_browser_expire_callbacksintermittently misses theremovecallback (seen on the PyPy 3.10 /skip_cythonrunner in this run). The test restamped every cached record's TTL from the main thread while the reaper runsDNSCache.async_expireon the event loop thread, and then waited a fixed 0.3 s for each callback.Details
_async_set_created_ttlrewrites the expiration heap;async_expirepops it. Doing the rewrite from the main thread races the reaper, and a re-add that lands mid-pop can leave the record's heap entry behind so the expiry never fires. The restamp now runs on the loop thread viacall_soon_threadsafeand blocks on anEventuntil it has completed. This lives intests/__init__.pyas_restamp_cache, next to_backdate_cache, with a docstring saying which to reach for:_backdate_cacheonly shiftscreated(for the RFC 6762 §10.2 recency checks),_restamp_cachere-adds through_async_set_created_ttlso the reaper actually expires the records.for _ in range(30): sleep(0.01)loops are replaced with a predicate-based_wait_for(predicate, timeout=2.0)helper intests/__init__.py, so a slow interpreter or a loaded runner no longer trips the assertion. The happy path is unchanged: it returns as soon as the predicate holds. The other hand-rolled poll loops intest_core.py,test_handlers.pyandutils/test_asyncio.pycould adopt it in a follow-up; left alone here to keep this a flake fix.Test plan
poetry run pytest tests/services/test_browser.py -k expire_callbacks10× in a row,SKIP_CYTHON=1tests/services/test_browser.pyandtests/test_core.pypasspre-commit run --files tests/services/test_browser.pyclean