Files
mesh-delivery/modules/mesh-delivery-watchman/internal/watch/waits_test.go
T
jschoubben faec6b5333 WM13 (watchman half): the builder's builds are no longer read; a package wait is heard as wait-held
The watchman's read of mesh-delivery-builder.builds (Build in mirror.go, the bucket, its manifest reads) goes; it hears the
builder's wait-held and wait-ended on the builder's stream, naming a package as their part, and times them as an acting
part's wait. A toolchain wait (no part) is left to the builder's own finding. The node-engine's have and mesh-host.health
reads stay: no event carries a have's phase, kept data, node record or a node's health report (asked of the lead).

Builds: design 47 G A-192, §484, §496, §602, §548

Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
2026-11-12 05:53:23 +01:00

161 lines
7.0 KiB
Go

package watch
import (
"encoding/json"
"strings"
"testing"
"time"
"git.novox.be/novox/mesh-contracts/go/seats/nodeengine"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
)
func heldWait(module string, since time.Time, from *time.Time) []byte {
b, _ := json.Marshal(meshwants.Wait{Step: "place", Part: "mesh-delivery-indexer", Version: "src2:new", Node: "ace", Module: module,
Since: since, ClockFrom: from, Bound: "30m"})
return b
}
// design 47 G §266, §269 (WM6): a wait held is the finding `acting-part-late` once its bound has run from the time `wait-held`
// carries as `clock-from` (its `since` where it carries none), not within it; `wait-ended` ends it.
func TestAnActingPartsWaitIsLateByItsBoundFromItsClock(t *testing.T) {
id := "mesh-wants-place-mesh-delivery-indexer-ace-web"
key := FindingKey(ScopeDelivery, id, KindActingPartLate)
t.Run("within the bound nothing, past it a finding, wait-ended ends it", func(t *testing.T) {
w, o, c := setup()
w.WaitHeld("mesh-wants", heldWait("web", c.t, nil))
if o.ttls[signalKey(actingRow, id)] != 30*time.Minute || len(o.findings) != 0 {
t.Fatalf("within the bound: ttl %v, findings %v", o.ttls[signalKey(actingRow, id)], o.findings)
}
expire(w, c, signalKey(actingRow, id), 30*time.Minute)
if _, ok := o.findings[key]; !ok {
t.Fatalf("past its bound: %v", o.findings)
}
w.WaitEnded("mesh-wants", heldWait("web", c.t, nil))
if len(o.findings) != 0 {
t.Fatalf("wait-ended left %v", o.findings)
}
})
t.Run("the bound counts from clock-from, not from since", func(t *testing.T) {
w, o, c := setup()
from := c.t.Add(-20 * time.Minute)
w.WaitHeld("mesh-wants", heldWait("web", c.t.Add(-time.Hour), &from))
if got := o.ttls[signalKey(actingRow, id)]; got != 10*time.Minute {
t.Fatalf("a wait whose clock began 20 minutes ago has %v left, want 10m", got)
}
})
t.Run("a wait whose bound ran before it was heard is a finding at once", func(t *testing.T) {
w, o, c := setup()
w.WaitHeld("mesh-wants", heldWait("web", c.t.Add(-2*time.Hour), nil))
if _, ok := o.findings[key]; !ok {
t.Fatalf("a late wait: %v", o.findings)
}
})
// The grants part's wait is held as a seat's event too (design 47 G §269, G-20 A-12): its body names no node, and its release
// is said `wait-ended` with how `released`, which clears the finding.
t.Run("the seat mesh-grants' granting wait is late by its bound and ended by its release", func(t *testing.T) {
w, o, c := setup()
body := func(how string) []byte {
b, _ := json.Marshal(map[string]any{"step": "grant", "part": "mesh-grants", "version": "fp", "module": "web", "bound": "10m0s",
"since": c.t, "clock-from": c.t, "how": how})
return b
}
gid := "mesh-grants-grant-mesh-grants--web"
w.WaitHeld("mesh-grants", body(""))
expire(w, c, signalKey(actingRow, gid), 10*time.Minute)
if _, ok := o.findings[FindingKey(ScopeDelivery, gid, KindActingPartLate)]; !ok {
t.Fatalf("past its bound: %v", o.findings)
}
w.WaitEnded("mesh-grants", body("released"))
if len(o.findings) != 0 {
t.Fatalf("the release left %v", o.findings)
}
})
}
// design 47 G §498 (WM14): a put's wait (`step: put`, no part) raises `put-stands` once its bound has run, and a pipeline's wait
// raises nothing for it; `wait-ended` ends it.
func TestAPutWithoutHoldThatStandsIsPutStands(t *testing.T) {
put := func(since time.Time) []byte {
b, _ := json.Marshal(meshwants.Wait{Step: meshwants.WaitStepPut, Node: "ace", Module: "web", Fingerprint: "fp-1", Since: since, Bound: "30m"})
return b
}
id := "mesh-wants-put--ace-web"
w, o, c := setup()
w.WaitHeld("mesh-wants", put(c.t))
if len(o.findings) != 0 {
t.Fatalf("within the bound: %v", o.findings)
}
expire(w, c, signalKey(actingRow, id), 30*time.Minute)
if _, ok := o.findings[FindingKey(ScopeDelivery, id, KindPutStands)]; !ok || len(o.findings) != 1 {
t.Fatalf("past its bound: %v", o.findings)
}
w.WaitEnded("mesh-wants", put(c.t))
if len(o.findings) != 0 {
t.Fatalf("wait-ended left %v", o.findings)
}
}
// design 47 G §499, §541 (WM4, WM5): a node-engine's hold of the composition standing 30 minutes is `delivery-waits` naming the node,
// the module and the reason, a wait for a kept build standing 60 minutes is `kept-build-waits`, and `wait-ended` clears either.
func TestANodeEnginesWaitIsAFindingPastItsBound(t *testing.T) {
held := func(step, reason string, since time.Time) []byte {
b, _ := json.Marshal(nodeengine.Wait{Step: step, Reason: reason, Node: "build1", Since: since, Owner: "node-engine"})
return b
}
for _, tc := range []struct {
name, step, reason, kind string
bound time.Duration
}{
{"a hold of the composition", nodeengine.WaitStepCompose, "restore point missing", KindDeliveryWaits, 30 * time.Minute},
{"a wait for a kept build", nodeengine.WaitStepKeptBuild, "node away", KindKeptBuildWaits, 60 * time.Minute},
} {
t.Run(tc.name, func(t *testing.T) {
w, o, c := setup()
id := "ace.web"
w.EngineWaitHeld("ace", "web", held(tc.step, tc.reason, c.t))
if o.ttls[signalKey(engineRow, id)] != tc.bound || len(o.findings) != 0 {
t.Fatalf("within the bound: ttl %v, findings %v", o.ttls[signalKey(engineRow, id)], o.findings)
}
expire(w, c, signalKey(engineRow, id), tc.bound)
f, ok := o.findings[FindingKey(ScopeDelivery, id, tc.kind)]
if !ok || len(o.findings) != 1 || !strings.Contains(f.Summary, tc.reason) {
t.Fatalf("past its bound: %v", o.findings)
}
w.EngineWaitEnded("ace", "web")
if len(o.findings) != 0 {
t.Fatalf("wait-ended left %v", o.findings)
}
})
}
}
// design 47 G A-192 (WM13): a key queued behind a package is a wait the builder says on its own stream with the package as its part;
// past its bound it is `acting-part-late`, `wait-ended` clears it, and a toolchain wait (no part) is left to the builder.
func TestAKeyQueuedBehindAPackageIsAnActingPartsWait(t *testing.T) {
body := func(part string, since time.Time) []byte {
b, _ := json.Marshal(meshwants.Wait{Step: "building", Part: part, On: "package:" + part, Module: "web", Fingerprint: "src2:f", Since: since, Bound: "1h0m0s"})
return b
}
const holder = "builder"
w, o, c := setup()
id := waitID(holder, meshwants.Wait{Step: "building", Part: "mesh-sdk@v0.1.14", Module: "web"})
w.ModuleWaitHeld(holder, body("mesh-sdk@v0.1.14", c.t))
if o.ttls[signalKey(actingRow, id)] != time.Hour || len(o.findings) != 0 {
t.Fatalf("within the bound: ttl %v, findings %v", o.ttls[signalKey(actingRow, id)], o.findings)
}
expire(w, c, signalKey(actingRow, id), time.Hour)
if _, ok := o.findings[FindingKey(ScopeDelivery, id, KindActingPartLate)]; !ok || len(o.findings) != 1 {
t.Fatalf("past its bound: %v", o.findings)
}
w.ModuleWaitEnded(holder, body("mesh-sdk@v0.1.14", c.t))
if len(o.findings) != 0 {
t.Fatalf("wait-ended left %v", o.findings)
}
w, o, c = setup()
w.ModuleWaitHeld(holder, body("", c.t.Add(-2*time.Hour)))
if len(o.findings) != 0 || len(o.ttls) != 0 {
t.Fatalf("a toolchain wait was timed by the watchman: %v %v", o.ttls, o.findings)
}
}