From 0fb0bfda303daa4c9a56b60e345325c394be04b2 Mon Sep 17 00:00:00 2001 From: yetone Date: Tue, 27 Oct 2026 09:55:48 +0800 Subject: [PATCH] gateway: TestSingleProviderOwnPatienceWins's 429 cases don't race a scaled keepHeldAfter The full suite at f3c4d7b7a went red once on the off case: "agent got 200, upstream asked 1 times; want 429, asked 1". scaled() sets keepHeldAfter to 20ms, so on a busy machine the upstream's 429 came after the held stream had already sent its 200 and SSE comments, and the 429 went to the agent inside the stream. The product's keepHeldAfter is 15s; the off and shorter cases test the user's Patience, not keep-alive, so they now hold keepHeldAfter at a minute. The longer case (want 200) keeps the scaled one. Run: - with a 60ms sleep injected in busyUpstream.ServeHTTP: off and shorter red on the old test, exactly CI's message; green with this change. - without it: -count=20 -run '^TestSingleProviderOwnPatienceWins$' ./internal/gateway ok (11.0s). gofmt clean. Test-only change; nothing else run for it. --- internal/gateway/single_busy_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/gateway/single_busy_test.go b/internal/gateway/single_busy_test.go index 0252aa188..232840d2e 100644 --- a/internal/gateway/single_busy_test.go +++ b/internal/gateway/single_busy_test.go @@ -293,6 +293,12 @@ func TestSingleProviderOwnPatienceWins(t *testing.T) { }} s := busyProviderWaiting(t, u, c.patience) scaled(t, c.byDefault) + if c.want != 200 { + // the 429 is the agent's status, however long a busy + // machine takes to have it: past a scaled keepHeldAfter + // the stream's 200 went first, and the 429 in it + keepHeldAfter = time.Minute + } gw := httptest.NewServer(s.Handler()) t.Cleanup(gw.Close) // a failure ends the request with the test, not when a pause