node-tools: every wait on the bus in a test waits the shared bound, not a few seconds (issue 1754)

TestAStaleWriteIsRefusedAndWritesNothing gave the watch 5 s to hear a 1 s
key's expire and failed main.505's integration step on a loaded build node;
TestARunnerAtItsStopAnswersNoCallAndItsCallersMeetNoResponders failed its
rerun while it asked 1 s of two round trips and 5 s and 10 s of its waits.
The second of a kind after 3850eb8, so the kind is fixed: meshtest.Bound
(30 s, Until's bound, named once) is what every node-tools test that starts
a bus waits for what the bus carries; Until becomes a deadline of it, so a
try that waits does not multiply it; an upper bound on how long a call or a
wait took is half the bound it tells apart (bus.RequestTimeout, the call's
or the wait's own), at most meshtest.Bound. A wait that hears ends then: no
passing test is longer (per-test durations before and after, equal).

A guard (meshtest waits_test.go) reads every test file that imports
meshtest and refuses a wait whose constant bound is a second or more under
meshtest.Bound; it names 34 such waits at 309069de.

Builds: issue 1754 note 8 (the quick fix), note 9 (1754/AC1 to AC4); principle 11
This commit is contained in:
2026-11-23 19:21:28 +01:00
parent 309069dec1
commit 6a1b4817f8
23 changed files with 309 additions and 72 deletions
+1 -1
View File
@@ -210,7 +210,7 @@ func TestTheMeshsToolsAreFoundByAddress(t *testing.T) {
}
defer stopLate()
var found string
for i := 0; i < 30; i++ {
for deadline := time.Now().Add(mt.Bound); time.Now().Before(deadline); {
found, _ = call(t, endpoint, "mesh_search", map[string]any{"query": "gamma given"})
if strings.Contains(found, "desk/gamma.given") {
break
+14 -18
View File
@@ -124,14 +124,14 @@ func TestMeshWaitAnswersTheFirstMatchingEvent(t *testing.T) {
var got answer
select {
case got = <-done:
case <-time.After(10 * time.Second):
case <-time.After(mt.Bound):
t.Fatal("mesh_wait did not answer the matching event")
}
if got.isErr {
t.Fatalf("mesh_wait failed: %s", got.text)
}
if got.at.Sub(published) > time.Second {
t.Errorf("answered %s after the event was published, want within a second", got.at.Sub(published))
if got.at.Sub(published) > 10*time.Second { // 1754/AC4: half its timeout of 20 s, on the event and not at its timeout
t.Errorf("answered %s after the event was published, want on the event, not at its timeout", got.at.Sub(published))
}
var heard heardAnswer
if err := json.Unmarshal([]byte(got.text), &heard); err != nil {
@@ -161,7 +161,7 @@ func TestMeshWaitAnswersTheFirstMatchingEvent(t *testing.T) {
h.Published != nil || !strings.Contains(heard.Read, "claude_code_answer") {
t.Errorf("the asker's decided: %s", got.text)
}
case <-time.After(10 * time.Second):
case <-time.After(mt.Bound):
t.Fatal("mesh_wait did not answer the asker's decided")
}
}
@@ -172,7 +172,7 @@ func TestMeshWaitSaysItTimedOutAndKeepsNothing(t *testing.T) {
before := s.conn.Subscriptions()
start := time.Now()
text, isErr := callWait(s, map[string]any{"subjects": []any{"mesh-knowledge.reviewed"}, "timeout": 1})
if took := time.Since(start); took < time.Second || took > 3*time.Second {
if took := time.Since(start); took < time.Second || took > mt.Bound { // 1754/AC4: at its timeout, not WaitDefault's
t.Errorf("a one-second wait took %s", took)
}
// Before the catalog half is read, names are not checked, and the answer says so (design 34 every-event §14).
@@ -219,13 +219,13 @@ func TestMeshWaitRefusesLoudlyAndNeverLoops(t *testing.T) {
{map[string]any{"subjects": []any{}}, "at least one event"},
{map[string]any{"subjects": []any{"mesh-knowledge.reviewed"}, "from": "bench"}, "seat, module or stream"},
} {
c.args["timeout"] = 1
c.args["timeout"] = 2 * int(mt.Bound/time.Second)
start := time.Now()
text, isErr := callWait(s, c.args)
if !isErr || !strings.Contains(text, c.says) || strings.Contains(text, "manifest") {
t.Errorf("%v: %s, want refused saying %q", c.args, text, c.says)
}
if took := time.Since(start); took > 500*time.Millisecond {
if took := time.Since(start); took > mt.Bound { // 1754/AC4: half the wait's timeout, refused before any wait
t.Errorf("%v was refused after %s, want at once", c.args, took)
}
}
@@ -268,7 +268,7 @@ func TestMeshWaitRefusesLoudlyAndNeverLoops(t *testing.T) {
t.Fatal(err)
}
go b.Start()
if !b.ReadyForConnections(10 * time.Second) {
if !b.ReadyForConnections(mt.Bound) {
t.Fatal("the bus did not come up")
}
t.Cleanup(b.Shutdown)
@@ -280,7 +280,7 @@ func TestMeshWaitRefusesLoudlyAndNeverLoops(t *testing.T) {
t.Cleanup(conn.Close)
start := time.Now()
text, isErr := callWait(NewSurface(conn, nil, "desk.node-tools"), map[string]any{"subjects": []any{"mesh-delivery-view.delivered"}, "timeout": 1})
if took := time.Since(start); took < time.Second || took > 3*time.Second {
if took := time.Since(start); took < time.Second || took > mt.Bound { // 1754/AC4: at its timeout, never at once
t.Errorf("a wait the bus refused whole answered after %s, want its timeout of 1s", took)
}
if !isErr || !strings.Contains(text, "the bus refused this account a subscription on mesh.seat.mesh-delivery-view.event.delivered") ||
@@ -369,7 +369,7 @@ func markedWaitsOnAWarrant(t *testing.T, s *Surface, mesh *mt.Mesh) {
if !strings.Contains(got, "make this wait again within 30 minutes") {
t.Errorf("a long wait chosen while it waits: %s", got)
}
case <-time.After(10 * time.Second):
case <-time.After(mt.Bound):
t.Fatal("a long marked wait was not answered at the choice")
}
before := g.conn.Subscriptions()
@@ -646,8 +646,8 @@ func TestMeshWaitEndsWhenItsClientHangsUp(t *testing.T) {
cancel()
start := time.Now()
for s.conn.Subscriptions() > before {
if time.Since(start) > 3*time.Second {
t.Fatalf("%d subscriptions 3s after the client hung up, %d before the wait", s.conn.Subscriptions(), before)
if time.Since(start) > mt.Bound {
t.Fatalf("%d subscriptions %s after the client hung up, %d before the wait", s.conn.Subscriptions(), mt.Bound, before)
}
time.Sleep(20 * time.Millisecond)
}
@@ -672,16 +672,12 @@ func TestMeshWaitEndsWhenTheConsoleCloses(t *testing.T) {
return nil
})
closed := make(chan error, 1)
start := time.Now()
go func() { closed <- up.Close() }()
select {
select { // 1754/AC4: within meshtest.Bound, not at the wait's timeout of 600 s
case <-closed:
case <-time.After(5 * time.Second):
case <-time.After(mt.Bound):
t.Fatal("closing the console waited on a mesh_wait in flight")
}
if took := time.Since(start); took > 3*time.Second {
t.Errorf("closing took %s", took)
}
mt.Until(t, func() error {
if s.conn.Subscriptions() > before {
return os.ErrExist