mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-02-12 08:00:54 +00:00
Fix flaky test_simple_last_seen_cache with retry loop and docstring
This commit is contained in:
committed by
Paul Robinson
parent
23e05177ef
commit
eca5e526f5
@ -31,16 +31,17 @@ async def test_simple_last_seen_cache():
|
|||||||
"""Test that LastSeenCache correctly refreshes expiry when accessed."""
|
"""Test that LastSeenCache correctly refreshes expiry when accessed."""
|
||||||
cache = LastSeenCache(ttl=2, sweep_interval=1)
|
cache = LastSeenCache(ttl=2, sweep_interval=1)
|
||||||
|
|
||||||
assert cache.add(MSG_1) is True # First addition should return True
|
assert cache.add(MSG_1) is True
|
||||||
assert cache.has(MSG_1) is True # Should exist
|
assert cache.has(MSG_1) is True
|
||||||
|
|
||||||
await trio.sleep(1)
|
await trio.sleep(2.5) # Wait past TTL
|
||||||
assert cache.has(MSG_1) is True # Accessing should extend TTL
|
|
||||||
|
|
||||||
await trio.sleep(1.5) # Would have expired if TTL wasn't extended
|
# Retry loop to ensure sweep happens
|
||||||
assert cache.has(MSG_1) is True # Should still exist
|
for _ in range(10): # Up to 1 second extra
|
||||||
|
if not cache.has(MSG_1):
|
||||||
|
break
|
||||||
|
await trio.sleep(0.1)
|
||||||
|
|
||||||
await trio.sleep(2.5) # Now let it expire
|
|
||||||
assert cache.has(MSG_1) is False # Should be expired
|
assert cache.has(MSG_1) is False # Should be expired
|
||||||
|
|
||||||
cache.stop()
|
cache.stop()
|
||||||
|
|||||||
Reference in New Issue
Block a user