Files
mesh-catalog/modules/mesh-config/cmd/mesh-config/quiet_integration_test.go
T
jschoubben 7ade318cfa mesh-config: one deadline timer for the earliest real deadline, its floor a setting (issue 1982; ADR 0681 §1; A-490l)
The one timer left is set for the earliest of three deadlines: a waiting proposal's end, an unanswered retirement's second
ask, and a rename window's seven-day held finding, which is now judged at its deadline (JudgeHeldWindows) so it comes in a
quiet mesh too. Its floor is the module's setting deadline-floor-seconds (default 60), not a constant.

Tests: an integration test counts asks by key and fails on any `seat:git.*` over the whole run (ADR 0681, How it is checked,
clause 1); a unit test shows an approved proposal records a hand act naming no pull request; another that a stored proposal
naming a pull request is refused on approval, saying why.

Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
2026-11-19 23:08:09 +01:00

135 lines
5.2 KiB
Go

//go:build integration
package main
// Issue 1982, against a real bus: mesh-config whole asks the bus for nothing while no input of it changes, and a changed input
// resolves only what it touches. The binary runs as the node's tool runtime plays it (whole_integration_test.go), and every
// request it makes of the runtime is counted: what a state read, a watch and a write ask of the bus.
import (
"context"
"os"
"os/exec"
"path/filepath"
"slices"
"strings"
"testing"
"github.com/nats-io/nats.go"
"github.com/nats-io/nats.go/jetstream"
"git.novox.be/novox/mesh-sdk/go/testbus"
)
func (p *player) snapshot() (calls map[string]int, puts []string) {
p.mu.Lock()
defer p.mu.Unlock()
calls = map[string]int{}
for k, v := range p.calls {
calls[k] = v
}
return calls, slices.Clone(p.puts)
}
// asked is how many requests of these methods the module made between two snapshots.
func asked(before, after map[string]int, methods ...string) int {
n := 0
for _, m := range methods {
n += after[m] - before[m]
}
return n
}
func TestConfigWholeAsksTheBusForNothingWhileNoInputChanges(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)
bin := filepath.Join(t.TempDir(), Module)
build := exec.Command("go", "build", "-o", bin, ".")
build.Stderr = os.Stderr
if err := build.Run(); err != nil {
t.Fatalf("mesh-config does not build: %v", err)
}
nc, err := nats.Connect(testbus.URL(t))
if err != nil {
t.Fatal(err)
}
t.Cleanup(nc.Close)
js, err := jetstream.New(nc)
if err != nil {
t.Fatal(err)
}
buckets := []string{"mesh-delivery-assigner_assignments", "mesh-delivery-assigner_wants", "mesh-delivery-indexer_predefined"}
for _, s := range []string{ValuesState, ResolvedState, PredefinedState, ProposalsState, DeclaredState,
RenamesState, RetiringState, FindingsState} {
buckets = append(buckets, Module+"_"+s)
}
for _, b := range buckets {
if _, err := js.CreateKeyValue(ctx, jetstream.KeyValueConfig{Bucket: b, History: 2}); err != nil {
t.Fatal(err)
}
}
haves := map[string]string{"g14.player": fpOf("player", fp1), "novox.player": fpOf("player", fp1), "g14.radio": fpOf("radio", fp1)}
p := start(t, bin, js, newStandIn(), haves, nil)
p.viewsReady()
const radio = `{"module":"radio","config":{"band":{"type":"number","default":1}}}`
p.manifestIn("player", oldPlayer)
p.manifestIn("radio", radio)
p.buildIn("g14", "player", fpOf("player", fp1), oldPlayer)
p.buildIn("novox", "player", fpOf("player", fp1), oldPlayer)
p.buildIn("g14", "radio", fpOf("radio", fp1), radio)
p.placed("g14", "player", "radio")
p.placed("novox", "player")
p.hearsTheViews()
eventually(t, "every value is resolved", func() bool {
a, okA := resolvedValue(p, "g14", "player", "volume")
b, okB := resolvedValue(p, "novox", "player", "volume")
c, okC := resolvedValue(p, "g14", "radio", "band")
return okA && okB && okC && a == "5" && b == "5" && c == "1"
})
// The passes the setup moved have ended when the module answers a tool: it takes its lock for none.
if _, err := p.call(ResyncTool, nil); err != nil {
t.Fatal(err)
}
// No input changes: the delivery says it delivered and a node-engine says what it reads, with no rename window open and no retirement
// waiting. Each is heard and none is a pass: nothing is asked of the bus. (The module has no polling timer; its one deadline
// timer is set for a real deadline, and none is near.)
before, putsBefore := p.snapshot()
for i := 0; i < 20; i++ {
p.event("mesh-delivery-view.delivered", map[string]any{"revision": "r"})
p.event("node-engine.manifest-reads-changed", map[string]any{"node": "g14"})
}
after, putsAfter := p.snapshot()
p.noGitAsk()
if n := asked(before, after, "mesh/state.get", "mesh/state.keys", "mesh/state.watch", "mesh/state.put", "mesh/state.create",
"mesh/state.update", "mesh/state.delete", "mesh/ask"); n != 0 || len(putsAfter) != len(putsBefore) {
t.Errorf("40 events that move nothing asked %d requests of the bus (%v); wrote %v", n, after, putsAfter[len(putsBefore):])
}
// One input changes: player's manifest declares a second value. Only player's values on its two nodes are written, and `declared`
// for player; radio's resolved values are not written again, and nothing is read key by key.
before, putsBefore = p.snapshot()
const gain = `{"module":"player","config":{"volume":{"type":"number","default":5},"gain":{"type":"number","default":2}}}`
p.manifestIn("player", gain)
eventually(t, "the new value is resolved on both nodes", func() bool {
a, okA := resolvedValue(p, "g14", "player", "gain")
b, okB := resolvedValue(p, "novox", "player", "gain")
return okA && okB && a == "2" && b == "2"
})
after, putsAfter = p.snapshot()
var wrote []string
for _, w := range putsAfter[len(putsBefore):] {
wrote = append(wrote, strings.TrimPrefix(w, "mesh/state."))
}
for _, w := range wrote {
if !strings.Contains(w, ResolvedState+"/g14.player.") && !strings.Contains(w, ResolvedState+"/novox.player.") &&
!strings.Contains(w, DeclaredState+"/player") {
t.Errorf("a changed manifest of player wrote %q, which is not player's", w)
}
}
if n := asked(before, after, "mesh/state.get", "mesh/state.keys", "mesh/state.watch"); n != 0 {
t.Errorf("a changed manifest read %d keys of the bus's states one by one (%v)", n, after)
}
}