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.
This commit is contained in:
yetone committed 2026-10-08 17:48:50 +08:00
1 parent 67329b8d9c
commit 0f8e4ebc48
1 file changed
+4 -1
+4 -1
View File
@@ -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)