From 304caaee027dab2d312d9ba1cee442003d98434c Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Tue, 20 Oct 2026 09:29:00 -0400 Subject: [PATCH] fix: the AcoustID rate-limit test bounds arrivals by the service's 3 a second, not the client's send spacing Run 9543 saw two arrivals 389ms apart though the client sent them 400ms apart. Co-Authored-By: Claude Opus 5.5 --- internal/acoustid/client_test.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/internal/acoustid/client_test.go b/internal/acoustid/client_test.go index 3226fcc4..437388ed 100644 --- a/internal/acoustid/client_test.go +++ b/internal/acoustid/client_test.go @@ -198,10 +198,14 @@ func TestLookup_KeepsToTheRateLimit(t *testing.T) { t.Fatal(err) } } + // The client spaces its sends by minInterval; the server sees arrivals, + // which transit can bunch by a few milliseconds (389ms under -race, CI run + // 9543). What AcoustID enforces is 3 a second at its end, so that is the + // bound: minInterval's headroom is what absorbs the bunching. + const serviceLimit = time.Second / 3 for i := 1; i < len(at); i++ { - // A little slack for the server's own clock reading. - if gap := at[i].Sub(at[i-1]); gap < minInterval-10*time.Millisecond { - t.Errorf("requests %d and %d were %s apart, want at least %s", i-1, i, gap, minInterval) + if gap := at[i].Sub(at[i-1]); gap < serviceLimit { + t.Errorf("requests %d and %d arrived %s apart, want at least %s", i-1, i, gap, serviceLimit) } } }