fix flaky test
All checks were successful
Generic zig build / build (push) Successful in 5m21s
Generic zig build / publish-macos (push) Successful in 12s
Generic zig build / deploy (push) Successful in 20s

This commit is contained in:
Emil Lerch 2026-09-30 10:30:30 -07:00
parent cc60c1991f
commit 1a9a27156b
Signed by: lobo
GPG key ID: A7B62D657EF764F8

View file

@ -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", .{}));
}