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()