gateway tests: a test run again starts routing afresh — routed (each provider's turn, each candidate's failures and tokens) and wrr's rounds live for the process, and fresh() didn't clear them, so under -count=2 TestGroupInGroupKeepsItsOwnRouting's second run began a turn on (c d a b) and TestOrderedKeepsAnAccountAt98's 502 was its second failure (a 4m backoff, not 1m). fresh() now forgets them (forgetRouting), and TestOrderedKeepsAnAccountAt98, which builds its own Server, calls it too. Both pass with -race -count=20 and fail on main under -count=2; go vet and go test ./internal/gateway/ pass.

This commit is contained in:
yetone
2026-10-06 11:31:50 +08:00
parent ccf5e5a1cb
commit e1df9135ad
2 changed files with 15 additions and 0 deletions
+14
View File
@@ -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.
+1
View File
@@ -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()