tests: TestAgentGoneInTheRetryPause cancels once the last try is in its pause, not 100ms after the upstream counted it

CI on b75e21be3 (ubuntu, run 38549121391) failed group_replan: the last
try ended 499 "canceled" after 112ms with Again 0, so the agent had left
while the try was still in flight, not in the pause the test is about.
The test counted the upstream's request and then slept a fixed 100ms
before cancelling; on a loaded runner the gateway hadn't read the 503 by
then. It now polls the trace until the last route has its tries and the
last one carries Again (written just before the pause starts), then
cancels.

Run (worktree on origin/main 331c27703):
- Injected a 150ms sleep in the fake upstream between counting and
  answering: the old test fails both subtests with CI's exact shape
  (Millis ~110, Again 0); the new one passes, -count=3.
- Break check: with try.Gone = true taken out of both pause paths in
  gateway.go, the new test fails both subtests.
- go test -race -run TestAgentGoneInTheRetryPause -count=8: ok (116s,
  load average ~300).
- gofmt -l clean, go vet -tags nogui ./internal/gateway ok.
Not run: the whole gateway package (only this test file changed).
This commit is contained in:
yetone
2026-10-14 19:46:29 +08:00
parent 331c27703a
commit b8070cc6c8
+24 -1
View File
@@ -83,7 +83,12 @@ func TestAgentGoneInTheRetryPause(t *testing.T) {
if up.n.Load() != want {
t.Fatalf("upstream asked %d times before the pause, want %d", up.n.Load(), want)
}
time.Sleep(100 * time.Millisecond)
// and its answer has been read: the last try says how long the
// pause is (a fixed sleep here cancelled the last try still in
// flight on a loaded runner)
if !inPause(s, int(want), 10*time.Second) {
t.Fatal("the last try never started its pause")
}
cancel() // the agent's window is closed
<-ended
// the route ends at once, not when the pause would have
@@ -120,3 +125,21 @@ func TestAgentGoneInTheRetryPause(t *testing.T) {
})
}
}
// inPause tells whether the last route's tries number n and the last of
// them waits to be asked again, polled for up to within.
func inPause(s *Server, n int, within time.Duration) bool {
for deadline := time.Now().Add(within); time.Now().Before(deadline); time.Sleep(5 * time.Millisecond) {
s.trace.mu.Lock()
ok := false
if k := len(s.trace.routes); k > 0 {
tries := s.trace.routes[k-1].Tries
ok = len(tries) == n && tries[n-1].Again > 0
}
s.trace.mu.Unlock()
if ok {
return true
}
}
return false
}