1 Commits
Author SHA1 Message Date
sneak bbb435b034 Health check test uses addresses nothing can listen on (closes #158)
check / check (push) Waiting to run
TestHealthCheck closed the app's server, and later smallwebwaf, and
expected connections to the freed ports to fail. Another test could take
such a port in between, so the connection succeeded and the test failed.

The failing app check now uses the multicast address 224.0.0.1, to which
TCP cannot connect. The failing smallwebwaf check uses port 0, on which
nothing listens. Neither result depends on other processes. The code
under test is unchanged.

Model: opus-5-5
2026-10-27 18:36:51 +00:00
+9 -8
View File
@@ -61,19 +61,13 @@ func TestHealthCheck(t *testing.T) {
} }
// Another test can take a closed server's port at once, so the app's // Another test can take a closed server's port at once, so the app's
// address here is a multicast address, to which TCP cannot connect. // address here is one that nothing can listen on: TCP cannot connect
// to a multicast address such as 224.0.0.1.
wantHealthCheck(t, map[string]string{ wantHealthCheck(t, map[string]string{
listenAddr: ":" + port, listenAddr: ":" + port,
upstreamURL: "http://224.0.0.1", upstreamURL: "http://224.0.0.1",
}, 1, "unhealthy: connect to the app: ") }, 1, "unhealthy: connect to the app: ")
// Listening on port 0 takes any free port, so nothing listens on port 0
// itself.
wantHealthCheck(t, map[string]string{listenAddr: ":0"}, 1,
"unhealthy: ask smallwebwaf: ")
wantHealthCheck(t, map[string]string{listenAddr: "8080"}, 1,
"unhealthy: invalid setting: SWWAF_LISTEN_ADDR: ")
stop() stop()
select { select {
@@ -81,6 +75,13 @@ func TestHealthCheck(t *testing.T) {
case <-time.After(waitLimit): case <-time.After(waitLimit):
t.Fatal("still running after being told to stop") t.Fatal("still running after being told to stop")
} }
// Listening on port 0 takes any free port, so nothing listens on port 0
// itself.
wantHealthCheck(t, map[string]string{listenAddr: ":0"}, 1,
"unhealthy: ask smallwebwaf: ")
wantHealthCheck(t, map[string]string{listenAddr: "8080"}, 1,
"unhealthy: invalid setting: SWWAF_LISTEN_ADDR: ")
} }
func TestHealthCheckRefusesAnArgument(t *testing.T) { func TestHealthCheckRefusesAnArgument(t *testing.T) {