From e1df9135ad411d84e4e077ee134890aea77b76a3 Mon Sep 17 00:00:00 2001 From: yetone Date: Tue, 6 Oct 2026 11:31:47 +0800 Subject: [PATCH] =?UTF-8?q?gateway=20tests:=20a=20test=20run=20again=20sta?= =?UTF-8?q?rts=20routing=20afresh=20=E2=80=94=20routed=20(each=20provider'?= =?UTF-8?q?s=20turn,=20each=20candidate's=20failures=20and=20tokens)=20and?= =?UTF-8?q?=20wrr's=20rounds=20live=20for=20the=20process,=20and=20fresh()?= =?UTF-8?q?=20didn't=20clear=20them,=20so=20under=20-count=3D2=20TestGroup?= =?UTF-8?q?InGroupKeepsItsOwnRouting's=20second=20run=20began=20a=20turn?= =?UTF-8?q?=20on=20(c=20d=20a=20b)=20and=20TestOrderedKeepsAnAccountAt98's?= =?UTF-8?q?=20502=20was=20its=20second=20failure=20(a=204m=20backoff,=20no?= =?UTF-8?q?t=201m).=20fresh()=20now=20forgets=20them=20(forgetRouting),=20?= =?UTF-8?q?and=20TestOrderedKeepsAnAccountAt98,=20which=20builds=20its=20o?= =?UTF-8?q?wn=20Server,=20calls=20it=20too.=20Both=20pass=20with=20-race?= =?UTF-8?q?=20-count=3D20=20and=20fail=20on=20main=20under=20-count=3D2;?= =?UTF-8?q?=20go=20vet=20and=20go=20test=20./internal/gateway/=20pass.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/gateway/group_test.go | 14 ++++++++++++++ internal/gateway/ordered_spent_test.go | 1 + 2 files changed, 15 insertions(+) diff --git a/internal/gateway/group_test.go b/internal/gateway/group_test.go index ebd7cc584..9088812c0 100644 --- a/internal/gateway/group_test.go +++ b/internal/gateway/group_test.go @@ -51,6 +51,20 @@ func fresh(t *testing.T) { classified.Lock() classified.m, classified.failed = map[string]classifiedAs{}, map[string]classifyFailure{} classified.Unlock() + forgetRouting() +} + +// forgetRouting clears what routing keeps for the gateway's life — each +// provider's turn, each candidate's failures and tokens, each weighted +// round — so a test run again (-count) starts where it did the first time +// rather than a turn on, or with a failure already counted. +func forgetRouting() { + routed.Lock() + routed.turn, routed.used, routed.failures = map[string]int{}, map[string]tokenUse{}, map[string]int{} + routed.Unlock() + wrr.Lock() + wrr.m = map[string]*wrrRound{} + wrr.Unlock() } // setHome makes dir the home, where Windows (USERPROFILE) finds it too. diff --git a/internal/gateway/ordered_spent_test.go b/internal/gateway/ordered_spent_test.go index b7c69a2a5..1d73f7ec3 100644 --- a/internal/gateway/ordered_spent_test.go +++ b/internal/gateway/ordered_spent_test.go @@ -13,6 +13,7 @@ import ( // not until the week renews; Smart keeps it for when nothing else can take // a request, as before. A week used up is out either way (#530). func TestOrderedKeepsAnAccountAt98(t *testing.T) { + forgetRouting() old := allowances defer func() { allowances = old }() now := time.Now()