diff --git a/internal/gateway/agent_gone_pause_test.go b/internal/gateway/agent_gone_pause_test.go index 662b01778..c873becaa 100644 --- a/internal/gateway/agent_gone_pause_test.go +++ b/internal/gateway/agent_gone_pause_test.go @@ -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 +}