Archived
S9 reads the one remembered advisory again on every look for an hour, and each look was kept as an observation and a line of evidence, so a single refusal read as one repeated every 30 seconds. An observation may now say when what it reads happened and how often; the keeper counts that, and a look with nothing newer adds nothing. Sources that look at the present keep counting their looks.
96 lines
4.3 KiB
Go
96 lines
4.3 KiB
Go
package main
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/novox/mesh-controller/internal/conditions"
|
|
"github.com/novox/mesh-controller/internal/link"
|
|
)
|
|
|
|
// **A refusal the bus said once is counted once** (novox/hq issue 402). The bus refused the controller
|
|
// one publish at 18:52:59 UTC on 2026-10-10 and never again, yet S9 looked at the one remembered
|
|
// advisory every half minute for the hour it is kept, and the condition said "observed 15 time(s), last
|
|
// 13s ago" with a refusal in its evidence every 30 seconds: two of us read it as a refusal going on and
|
|
// went looking for a missing grant. The condition counts what the bus said, with when it last said it,
|
|
// never how often the controller looked.
|
|
func TestARefusalSaidOnceIsCountedOnceHoweverOftenItIsLookedAt(t *testing.T) {
|
|
refused := time.Date(2026, 10, 10, 18, 52, 59, 0, time.UTC)
|
|
now := refused.Add(10 * time.Second)
|
|
store := conditions.NewInMemory()
|
|
k := conditions.NewKeeper(t.Context(), conditions.Options{Store: store, History: store,
|
|
Teller: &conditions.Told{}, Now: func() time.Time { return now }})
|
|
t.Cleanup(func() { k.Close(t.Context()) })
|
|
|
|
// The words the live condition bus.controller.refused carried on 2026-10-10.
|
|
said := "the bus refused the controller: nats: permissions violation: Permissions Violation for " +
|
|
`Publish to "mesh.seat.mesh-delivery.tool.times"`
|
|
advisory := link.Advisory{Kind: link.AdvisoryRefused, ID: "controller", Said: said,
|
|
First: refused, Last: refused, Count: 1}
|
|
look := func() conditions.Condition {
|
|
t.Helper()
|
|
f := &signalFacts{now: now, host: "novox", advisories: []link.Advisory{advisory}}
|
|
if err := k.Reconcile(t.Context(), "S9", watchAdvisories(f)); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
c, found, err := conditions.ReadOne(t.Context(), store, "bus.controller.refused")
|
|
if err != nil || !found {
|
|
t.Fatalf("bus.controller.refused: found %v, %v", found, err)
|
|
}
|
|
return c
|
|
}
|
|
|
|
var c conditions.Condition
|
|
for range 15 {
|
|
c = look()
|
|
now = now.Add(30 * time.Second)
|
|
}
|
|
if c.Observations != 1 || len(c.Evidence) != 1 {
|
|
t.Fatalf("one refusal, looked at 15 times, reads as observed %d time(s) with %d evidence lines: %+v",
|
|
c.Observations, len(c.Evidence), c.Evidence)
|
|
}
|
|
if !c.LastObserved.Equal(refused) || !c.Evidence[0].At.Equal(refused) {
|
|
t.Fatalf("last observed %s, evidence at %s: the refusal was at %s", c.LastObserved, c.Evidence[0].At, refused)
|
|
}
|
|
|
|
// The bus refuses it three times more between two looks: the condition counts four refusals, says
|
|
// the newest, and adds one line of evidence for the look that saw them.
|
|
again := now.Add(-5 * time.Second)
|
|
advisory.Last, advisory.Count = again, 4
|
|
c = look()
|
|
if c.Observations != 4 || len(c.Evidence) != 2 || !c.LastObserved.Equal(again) || !c.Evidence[0].At.Equal(again) {
|
|
t.Fatalf("four refusals read as observed %d time(s), last %s, evidence %+v", c.Observations, c.LastObserved, c.Evidence)
|
|
}
|
|
if !strings.Contains(c.Summary, "(4 times since 18:52 UTC)") {
|
|
t.Fatalf("summary %q", c.Summary)
|
|
}
|
|
now = now.Add(30 * time.Second)
|
|
if c = look(); c.Observations != 4 || len(c.Evidence) != 2 {
|
|
t.Fatalf("a look with nothing new counted: observed %d time(s), evidence %+v", c.Observations, c.Evidence)
|
|
}
|
|
}
|
|
|
|
// **A condition that looks at the present still counts its looks** (novox/hq issue 402 changes only
|
|
// what reads a record): a machine silent for three looks was observed three times, and says so.
|
|
func TestAConditionOfThePresentCountsItsLooks(t *testing.T) {
|
|
now := time.Date(2026, 10, 10, 19, 0, 0, 0, time.UTC)
|
|
store := conditions.NewInMemory()
|
|
k := conditions.NewKeeper(t.Context(), conditions.Options{Store: store, History: store,
|
|
Teller: &conditions.Told{}, Now: func() time.Time { return now }})
|
|
t.Cleanup(func() { k.Close(t.Context()) })
|
|
var c conditions.Condition
|
|
for range 3 {
|
|
var err error
|
|
if c, err = k.Observe(t.Context(), conditions.Observation{Scope: conditions.ScopeMachine, ID: "ace",
|
|
Kind: "silent", Machine: "ace", Severity: conditions.Warning, Summary: "ace has not been heard from",
|
|
Source: "S1"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
now = now.Add(30 * time.Second)
|
|
}
|
|
if c.Observations != 3 || len(c.Evidence) != 3 || !c.LastObserved.Equal(now.Add(-30*time.Second)) {
|
|
t.Fatalf("observed %d time(s), %d evidence lines, last %s", c.Observations, len(c.Evidence), c.LastObserved)
|
|
}
|
|
}
|