rproxy tests: leave room for a busy host in four timing tests (closes #451)
check / check (push) Waiting to run
check / check (push) Waiting to run
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 breaker test keeps 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. Model: opus-5-5
This commit is contained in:
1 parent
805c64a256
commit
07777fdc4b
2 files changed
+31
-25
No files matched your search
@@ -1262,7 +1262,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 +1429,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(
|
||||
|
||||
@@ -1519,18 +1519,7 @@ func TestVisitorsThatGoAwayWhileWAFIsAskedLeaveTheBreakerClosed(
|
||||
func TestAnswersThatCannotBePassedOnOpenTheBreaker(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var answering atomic.Bool
|
||||
|
||||
tooLarge := overOneMiB(dispositionDeny)
|
||||
standIn := startWAF(t, func(w http.ResponseWriter, r *http.Request) {
|
||||
if answering.Load() {
|
||||
allow(w, r)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
tooLarge(w, r)
|
||||
})
|
||||
standIn := startWAF(t, overOneMiB(dispositionDeny))
|
||||
app := startApp(t, greet)
|
||||
addr, out := startRProxy(t, standIn.URL, app.URL, map[string]string{
|
||||
wafBackendTimeout: "60000",
|
||||
@@ -1544,15 +1533,20 @@ func TestAnswersThatCannotBePassedOnOpenTheBreaker(t *testing.T) {
|
||||
standIn.question(t)
|
||||
}
|
||||
|
||||
answering.Store(true)
|
||||
wantGreeting(t, get(t, addr, "/"))
|
||||
out.waitFor(t, "the circuit breaker is open")
|
||||
// A request that asks waf is answered 502, and one kept from asking gets the
|
||||
// app's greeting. On a busy host, more requests can ask: the five asks can
|
||||
// take longer than five seconds, and an open breaker lets one request ask
|
||||
// each second.
|
||||
deadline := time.Now().Add(waitLimit)
|
||||
|
||||
select {
|
||||
case <-standIn.questions:
|
||||
t.Error("waf was asked, want it not to be")
|
||||
case <-time.After(10 * pollInterval):
|
||||
got := get(t, addr, "/")
|
||||
for got.status == http.StatusBadGateway && time.Now().Before(deadline) {
|
||||
standIn.question(t)
|
||||
got = get(t, addr, "/")
|
||||
}
|
||||
|
||||
wantGreeting(t, got)
|
||||
out.waitFor(t, "the circuit breaker is open")
|
||||
}
|
||||
|
||||
func TestAPathUnderOwnPrefixNeverReachesTheApp(t *testing.T) {
|
||||
@@ -1809,11 +1803,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)
|
||||
@@ -1838,7 +1836,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"
|
||||
|
||||
|
||||
Reference in new issue
Block a user