From 78b4ef1210883156146123f9330d5177ceacf818 Mon Sep 17 00:00:00 2001 From: sneak Date: Thu, 19 Nov 2026 17:38:13 +0000 Subject: [PATCH] waf: wait as long as it takes for a test request's answer (closes #454) requestWithBody gave the answer 10 seconds, and endedLines gave the log line 10 seconds. On a busy host the Core Rule Set's inspection of a request with 1000 query parameters, under the race detector, took longer. Both now wait until the answer or line comes; go test's -timeout ends a test where it never does. Model: opus-5-5 --- internal/waf/bans_test.go | 9 ++++----- internal/waf/proxy_test.go | 8 ++------ 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/internal/waf/bans_test.go b/internal/waf/bans_test.go index a2f2a23..9f98d9b 100644 --- a/internal/waf/bans_test.go +++ b/internal/waf/bans_test.go @@ -548,6 +548,10 @@ func (s *sender) requestWithHeader( // body is sent as it is after the headers, header holding its // Content-Length or Transfer-Encoding. header may hold several lines, // separated by "\r\n". It returns the whole answer. +// +// It waits for the answer as long as it takes, since a busy host can slow +// the Core Rule Set past any shorter wait. go test's -timeout ends a test +// whose answer never comes. func (s *sender) requestWithBody( method, from, path, header, body string, status int, action string, ) (logLine, answer) { @@ -566,11 +570,6 @@ func (s *sender) requestWithBody( send(s.t, conn, method+" "+path+" HTTP/1.1\r\nHost: "+appHost+"\r\n"+ forwardedFor+": "+from+"\r\n"+header+"\r\n"+body) - err := conn.SetReadDeadline(time.Now().Add(waitLimit)) - if err != nil { - s.t.Fatalf("set read deadline: %v", err) - } - var got answer res, err := http.ReadResponse(bufio.NewReader(conn), nil) diff --git a/internal/waf/proxy_test.go b/internal/waf/proxy_test.go index f5eeb27..81e46f0 100644 --- a/internal/waf/proxy_test.go +++ b/internal/waf/proxy_test.go @@ -193,11 +193,11 @@ func (o *output) requestLine(t *testing.T) logLine { // endedLines waits for count requests that went through rproxy, or to waf's // own endpoints, to have ended, and returns the last log line of each, in the // order waf took them. A question's last line is the one its report writes. +// It waits as long as it takes, as requestWithBody does. func (o *output) endedLines(t *testing.T, count int) []logLine { t.Helper() - deadline := time.Now().Add(waitLimit) - for time.Now().Before(deadline) { + for { found := o.lastLines(t) ended := len(found) >= count @@ -213,10 +213,6 @@ func (o *output) endedLines(t *testing.T, count int) []logLine { time.Sleep(pollInterval) } - - t.Fatalf("fewer than %d requests have ended after %s", count, waitLimit) - - return nil } // lastLines returns the last request log line written so far of each request, -- 2.54.0