Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions newsfragments/1408.internal.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
De-flaked ``test_expiry_removal`` by polling until the background sweeper thread removes the expired entry instead of a fixed ``trio.sleep``, which raced on slow CI runners (integer-second TTL swept on a coarse ~1s thread cadence).
9 changes: 7 additions & 2 deletions tests/core/tools/timed_cache/test_timed_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,13 @@ async def test_expiry_removal():
"""Test that expired items are removed by the background sweeper."""
cache = LastSeenCache(ttl=2, sweep_interval=1)
cache.add(MSG_1)
await trio.sleep(2.1) # Wait for sweeper to remove expired items
assert MSG_1 not in cache.cache # Should be removed
# Poll until the background sweeper removes the expired entry instead of a
# fixed sleep. The sweeper is a real thread on a `sweep_interval` cadence and
# the TTL is integer-second, so removal timing is coarse; a fixed 2.1s sleep
# raced on slow CI runners and left the entry still present.
with trio.fail_after(15):
while MSG_1 in cache.cache:
await trio.sleep(0.1)
cache.stop()


Expand Down
Loading