From 0f8e4ebc485c4933710f3aa37f557554cad60211 Mon Sep 17 00:00:00 2001 From: yetone Date: Thu, 8 Oct 2026 17:48:50 +0800 Subject: [PATCH] gateway: TestRestingKeyReadAgainInAnOrderedGroup reads the key's card before planning, so its windows aren't read unraised before the limit goes up Red on main's Race (run 37754525077, d7bdb076): "its limit raised: still rests by window ..., its windows read 3 times". The first plan started a reading of the key's windows; when it was still out as the key refused, ee2588c2's reading-again followed it at once, before the test raised the limit, so it read 800 again, and first() asked for none within the minute. The test's goal, the reading at planning that brings the key back, is unchanged: with the card read first no reading is out when it refuses. Reproduced with the first relay reading held 300ms and a 600ms pause before the raise: FAIL with the same message, read 3 times. With the change it passes under the same delays. Without them: -race -count=40 -cpu 1,2 ok; go vet ./internal/gateway; -race -run 'Key|Resting|Rest' ok. --- internal/gateway/key_limits_test.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/gateway/key_limits_test.go b/internal/gateway/key_limits_test.go index 22a00e570..dbc1f03bc 100644 --- a/internal/gateway/key_limits_test.go +++ b/internal/gateway/key_limits_test.go @@ -300,6 +300,10 @@ func TestRestingKeyReadAgainInAnOrderedGroup(t *testing.T) { if !ok { t.Fatal("no group") } + // its card read first: no reading of the plan's own is out when the + // key refuses, whose reading again after it would come before the + // limit is raised, and read it unraised + provider.KeyBalances(context.Background()) // its card: its week used up s := &Server{} first := func() (string, *Rest) { out, pl := s.planGroup(g, ms, provider.Responses) @@ -317,7 +321,6 @@ func TestRestingKeyReadAgainInAnOrderedGroup(t *testing.T) { } a := cs[0] t.Cleanup(func() { clearRest(a.restKey()) }) - provider.KeyBalances(context.Background()) // its card: its week used up quota := []byte(`{"error":{"message":"api key 7天限额已用完","type":"rate_limit_exceeded"}}`) if r := s.restAfter(a, 429, http.Header{}, quota); r.Why != failQuota || r.By != "window" { t.Fatalf("out of its week: rests by %s (%s)", r.By, r.Why)