Skip to content

Flaky test: test_cache_expires_entries fails intermittently on Windows (Python 3.12) #4602

Backlog

Description

@tomron

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

  1. SurenderguliaEnginner commented on Dec 3, 2026

    @SurenderguliaEnginner

    Hi @tomron, I'd be happy to pick this up and fix the flakiness in test_cache_expires_entries by using a deterministic fake/injectable clock instead of time.sleep.

    Could you please assign this issue to me? Thanks!

  2. tomron commented on Dec 3, 2026

    @tomron
    Author

    @SurenderguliaEnginner i am not a maintainer so I don't think I can assign you

  3. added a commit that references this issue on Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions