From 973cf472a22feefa7dc0412119d9d7b916a3d063 Mon Sep 17 00:00:00 2001 From: splitsec2 <35583321+splitsec2@users.noreply.github.com> Date: Sat, 24 Oct 2026 17:10:08 -0600 Subject: [PATCH] test(image-cache): flush window test no longer depends on float rounding (#1580) `test_cache_hit_flushes_the_index_once_the_window_has_passed` (from #1544) failed on the first attempt of two of my PRs' Python Tests runs today (#1576, #1579) and passed on rerun, with nothing in either PR touching the image cache. The test sets the clock to exactly `last_saved + ACCESS_FLUSH_SECONDS` and expects a flush. `(now + 30) - now` isn't always 30.0 in floating point. For example `105.65207077218265 + 30 - 105.65207077218265` is `29.999999999999986`, so the `>=` check is false and the flush never happens. That only shows up when the monotonic value is small, which fits a freshly booted runner (on this box the uptime is in the millions of seconds and it never fails). I haven't been able to see the runner's actual uptime in the CI logs, so that part is an inference, but pinning `_last_saved` to that value reproduces the exact failure (`assert [] == [1]`) locally. The test now puts the clock one second past the window. The production check is fine, real elapsed time doesn't have this edge, so only the test changes. --- tests/core/test_image_cache.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/core/test_image_cache.py b/tests/core/test_image_cache.py index 7bd4e087..c02ef5ab 100644 --- a/tests/core/test_image_cache.py +++ b/tests/core/test_image_cache.py @@ -112,8 +112,10 @@ def test_cache_hit_flushes_the_index_once_the_window_has_passed(tmp_path, monkey monkeypatch.setattr(cache, "_save_index", lambda: (saves.append(1), real_save())[1]) now = cache._last_saved + # One second past the window. Exactly on it, (now + 30) - now can come out a hair under 30 + # for the small monotonic values of a freshly booted runner. monkeypatch.setattr( - image_cache.time, "monotonic", lambda: now + image_cache.ACCESS_FLUSH_SECONDS + image_cache.time, "monotonic", lambda: now + image_cache.ACCESS_FLUSH_SECONDS + 1 ) assert cache.get("cover-a") is not None assert saves == [1]