Visitar URL original
✅ Stop the timedelta ttl tests racing memcached's one second clock · aisk/python-memcache@640b576 · GitHub
Skip to content

Commit 640b576

Browse files
committed
✅ Stop the timedelta ttl tests racing memcached's one second clock
1 parent ecfded4 commit 640b576

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

‎tests/test_scenario.py‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,12 @@ def test_ttl_accepts_timedelta(cache):
9292
assert 0 < cache.inspect("lasting").ttl <= 600
9393

9494

95-
def test_ttl_subsecond_timedelta_rounds_up_not_forever(cache):
96-
cache.set("blink", "v", ttl=timedelta(milliseconds=500))
97-
assert cache.inspect("blink").ttl != -1
95+
def test_ttl_subsecond_timedelta_rounds_up_not_forever():
96+
# Checked on the wire value: a one second entry can already be gone by
97+
# the time a follow-up read reaches the server.
98+
from memcache.experiment._core import wire_ttl
99+
100+
assert wire_ttl(timedelta(milliseconds=500)) == 1
98101

99102

100103
def test_ttl_rejects_negative_timedelta():
@@ -107,9 +110,10 @@ def test_ttl_rejects_negative_timedelta():
107110

108111
def test_ttl_accepts_aware_datetime(cache):
109112
cache.set("dated", "v", ttl=datetime.now(timezone.utc) + timedelta(minutes=5))
110-
# The absolute moment is rounded up to a whole second, so the remaining
111-
# lifetime may read one second past the requested duration.
112-
assert 0 < cache.inspect("dated").ttl <= 301
113+
# The absolute moment is rounded up to a whole second and memcached's
114+
# own clock only ticks once a second, so the remaining lifetime may read
115+
# up to two seconds past the requested duration.
116+
assert 0 < cache.inspect("dated").ttl <= 302
113117

114118

115119
def test_ttl_rejects_naive_and_past_datetime():

0 commit comments

Comments
 (0)