From bfdf17126c72115267c04c9e3f8906a3eeb3d0b0 Mon Sep 17 00:00:00 2001 From: sneak Date: Thu, 19 Nov 2026 19:24:37 +0000 Subject: [PATCH] rproxy tests: leave room for a busy host in five timing tests (closes #451) Three tests that wait out a 2- or 3-second request time limit now use 5 seconds, so the request reaches the app before it runs out under load. The WebSocket test also uses 5-second limits, and renews its connection's deadline after the wait. TestFiveFailedAsksKeepTheNextRequestFromAskingWAF stops the breaker's clock like TestAnswersThatCannotBePassedOnOpenTheBreaker. Model: opus-5-5 --- internal/rproxy/limits_test.go | 17 +++++++++++++---- internal/rproxy/rproxy_test.go | 31 +++++++++++++++++++++---------- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/internal/rproxy/limits_test.go b/internal/rproxy/limits_test.go index 8035e4e..1d96bf0 100644 --- a/internal/rproxy/limits_test.go +++ b/internal/rproxy/limits_test.go @@ -870,10 +870,14 @@ func TestAnAnswerRProxyGivesItselfHasTenSecondsToBeSentAtLeast( func TestAVisitorTooSlowToSendTheRestIsAnswered408(t *testing.T) { t.Parallel() + // rproxy is waiting for the rest of the body well within this limit, even on + // a busy host, and answers when it runs out, well before dial's deadline. + const limit = 5 * time.Second + standIn := startWAF(t, allow) app := startApp(t, greet) addr, _ := startRProxy(t, standIn.URL, app.URL, map[string]string{ - maxRequestTime: "3000", + maxRequestTime: strconv.FormatInt(limit.Milliseconds(), 10), }) conn := dial(t, addr) @@ -1262,7 +1266,9 @@ func TestAVisitorThatStopsALittleShortIsReadUntilTheRequestTimeLimit( ) { t.Parallel() - const limit = 2 * time.Second + // The app's answer arrives well within this limit, even on a busy host, and + // the connection closes when it runs out, well before dial's deadline. + const limit = 5 * time.Second standIn := startWAF(t, allow) app := startApp(t, answerBeforeTheBody) @@ -1427,17 +1433,20 @@ func TestTheRequestTimeLimitDoesNotCutAnAnswerOnceTheAppHasTheRequest( const answer = "the end of a long answer" + // The request reaches the app well within this limit, even on a busy host. + const limit = 5 * time.Second + standIn := startWAF(t, allow) app := startApp(t, func(w http.ResponseWriter, r *http.Request) { _, _ = io.Copy(io.Discard, r.Body) _ = http.NewResponseController(w).Flush() - time.Sleep(2100 * time.Millisecond) + time.Sleep(limit + 100*time.Millisecond) _, _ = io.WriteString(w, answer) }) addr, _ := startRProxy(t, standIn.URL, app.URL, map[string]string{ - maxRequestTime: "2000", + maxRequestTime: strconv.FormatInt(limit.Milliseconds(), 10), }) got := visit( diff --git a/internal/rproxy/rproxy_test.go b/internal/rproxy/rproxy_test.go index 74578f3..01ee5d5 100644 --- a/internal/rproxy/rproxy_test.go +++ b/internal/rproxy/rproxy_test.go @@ -1452,14 +1452,18 @@ func TestFiveFailedAsksKeepTheNextRequestFromAskingWAF(t *testing.T) { greet(w, r) }) - addr, out := startRProxy( - t, - standIn.URL, - app.URL, - map[string]string{ - wafBackendTimeout: "200", - }, + out := &output{} + server := newServer( + t, standIn.URL, app.URL, + map[string]string{wafBackendTimeout: "200"}, + out, out, ) + // The breaker's clock stands still, as in + // TestAnswersThatCannotBePassedOnOpenTheBreaker: on a slow host, the five + // failures could take more than five seconds, and the next request could + // come more than a second later. + server.StopBreakerClock(time.Now()) + addr := serve(t, server) // An ask can time out before it reaches the stand-in, so these // may leave fewer than five questions, or leave some late. @@ -1831,11 +1835,15 @@ func TestWaitForReportsWaitsForAReportBeingSent(t *testing.T) { func TestReportOfAWebSocketCountsWhatItCarried(t *testing.T) { t.Parallel() + // The app's answer to the upgrade arrives well within these limits, even on a + // busy host. + const limit = 5 * time.Second + standIn := startWAF(t, allow) app := startApp(t, echoAfterUpgrade) addr, out := startRProxy(t, standIn.URL, app.URL, map[string]string{ - maxRequestTime: "2000", - maxResponseTime: "2000", + maxRequestTime: strconv.FormatInt(limit.Milliseconds(), 10), + maxResponseTime: strconv.FormatInt(limit.Milliseconds(), 10), }) conn := dial(t, addr) @@ -1860,7 +1868,10 @@ func TestReportOfAWebSocketCountsWhatItCarried(t *testing.T) { } // Past both time limits, the connection still carries what is sent. - time.Sleep(2100 * time.Millisecond) + time.Sleep(limit + 100*time.Millisecond) + + // dial's deadline ran from before the upgrade and this wait. + _ = conn.SetDeadline(time.Now().Add(waitLimit)) const message = "still here\n" -- 2.54.0