node-tools: a test's wait on the bus takes the test's own deadline (issue 1754, review round 1)

The lead's answer on issue 1754 (note of 2026-11-23 20:00, principles 11
and 7): no bound written into the code. meshtest.Bound(t) is t.Deadline()
less 30 s for the test's cleanup, go test's default of 10 min where a run
names no deadline, and what is left, at least 1 ms, once less than the
margin is (the lead's round-2 answer, note 11; principles 3 and 7). Until
stops at it; callWithin is gone, call() takes it. The guard now refuses
any constant bound of a second or more.

Each upper limit is half the bound it tells apart: the watch's refusal is
held to half the default StateTimeout the test replaced (a watch timer
fixed at 10 s failed it in 10.0 s, round 1 passed it); the console's close
to half its backstop ShutdownWithin (a Close that never cancels failed it
in 5.1 s, round 1 passed it); the console waits to half WaitDefault.

Builds: issue 1754 notes 10 (lead answer, 20:00) and 11 (round 2: margin, AC1, AC4); principles 3, 7 and 11
This commit is contained in:
2026-11-23 20:11:13 +01:00
parent 6a1b4817f8
commit 56d20314ba
23 changed files with 143 additions and 90 deletions
+19 -16
View File
@@ -124,7 +124,7 @@ func TestMeshWaitAnswersTheFirstMatchingEvent(t *testing.T) {
var got answer
select {
case got = <-done:
case <-time.After(mt.Bound):
case <-time.After(mt.Bound(t)):
t.Fatal("mesh_wait did not answer the matching event")
}
if got.isErr {
@@ -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(mt.Bound):
case <-time.After(mt.Bound(t)):
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 > mt.Bound { // 1754/AC4: at its timeout, not WaitDefault's
if took := time.Since(start); took < time.Second || took > WaitDefault/2 { // 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,12 @@ 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"] = 2 * int(mt.Bound/time.Second)
start := time.Now()
start := time.Now() // no timeout: the wait's would be WaitDefault
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 > mt.Bound { // 1754/AC4: half the wait's timeout, refused before any wait
if took := time.Since(start); took > WaitDefault/2 { // 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 +267,7 @@ func TestMeshWaitRefusesLoudlyAndNeverLoops(t *testing.T) {
t.Fatal(err)
}
go b.Start()
if !b.ReadyForConnections(mt.Bound) {
if !b.ReadyForConnections(mt.Bound(t)) {
t.Fatal("the bus did not come up")
}
t.Cleanup(b.Shutdown)
@@ -280,7 +279,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 > mt.Bound { // 1754/AC4: at its timeout, never at once
if took := time.Since(start); took < time.Second || took > WaitDefault/2 { // 1754/AC4: at its timeout, not WaitDefault's
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 +368,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(mt.Bound):
case <-time.After(mt.Bound(t)):
t.Fatal("a long marked wait was not answered at the choice")
}
before := g.conn.Subscriptions()
@@ -644,12 +643,10 @@ func TestMeshWaitEndsWhenItsClientHangsUp(t *testing.T) {
return nil
})
cancel()
start := time.Now()
for 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)
for deadline := time.Now().Add(mt.Bound(t)); s.conn.Subscriptions() > before; time.Sleep(20 * time.Millisecond) {
if time.Now().After(deadline) {
t.Fatalf("%d subscriptions at the test's bound after the client hung up, %d before the wait", s.conn.Subscriptions(), before)
}
time.Sleep(20 * time.Millisecond)
}
}
@@ -672,12 +669,18 @@ func TestMeshWaitEndsWhenTheConsoleCloses(t *testing.T) {
return nil
})
closed := make(chan error, 1)
start := time.Now()
go func() { closed <- up.Close() }()
select { // 1754/AC4: within meshtest.Bound, not at the wait's timeout of 600 s
select {
case <-closed:
case <-time.After(mt.Bound):
case <-time.After(mt.Bound(t)):
t.Fatal("closing the console waited on a mesh_wait in flight")
}
// 1754/AC4: half the bound it tells apart, the console's own backstop ShutdownWithin, which ends a close whose waits
// were never cancelled
if took := time.Since(start); took > ShutdownWithin/2 {
t.Errorf("closing took %s, want the waits cancelled at once, not ended by the backstop of %s", took, ShutdownWithin)
}
mt.Until(t, func() error {
if s.conn.Subscriptions() > before {
return os.ErrExist