feat: complete Windows client control and recovery paths
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package observability
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestHealthHandlerReadinessAndMetrics_HP_OPS_01(t *testing.T) {
|
||||
t.Parallel()
|
||||
health := New()
|
||||
health.Inc("dispatch_attempt")
|
||||
handler := health.Handler(Paths{Liveness: "/live", Readiness: "/ready", Metrics: "/metrics"})
|
||||
ready := httptest.NewRecorder()
|
||||
handler.ServeHTTP(ready, httptest.NewRequest(http.MethodGet, "/ready", nil))
|
||||
if ready.Code != http.StatusServiceUnavailable || !strings.Contains(ready.Body.String(), "ready=false") {
|
||||
t.Fatalf("initial readiness = %d %q", ready.Code, ready.Body.String())
|
||||
}
|
||||
health.SetReady(true)
|
||||
health.SetDirty(true)
|
||||
ready = httptest.NewRecorder()
|
||||
handler.ServeHTTP(ready, httptest.NewRequest(http.MethodGet, "/ready", nil))
|
||||
if ready.Code != http.StatusOK || !strings.Contains(ready.Body.String(), "dirty=true") {
|
||||
t.Fatalf("ready health = %d %q", ready.Code, ready.Body.String())
|
||||
}
|
||||
metrics := httptest.NewRecorder()
|
||||
handler.ServeHTTP(metrics, httptest.NewRequest(http.MethodGet, "/metrics", nil))
|
||||
if metrics.Code != http.StatusOK || !strings.Contains(metrics.Body.String(), "rvbox_dispatch_attempt_total 1") {
|
||||
t.Fatalf("metrics = %d %q", metrics.Code, metrics.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestHealthMetricNamesAreBounded_BH_OPS_01(t *testing.T) {
|
||||
t.Parallel()
|
||||
health := New()
|
||||
health.Inc("bad name")
|
||||
_, _, counters := health.Snapshot()
|
||||
if len(counters) != 0 {
|
||||
t.Fatalf("invalid metric name recorded: %#v", counters)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user