Description
tests/io/test_content_cache.py::test_cache_expires_entries (added in #4527) failed in the windows-unit-test (3.12) job on PR #4545:
assert new_input.call_count == 2
AssertionError: assert 1 == 2
The test creates the cache with a 1 ms expiration, opens a file, calls time.sleep(0.01), opens it again and expects a second new_input call. The cache is a cachetools.TTLCache using the default time.monotonic timer.
On Python 3.12 on Windows, time.monotonic has a coarse resolution of about 15.6 ms (this was only changed in 3.13, see python/cpython#116781 and python/cpython#88494). A 10 ms sleep can land in the same clock tick, so the entry does not expire. Simulating a clock quantized to 15.6 ms with the same TTL and sleep, the entry expired in only about 65% of 2000 trials, so roughly one run in three would fail.
The same job passed on main and on another PR after #4527 merged, so it is intermittent. Suggested fix: use a fake or injectable clock in the test, as the earlier version did, or sleep for longer than the clock resolution.
The PR that hit it, #4545, does not touch the cache code or tests/io. I haven't reproduced this on a real Windows runner.
Activity
SurenderguliaEnginner commentedon Dec 3, 2026
Hi @tomron, I'd be happy to pick this up and fix the flakiness in
test_cache_expires_entriesby using a deterministic fake/injectable clock instead oftime.sleep.Could you please assign this issue to me? Thanks!
tomron commentedon Dec 3, 2026
@SurenderguliaEnginner i am not a maintainer so I don't think I can assign you
Retrigger CI