sww tests: wait for every starting line as long as the start takes (closes #331)
check / check (push) Waiting to run

Each test in internal/sww that waits for the starting line now waits until
the line is written or sww exits, so a slow Core Rule Set compile on a
loaded host no longer fails it. The two tests that run sww as a child
process get its exit status from a goroutine that waits on it, and no
longer kill it after 30 seconds; the waits after SIGTERM still end after
waitLimit. startRProxyProcess returns a stop function in place of the
process and its output.

Model: opus-5-5
This commit is contained in:
sneak committed 2026-11-11 07:00:26 +00:00
1 parent eba697af48
commit 08b05907a5
3 files changed
+50 -42

No files matched your search

+16 -13
View File
@@ -54,12 +54,9 @@ func TestMainRunsWAF(t *testing.T) {
t.Fatalf("find the test binary: %v", err)
}
ctx, cancel := context.WithTimeout(t.Context(), 3*waitLimit)
defer cancel()
dir := t.TempDir()
out := &output{}
cmd := exec.CommandContext(ctx, binary) //nolint:gosec // this test binary
cmd := exec.CommandContext(t.Context(), binary) //nolint:gosec // this test binary
cmd.Stdout = out
cmd.Env = append(os.Environ(),
@@ -75,12 +72,14 @@ func TestMainRunsWAF(t *testing.T) {
t.Fatalf("start: %v", err)
}
t.Cleanup(func() {
_ = cmd.Process.Kill()
_ = cmd.Wait()
})
exited := make(chan int, 1)
starting := out.line(t, "msg", "starting")
go func() {
_ = cmd.Wait()
exited <- cmd.ProcessState.ExitCode()
}()
starting := out.lineBeforeExit(t, "starting", exited)
addr, _ := starting["address"].(string)
ask(t, addr, "/", http.StatusOK, waf.DispositionAllow)
@@ -90,9 +89,13 @@ func TestMainRunsWAF(t *testing.T) {
t.Fatalf("signal: %v", err)
}
err = cmd.Wait()
if err != nil {
t.Fatalf("exit: %v; output:\n%s", err, out.text())
select {
case status := <-exited:
if status != 0 {
t.Fatalf("exit status %d, want 0; output:\n%s", status, out.text())
}
case <-time.After(waitLimit):
t.Fatal("still running after being told to stop")
}
wantUTC(t, "the process line", starting["time"])
@@ -215,7 +218,7 @@ func runWAF(t *testing.T, env map[string]string, use func(addr string)) {
exited <- run(ctx, env, out)
}()
addr, _ := out.line(t, "msg", "starting")["address"].(string)
addr, _ := out.lineBeforeExit(t, "starting", exited)["address"].(string)
use(addr)
stop()