From 8807f4d27d1aebec764effa199fdd63c82f05947 Mon Sep 17 00:00:00 2001 From: Lukasz Raczylo Date: Thu, 24 Sep 2026 06:04:40 +0100 Subject: [PATCH] fix(test): pin the limiter clock in TestModelSpanTotalsSumsBuckets The test wrote counters for a fixed date, 2026-09-23, but never pinned the limiter's clock. modelTotals therefore read the real time. The test passed only on the date it was written and fails on every later day. It now sets l.nowFn to the fixed time, as the other span tests do. This is a test-only fix; production code is unchanged. Claude-Session: https://claude.ai/code/session_01V5jYJNxpDFdJkyyExpADrv --- limits_test.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/limits_test.go b/limits_test.go index 38e5dd5..0ea604a 100644 --- a/limits_test.go +++ b/limits_test.go @@ -2637,6 +2637,19 @@ func TestModelTotals_ConfiguredStoreDown_FailOpen_ReturnsNotOK(t *testing.T) { func TestModelSpanTotalsSumsBuckets(t *testing.T) { l := newLimiter(nil, true) now := time.Date(2026, 9, 23, 10, 0, 0, 0, time.UTC) + // Fix (verify-retry.md item 5): pin the limiter's own clock to the + // fixed now above — the same convention every other test in this file + // that touches l.now() already follows (TestLimiterRequestWindow and + // dozens more, each setting l.nowFn right after newLimiter). Without + // this, modelTotals below reads l.now() (real time.Now(), limits.go's + // newLimiter default) instead of this test's fixed now: the buckets + // were written against 2026-09-23, so the span=1 assertion only + // happened to pass on the calendar day this test was first written, + // and fails deterministically on every later day — not a race, and + // not flaky under -race specifically; a plain date mismatch that + // -race's slower execution does not change the odds of, just the day + // this was first noticed on. + l.nowFn = func() time.Time { return now } id := "openai/gpt-4o" l.incrCounter(kindModel, id, metricReq, windowDay, historyStepBack(now, windowDay, 2), 5, dayWindowTTL)