rproxy tests: leave room for a busy host in five timing tests (closes #451)
check / check (push) Failing after 2m3s

Three tests that wait out a 2-second request or response time limit now
use 5 seconds, so the request reaches the app before it runs out under
load. The WebSocket one also renews its connection's deadline after the
wait.

The two breaker tests keep sending requests until one is kept from
asking waf, instead of expecting the sixth to be. On a busy host the five
asks can spread over more than five seconds, or the sixth can arrive
after the open breaker's one-second wait. Their stand-ins for waf now
fail every ask, so a request that asks never closes the breaker.

Model: opus-5-5
This commit is contained in:
sneak committed 2026-11-19 18:34:21 +00:00
1 parent 11ac8aee50
commit 7002a5bfb0
2 files changed
+62 -54

No files matched your search

+8 -3
View File
@@ -1262,7 +1262,9 @@ func TestAVisitorThatStopsALittleShortIsReadUntilTheRequestTimeLimit(
) { ) {
t.Parallel() 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) standIn := startWAF(t, allow)
app := startApp(t, answerBeforeTheBody) app := startApp(t, answerBeforeTheBody)
@@ -1427,17 +1429,20 @@ func TestTheRequestTimeLimitDoesNotCutAnAnswerOnceTheAppHasTheRequest(
const answer = "the end of a long answer" 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) standIn := startWAF(t, allow)
app := startApp(t, func(w http.ResponseWriter, r *http.Request) { app := startApp(t, func(w http.ResponseWriter, r *http.Request) {
_, _ = io.Copy(io.Discard, r.Body) _, _ = io.Copy(io.Discard, r.Body)
_ = http.NewResponseController(w).Flush() _ = http.NewResponseController(w).Flush()
time.Sleep(2100 * time.Millisecond) time.Sleep(limit + 100*time.Millisecond)
_, _ = io.WriteString(w, answer) _, _ = io.WriteString(w, answer)
}) })
addr, _ := startRProxy(t, standIn.URL, app.URL, map[string]string{ addr, _ := startRProxy(t, standIn.URL, app.URL, map[string]string{
maxRequestTime: "2000", maxRequestTime: strconv.FormatInt(limit.Milliseconds(), 10),
}) })
got := visit( got := visit(
+54 -51
View File
@@ -1412,26 +1412,12 @@ func TestFiveFailedAsksKeepTheNextRequestFromAskingWAF(t *testing.T) {
t.Run(name, func(t *testing.T) { t.Run(name, func(t *testing.T) {
t.Parallel() t.Parallel()
var answering atomic.Bool standIn := startWAF(t, failure)
// The app sends back the request ID, so the test knows which
standIn := startWAF( // request rproxy kept from asking.
t,
func(w http.ResponseWriter, r *http.Request) {
if answering.Load() {
allow(w, r)
return
}
failure(w, r)
},
)
nextID := make(chan string, 1)
app := startApp(t, func(w http.ResponseWriter, r *http.Request) { app := startApp(t, func(w http.ResponseWriter, r *http.Request) {
if answering.Load() { id := r.Header.Get(requestIDHeader)
nextID <- r.Header.Get(requestIDHeader) w.Header().Set(requestIDHeader, id)
}
greet(w, r) greet(w, r)
}) })
addr, out := startRProxy( addr, out := startRProxy(
@@ -1455,19 +1441,35 @@ func TestFiveFailedAsksKeepTheNextRequestFromAskingWAF(t *testing.T) {
t.Error("the circuit breaker opened before five asks failed") t.Error("the circuit breaker opened before five asks failed")
} }
answering.Store(true) // Every ask fails, so a request that asks waf keeps the breaker open
wantGreeting(t, get(t, addr, "/")) // or opens it. On a busy host, more requests can ask: the five asks
out.waitFor(t, "the circuit breaker is open") // can take longer than five seconds, and an open breaker lets one
// request ask each second.
deadline := time.Now().Add(waitLimit)
// Had the next request asked waf, its question would have reached var got answered
// the stand-in before the request reached the app.
var id string for !out.has("the circuit breaker is open") {
select { if time.Now().After(deadline) {
case id = <-nextID: t.Fatal(
default: `rproxy did not write "the circuit breaker is open"`,
t.Fatal("the app did not get the next request") )
} }
// The stand-in waits while its channel of questions is full, so
// it is emptied first.
for len(standIn.questions) > 0 {
<-standIn.questions
}
got = get(t, addr, "/")
wantGreeting(t, got)
}
// No question the stand-in got since it was last emptied came from
// the request kept from asking.
id := got.header.Get(requestIDHeader)
for len(standIn.questions) > 0 { for len(standIn.questions) > 0 {
asked := <-standIn.questions asked := <-standIn.questions
if asked.header.Get(requestIDHeader) == id { if asked.header.Get(requestIDHeader) == id {
@@ -1519,18 +1521,7 @@ func TestVisitorsThatGoAwayWhileWAFIsAskedLeaveTheBreakerClosed(
func TestAnswersThatCannotBePassedOnOpenTheBreaker(t *testing.T) { func TestAnswersThatCannotBePassedOnOpenTheBreaker(t *testing.T) {
t.Parallel() t.Parallel()
var answering atomic.Bool standIn := startWAF(t, overOneMiB(dispositionDeny))
tooLarge := overOneMiB(dispositionDeny)
standIn := startWAF(t, func(w http.ResponseWriter, r *http.Request) {
if answering.Load() {
allow(w, r)
return
}
tooLarge(w, r)
})
app := startApp(t, greet) app := startApp(t, greet)
addr, out := startRProxy(t, standIn.URL, app.URL, map[string]string{ addr, out := startRProxy(t, standIn.URL, app.URL, map[string]string{
wafBackendTimeout: "60000", wafBackendTimeout: "60000",
@@ -1544,15 +1535,20 @@ func TestAnswersThatCannotBePassedOnOpenTheBreaker(t *testing.T) {
standIn.question(t) standIn.question(t)
} }
answering.Store(true) // A request that asks waf is answered 502, and one kept from asking gets the
wantGreeting(t, get(t, addr, "/")) // app's greeting. On a busy host, more requests can ask: the five asks can
out.waitFor(t, "the circuit breaker is open") // take longer than five seconds, and an open breaker lets one request ask
// each second.
deadline := time.Now().Add(waitLimit)
select { got := get(t, addr, "/")
case <-standIn.questions: for got.status == http.StatusBadGateway && time.Now().Before(deadline) {
t.Error("waf was asked, want it not to be") standIn.question(t)
case <-time.After(10 * pollInterval): got = get(t, addr, "/")
} }
wantGreeting(t, got)
out.waitFor(t, "the circuit breaker is open")
} }
func TestAPathUnderOwnPrefixNeverReachesTheApp(t *testing.T) { func TestAPathUnderOwnPrefixNeverReachesTheApp(t *testing.T) {
@@ -1809,11 +1805,15 @@ func TestWaitForReportsWaitsForAReportBeingSent(t *testing.T) {
func TestReportOfAWebSocketCountsWhatItCarried(t *testing.T) { func TestReportOfAWebSocketCountsWhatItCarried(t *testing.T) {
t.Parallel() 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) standIn := startWAF(t, allow)
app := startApp(t, echoAfterUpgrade) app := startApp(t, echoAfterUpgrade)
addr, out := startRProxy(t, standIn.URL, app.URL, map[string]string{ addr, out := startRProxy(t, standIn.URL, app.URL, map[string]string{
maxRequestTime: "2000", maxRequestTime: strconv.FormatInt(limit.Milliseconds(), 10),
maxResponseTime: "2000", maxResponseTime: strconv.FormatInt(limit.Milliseconds(), 10),
}) })
conn := dial(t, addr) conn := dial(t, addr)
@@ -1838,7 +1838,10 @@ func TestReportOfAWebSocketCountsWhatItCarried(t *testing.T) {
} }
// Past both time limits, the connection still carries what is sent. // 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" const message = "still here\n"