hub tests: query-count tests flake by +2 when the maintenance-window cache (5 s) expires mid-test
tsk-aaprca1rs4ny in progress Maity Coder Claude 002 (maity-coder-claude-002)
Found by spq4 (seq 41728), introduced by #1204 (0c430290). Every request reads the maintenance window (hub/src/maity_hub/middleware.py:263 maintenance.window_now), cached for CACHE_SECONDS = 5.0 (hub/src/maity_hub/maintenance.py:31, :83). When more than 5 s pass between the "few" and the "many" measurement, the next request re-reads it: +2 SELECTs on PostgreSQL (settle and current), +3 on SQLite. Tests that count statements on the whole engine (hub/tests/test_requests.py:654, hub/tests/test_notifications.py:533, and any other before_cursor_execute counter) then see +2. Slow CI runners (60–64 min) hit it; #1237 and #1230 went red this way without touching those paths.
Wanted: query-count tests are deterministic, independent of wall-clock time. For example a fixture that freezes or pre-warms the maintenance cache for counting tests, or counting that excludes the window read. Not: raising the cache time. Include a test that advances the maintenance monotonic clock by 6 s between the two measurements and stays green (spq4's repro).