The update watchdog verifies archied's restart, so archied has to be what answers. It was probing the dashboard's /healthz, which belongs to the dashboard: switch [web] off and nothing answers, and in the extracted UI topology that endpoint reports a different process entirely, which would confirm a release while the daemon it was meant to verify is down. [health].listen (127.0.0.1:8485, defaulted, always on) serves /healthz, /health and /health/detailed for the life of the process. Liveness answers 503 until the daemon reaches its run loop: the listener binds before the subsystems do, so an unconditional 200 would tell the watchdog a half-booted release came up. Failing to bind is fatal, because a daemon nothing can probe gets every update rolled back. The State Store's readiness surface now shares the listener plumbing, keeping its log and error text verbatim. Closes archie-core-exbz, which asked which of two bad options to take when the dashboard is off. Neither: the daemon owns its own liveness. Also deletes TestInstallUpdateDetachesInstallerFromCallbackContext. It has failed intermittently under load more than once, racing its fake bot server's multipart parse against the cancellation it induces.
83 lines
2.8 KiB
Go
83 lines
2.8 KiB
Go
package archied
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/samcharles93/archie-core/internal/domain/health"
|
|
)
|
|
|
|
// TestHealthSurfaceLivenessWaitsForBoot: the update watchdog restarts archied
|
|
// and takes the first 200 as proof the new release came up. The listener
|
|
// binds early so the port is not simply refused during boot, which means an
|
|
// unconditional 200 would confirm a release that had not started yet.
|
|
func TestHealthSurfaceLivenessWaitsForBoot(t *testing.T) {
|
|
surface := &healthSurface{}
|
|
handler := surface.handler()
|
|
|
|
for _, path := range []string{"/healthz", "/health"} {
|
|
res := httptest.NewRecorder()
|
|
handler.ServeHTTP(res, httptest.NewRequestWithContext(t.Context(), http.MethodGet, path, nil))
|
|
if res.Code != http.StatusServiceUnavailable {
|
|
t.Errorf("GET %s while booting = %d, want 503", path, res.Code)
|
|
}
|
|
}
|
|
|
|
surface.markServing()
|
|
|
|
for _, path := range []string{"/healthz", "/health"} {
|
|
res := httptest.NewRecorder()
|
|
handler.ServeHTTP(res, httptest.NewRequestWithContext(t.Context(), http.MethodGet, path, nil))
|
|
if res.Code != http.StatusOK {
|
|
t.Errorf("GET %s once serving = %d, want 200", path, res.Code)
|
|
}
|
|
}
|
|
}
|
|
|
|
// TestHealthSurfaceDetailedReportsProbes: /health/detailed is the readiness
|
|
// answer, and an unwired or degraded registry must never read as ready.
|
|
func TestHealthSurfaceDetailedReportsProbes(t *testing.T) {
|
|
var registry *health.Registry
|
|
surface := &healthSurface{registry: func() *health.Registry { return registry }}
|
|
surface.markServing()
|
|
handler := surface.handler()
|
|
|
|
res := httptest.NewRecorder()
|
|
handler.ServeHTTP(res, httptest.NewRequestWithContext(t.Context(), http.MethodGet, "/health/detailed", nil))
|
|
if res.Code != http.StatusServiceUnavailable {
|
|
t.Fatalf("detailed with no probes = %d, want 503", res.Code)
|
|
}
|
|
|
|
registry = health.NewRegistry(failingProbe{})
|
|
res = httptest.NewRecorder()
|
|
handler.ServeHTTP(res, httptest.NewRequestWithContext(t.Context(), http.MethodGet, "/health/detailed", nil))
|
|
if res.Code != http.StatusServiceUnavailable {
|
|
t.Fatalf("detailed with a failing probe = %d, want 503", res.Code)
|
|
}
|
|
|
|
registry = health.NewRegistry(passingProbe{})
|
|
res = httptest.NewRecorder()
|
|
handler.ServeHTTP(res, httptest.NewRequestWithContext(t.Context(), http.MethodGet, "/health/detailed", nil))
|
|
if res.Code != http.StatusOK {
|
|
t.Fatalf("detailed with a passing probe = %d, want 200", res.Code)
|
|
}
|
|
}
|
|
|
|
type failingProbe struct{}
|
|
|
|
func (failingProbe) Name() string { return "test" }
|
|
|
|
func (failingProbe) Check(context.Context) health.Result {
|
|
return health.Result{Status: health.StatusDegraded, Detail: "down"}
|
|
}
|
|
|
|
type passingProbe struct{}
|
|
|
|
func (passingProbe) Name() string { return "test" }
|
|
|
|
func (passingProbe) Check(context.Context) health.Result {
|
|
return health.Result{Status: health.StatusOK}
|
|
}
|