A group asks its busy members again after pauses of 2s, 4s, 8s, 16s, then 30s, for as long as its Patience lasts, but replanRounds stopped it after 6 rounds: 90s of pauses whatever the group was set to. real-jacket's trace on #1418 shows patience=240 with replan=6 and ~103s in all. replanRounds is now 12, a backstop sized so that the pauses alone reach PatienceLongest (240s) in 11 rounds, and the patience is what ends the wait. It stays bound by kept.tooQuiet, as before. The longest pause is now 30 x retryPause (30s in use), so the tests' 1ms retryPause doesn't grow a 4s pause at round 12. Run: TestPatienceIsUsedUp (new) counts replan's pauses for 30s to 240s of patience, and TestReplanRoundsOutlastPatience (new) sums the backstop's schedule. With replanRounds back at 6, both fail: patience 3m0s and 4m0s pause 1m30s. go test ./internal/gateway -run 'Overload|Patience|Replan|WaitsOut|Busy|Codex' is green. Not tried against a real overloaded vendor for 240s.
54 lines
1.7 KiB
Go
54 lines
1.7 KiB
Go
package gateway
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// The pauses a group takes add up to its patience, whatever it is set to,
|
|
// and not past it: the rounds are a backstop, not a second, shorter limit
|
|
// (#1418: patience=240 gave up after 90s of pauses, replan=6). Time is
|
|
// counted, not slept: each round's budget is the patience less the pauses
|
|
// before it, as waitFrom.Add(patience) is in the candidate loop.
|
|
func TestPatienceIsUsedUp(t *testing.T) {
|
|
k := retryPause
|
|
retryPause = time.Second
|
|
t.Cleanup(func() { retryPause = k })
|
|
for _, secs := range []int{30, provider.PatienceDefault, 90, 120, 180, provider.PatienceLongest} {
|
|
patience := time.Duration(secs) * time.Second
|
|
var waited time.Duration
|
|
rounds := 0
|
|
for {
|
|
list := []busyTry{{c: candidate{p: provider.Provider{ID: "a"}, model: "m"}, ready: time.Now()}}
|
|
_, wait, ok := replan(list, rounds, time.Now().Add(patience-waited))
|
|
if !ok {
|
|
break
|
|
}
|
|
waited += wait
|
|
rounds++
|
|
}
|
|
// the pause that would end past the budget isn't taken: at most the
|
|
// longest pause is left over
|
|
if waited > patience || waited < patience-replanLongest() {
|
|
t.Errorf("patience %s: %d rounds paused %s", patience, rounds, waited)
|
|
}
|
|
}
|
|
}
|
|
|
|
// The backstop's own schedule outlasts the longest patience a group may
|
|
// set, with no time spent on the tries between.
|
|
func TestReplanRoundsOutlastPatience(t *testing.T) {
|
|
k := retryPause
|
|
retryPause = time.Second
|
|
t.Cleanup(func() { retryPause = k })
|
|
var all time.Duration
|
|
for round := range replanRounds {
|
|
all += min(retryPause<<(round+1), replanLongest())
|
|
}
|
|
if all < provider.PatienceLongest*time.Second {
|
|
t.Fatalf("%d rounds pause %s in all, under PatienceLongest", replanRounds, all)
|
|
}
|
|
}
|