From 1a9a27156bba72d739625285d43f968bc8066da4 Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Wed, 30 Sep 2026 10:30:30 -0700 Subject: [PATCH] fix flaky test --- src/service.zig | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/service.zig b/src/service.zig index 0203c94..69f7114 100644 --- a/src/service.zig +++ b/src/service.zig @@ -5320,8 +5320,18 @@ test "recheck floor: once the interval has passed, the symbol is asked again" { var store = svc.store(); const spec = DataService.dividendTtl(divs[0..]); - // One second inside the interval -> still served. - writeAged(Dividend, &store, "TEST", divs[0..], spec, DataService.smart_refresh_recheck_interval - 1); + // A MINUTE either side, not a second. `writeAged` stamps `expires` off + // the wall clock at write time and `askedRecently` recovers the age off + // the wall clock at read time, so the entry ages by however long the gap + // between the two takes. At one second that gap was the margin: under + // kcov the instrumented binary occasionally crossed a second boundary, + // the "inside" entry read as 12h old, the refetch went ahead, and the + // network assertion panicked the coverage run. A minute is far beyond + // any real gap and still nothing against a 12-hour interval. + const margin: i64 = 60; + + // Inside the interval -> still served. + writeAged(Dividend, &store, "TEST", divs[0..], spec, DataService.smart_refresh_recheck_interval - margin); { svc.panic_on_network_attempt = true; const held = try svc.getDividends("TEST", .{}); @@ -5330,9 +5340,9 @@ test "recheck floor: once the interval has passed, the symbol is asked again" { svc.panic_on_network_attempt = false; } - // One second past it -> asked again (NoApiKey proves we got to the - // provider rather than being served the cache). - writeAged(Dividend, &store, "TEST", divs[0..], spec, DataService.smart_refresh_recheck_interval + 1); + // Past it -> asked again (NoApiKey proves we got to the provider rather + // than being served the cache). + writeAged(Dividend, &store, "TEST", divs[0..], spec, DataService.smart_refresh_recheck_interval + margin); try std.testing.expectError(DataError.NoApiKey, svc.getDividends("TEST", .{})); }