Files
mesh-controller/cmd/mesh-controller/runtime_health_test.go
T

56 lines
1.9 KiB
Go

package main
import (
"strings"
"testing"
"time"
"github.com/novox/mesh-controller/internal/link"
)
// novox/hq ADR 0366 §3: a module's own runtime stated unhealthy by its runtime-health raises the module's usual
// condition, module.<module>.<machine>.unhealthy, through ADR 0240's path, saying the tool's reason, and the first
// statement that says it healthy clears it.
func TestAnUnhealthyOwnRuntimeRaisesTheModulesUsualCondition(t *testing.T) {
open := aMesh(t)
ctx := t.Context()
inv, k := open.inventory, conditionsFrom
const key = "module.mesh-vault.anchor.unhealthy"
said := func(at time.Time, state, reason string) link.Health {
return link.Health{Contract: link.LivenessContract, At: at, Resources: []link.ResourceHealth{{
Module: "mesh-vault", Resource: "mesh-vault.own-runtime", Kind: "process", Target: "mesh-vault-runtime.service",
State: state, Reason: reason, Since: at, Check: "tool"}}}
}
why := "re-sealing to the operator key failed on 3 passes in a row: the operator key is not readable"
for i := 0; i < 2; i++ {
at := h0.Add(time.Duration(i) * time.Minute)
if err := stateHealth(ctx, inv, k, "anchor", said(at, link.StateUnhealthy, why), at); err != nil {
t.Fatal(err)
}
}
c, had, err := k.Get(ctx, key)
if err != nil || !had {
t.Fatalf("two unhealthy statements of its own runtime raised no %s: %v", key, err)
}
evidence := ""
for _, e := range c.Evidence {
evidence += e.Said + "\n"
}
if !strings.Contains(c.Summary+evidence, "operator key is not readable") {
t.Errorf("the condition does not say the tool's reason: %s / %s", c.Summary, evidence)
}
at := h0.Add(3 * time.Minute)
if err := stateHealth(ctx, inv, k, "anchor", said(at, link.StateHealthy, ""), at); err != nil {
t.Fatal(err)
}
list, err := k.Open(ctx)
if err != nil {
t.Fatal(err)
}
for _, o := range list {
if o.Key == key {
t.Fatalf("a healthy statement did not clear %s", key)
}
}
}