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.
This commit is contained in:
splitsec2 authored and GitHub committed 2026-10-24 17:10:08 -06:00
1 parent b248bcd536
commit 973cf472a2
1 file changed
+3 -1
+3 -1
View File
@@ -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]