Keep the sww and rproxy tests from failing on a busy host (closes #420)
check / check (push) Failing after 2m0s

The rproxy tests and the sww tests that run rproxy now wait a minute for
waf's answers unless a test sets SWW_RPROXY_WAF_BACKEND_TIMEOUT_MS. At
the 2-second default, a slow host made rproxy drop questions and
reports.

The sww tests run waf with the Core Rule Set off unless a test sets
SWW_WAF_CORE_RULE_SET_MODE. Under the race detector its inspections
could pass waf's 500 ms limit for its checks, and waf answered 503. The
waf package's tests cover the Core Rule Set.

Model: opus-5-5
This commit is contained in:
sneak committed 2026-11-19 08:48:10 +00:00
1 parent dadd5768d5
commit 969f472482
3 files changed
+16 -1

No files matched your search

+3 -1
View File
@@ -324,7 +324,8 @@ func greet(w http.ResponseWriter, r *http.Request) {
// startRProxy starts rproxy with waf at backend and the app at appURL, and
// the settings in env on top of the defaults. It returns where rproxy listens
// and what it writes.
// and what it writes. SWW_RPROXY_WAF_BACKEND_TIMEOUT_MS is a minute unless env
// sets it, so that a busy host cannot make rproxy drop a question or a report.
func startRProxy(
t *testing.T, backend, appURL string, env map[string]string,
) (string, *output) {
@@ -357,6 +358,7 @@ func startServerLogging(
settings := map[string]string{
"SWW_RPROXY_WAF_BACKEND": backend, "SWW_RPROXY_UPSTREAM_URL": appURL,
wafBackendTimeout: "60000",
}
maps.Copy(settings, env)
+3
View File
@@ -52,6 +52,8 @@ func runRProxy(ctx context.Context, env map[string]string, out *output) int {
// startRProxy runs rproxy with waf at backend and the app at appURL, and
// returns its URL and what it writes. It believes X-Forwarded-For from the
// tests. It stops as the test ends, and that it stopped in order is checked.
// It waits a minute for waf's answers, so that a busy host cannot make it drop
// a question or a report.
func startRProxy(t *testing.T, backend, appURL string) (string, *output) {
t.Helper()
@@ -65,6 +67,7 @@ func startRProxy(t *testing.T, backend, appURL string) (string, *output) {
"SWW_RPROXY_UPSTREAM_URL": appURL,
"SWW_RPROXY_TRUSTED_PROXIES": localhost + "/32",
wafBackend: backend,
wafBackendTimeout: "60000",
}, out)
}()
+10
View File
@@ -157,12 +157,21 @@ func (o *output) text() string {
// run runs `sww waf` with the settings in env until ctx is done,
// and returns its exit status. SWW_WAF_LOOKUP_SOURCE is off unless env sets it,
// so that no test sends GeoJS its clients' addresses.
//
// SWW_WAF_CORE_RULE_SET_MODE is off unless env sets it too. The race detector
// and a busy host can slow the Core Rule Set's inspections past waf's time
// limit for its checks, and waf then refuses the request with 503. The waf
// package's tests cover the Core Rule Set.
func run(ctx context.Context, env map[string]string, out *output) int {
v := configtest.Viper(env)
if _, set := env["SWW_WAF_LOOKUP_SOURCE"]; !set {
v.Set("SWW_WAF_LOOKUP_SOURCE", "off")
}
if _, set := env["SWW_WAF_CORE_RULE_SET_MODE"]; !set {
v.Set("SWW_WAF_CORE_RULE_SET_MODE", config.CoreRuleSetModeOff)
}
// The cache files go beside the state files unless the test says
// otherwise.
if _, set := env[cacheDir]; !set && env[stateDir] != "" {
@@ -625,6 +634,7 @@ func TestCoreRuleSetExclusionsFileThatCannotBeReadStopsTheStart(
status := run(t.Context(), map[string]string{
listenAddr: localhost + ":0", stateDir: t.TempDir(), ruleFilesDir: t.TempDir(),
"SWW_WAF_CORE_RULE_SET_MODE": config.CoreRuleSetModeBlock,
"SWW_WAF_CORE_RULE_SET_EXCLUSIONS_FILE": path,
}, out)
if status != 1 {