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
+9 -9
View File
@@ -35,7 +35,7 @@ func grantedBus(t *testing.T, publish map[string][]string) string {
t.Fatal(err)
}
go s.Start()
if !s.ReadyForConnections(mt.Bound) {
if !s.ReadyForConnections(mt.Bound(t)) {
t.Fatal("the bus did not come up")
}
t.Cleanup(s.Shutdown)
@@ -173,7 +173,7 @@ func TestAGrantedCallerIsHeardAsItselfAndCannotNameAnother(t *testing.T) {
if !errors.Is(err, nats.ErrPermissionViolation) {
t.Errorf("the bus said %v, want a permissions violation", err)
}
case <-time.After(mt.Bound):
case <-time.After(mt.Bound(t)):
t.Error("the bus did not refuse a call naming another caller")
}
if got := h.all(); len(got) != 1 || got[0] != "shanks.node-tools" {
@@ -249,7 +249,7 @@ func TestACallWaitsTheBoundItsVerbNamesAndTimesOutThere(t *testing.T) {
// caller meets no responders at once; the call in flight at the stop is still answered; a subject served once the stop began
// is not subscribed, and says so.
// 1754/AC3: its order is held (StopAnswering returns once the bus holds the unsubscriptions), so it needs no clock of its
// own: each call and the held call's arrival wait meshtest.Bound, and "at once" is the bus's word, no responders, where a
// own: each call and the held call's arrival wait meshtest.Bound(t), and "at once" is the bus's word, no responders, where a
// subscription left behind would end the call at its bound in a timeout. It failed on a loaded build node (main.505)
// while it asked 1 s of two round trips and 5 s and 10 s of its waits.
func TestARunnerAtItsStopAnswersNoCallAndItsCallersMeetNoResponders(t *testing.T) {
@@ -271,18 +271,18 @@ func TestARunnerAtItsStopAnswersNoCallAndItsCallersMeetNoResponders(t *testing.T
asker := dial(t, url, "node-tools", "shanks", "shanks.node-tools")
held := make(chan error, 1)
go func() {
_, err := asker.AskWithin("ledger.who", map[string]any{"held": true}, "", mt.Bound)
_, err := asker.AskWithin("ledger.who", map[string]any{"held": true}, "", mt.Bound(t))
held <- err
}()
select {
case <-began:
case <-time.After(mt.Bound):
case <-time.After(mt.Bound(t)):
t.Fatal("the call to hold never reached the runner")
}
server.StopAnswering()
at := time.Now()
answered, err := asker.AskWithin("ledger.who", map[string]any{}, "", mt.Bound)
if took := time.Since(at); !errors.Is(err, bus.ErrNoResponders) || took > mt.Bound/2 {
at, within := time.Now(), mt.Bound(t)
answered, err := asker.AskWithin("ledger.who", map[string]any{}, "", within)
if took := time.Since(at); !errors.Is(err, bus.ErrNoResponders) || took > within/2 {
t.Errorf("a call after the stop began was answered %s, %v in %s; want no responders at once", answered.Result, err, took)
}
if _, err := server.HandleSubjectCalled("mesh.mod.ledger.tool.late", func(string, string, json.RawMessage) (any, error) {
@@ -304,7 +304,7 @@ func TestARunnerAtItsStopAnswersNoCallAndItsCallersMeetNoResponders(t *testing.T
}); err == nil {
t.Error("a serve that raced the stop was kept, want it refused")
}
if answered, err := asker.AskWithin("ledger.raced", map[string]any{}, "", mt.Bound); !errors.Is(err, bus.ErrNoResponders) {
if answered, err := asker.AskWithin("ledger.raced", map[string]any{}, "", mt.Bound(t)); !errors.Is(err, bus.ErrNoResponders) {
t.Errorf("a call of a tool whose serve raced the stop was answered %s, %v; want no responders", answered.Result, err)
}
}
+1 -1
View File
@@ -137,7 +137,7 @@ func TestAConsumerSaysItIsBoundWhileIdleAndOnceWhenTheBusEndedIt(t *testing.T) {
for n := 0; n < 3; n++ { // three more intervals pass, counted by the loop's own tick
select {
case <-ticks:
case <-time.After(mt.Bound):
case <-time.After(mt.Bound(t)):
t.Fatal("the heartbeat loop handled no more intervals")
}
}
+2 -2
View File
@@ -145,7 +145,7 @@ func TestTheHolderTakesItsWorkOnceAndAFailureComesBack(t *testing.T) {
t.Fatal(err)
}
defer stop()
deadline := time.Now().Add(mt.Bound)
deadline := time.Now().Add(mt.Bound(t))
for {
mu.Lock()
n := len(got)
@@ -212,7 +212,7 @@ func TestAProofIsAskedAndAnsweredAndNeverKept(t *testing.T) {
t.Fatal(err)
}
}
if first, err := replies.NextMsg(mt.Bound); err != nil || string(first.Data) != `{"linked":true}` {
if first, err := replies.NextMsg(mt.Bound(t)); err != nil || string(first.Data) != `{"linked":true}` {
t.Fatalf("a proof cut at the stop was answered, or the whole one not: %v %v", first, err)
}
if _, err := conn.SeatProve("telegram", "mesh.seat.intake.proof.code.desktop", json.RawMessage(`{}`)); err == nil {
@@ -117,7 +117,7 @@ func TestAPerNodeStateIsServedAcrossEveryNodesBucket(t *testing.T) {
}
return nil
}
bound := time.After(mt.Bound)
bound := time.After(mt.Bound(t))
for err := missing(); err != nil; err = missing() {
select {
case <-heard:
+2 -2
View File
@@ -140,7 +140,7 @@ func TestAWatchHoldsWhileItsCurrentValuesKeepArriving(t *testing.T) {
}
select {
case <-first:
case <-time.After(mt.Bound):
case <-time.After(mt.Bound(t)):
t.Fatal("the bundle was handed no change")
}
stop()
@@ -180,7 +180,7 @@ func TestAWatchIsRefusedWhenNoCurrentValueIsTakenWithinTheBound(t *testing.T) {
if err == nil || !strings.Contains(err.Error(), "did not arrive in") {
t.Fatalf("a watch whose first value was never taken: want refused, got %v", err)
}
if took := time.Since(began); took > mt.Bound { // 1754/AC4: refused at its bound, never waited on for ever
if took := time.Since(began); took > was/2 { // 1754/AC4: at the bound it was set, half the default StateTimeout it replaced
t.Fatalf("the refusal took %s, far past the bound", took)
}
}
+1 -1
View File
@@ -63,7 +63,7 @@ func TestAnEventADeclaredStreamCarriesIsPublishedOnItsSubjectAlone(t *testing.T)
if got != "mesh.stream.mail.event.mail.home.message.added" {
t.Errorf("published on %s", got)
}
case <-time.After(mt.Bound):
case <-time.After(mt.Bound(t)):
t.Fatal("the event did not land on its stream's subject")
}
if err := conn.PublishAs("mail", bus.Envelope{Key: "status", Body: json.RawMessage(`{}`)}); err != nil {
+7 -6
View File
@@ -29,7 +29,7 @@ func TestTheBusRefusesAWaitOutsideTheGrant(t *testing.T) {
t.Fatal(err)
}
go s.Start()
if !s.ReadyForConnections(mt.Bound) {
if !s.ReadyForConnections(mt.Bound(t)) {
t.Fatal("the bus did not come up")
}
t.Cleanup(s.Shutdown)
@@ -38,7 +38,8 @@ func TestTheBusRefusesAWaitOutsideTheGrant(t *testing.T) {
// Every subscription refused: answered after the timeout, never at once, in §16's words.
start := time.Now()
_, ok, refused, err := c.HearFirst(context.Background(), []string{other}, 300*time.Millisecond, nil)
if took := time.Since(start); took < 300*time.Millisecond || took > mt.Bound { // 1754/AC4: after its timeout, never at once
// 1754/AC4: after its timeout, never at once; a wait that never ended would meet the test's own deadline
if took := time.Since(start); took < 300*time.Millisecond {
t.Errorf("a wait refused whole answered after %s, want its timeout of 300ms", took)
}
if ok || err == nil || !strings.Contains(err.Error(), "the bus refused this account a subscription on "+other) ||
@@ -62,7 +63,7 @@ func TestTheBusRefusesAWaitOutsideTheGrant(t *testing.T) {
}
done := make(chan result, 1)
go func() {
h, ok, refused, err := c.HearFirst(context.Background(), []string{other, granted}, mt.Bound, nil)
h, ok, refused, err := c.HearFirst(context.Background(), []string{other, granted}, mt.Bound(t), nil)
if !ok && err == nil {
err = errors.New("timed out")
}
@@ -103,12 +104,12 @@ func TestAWaitEndsWhenItsCallerIsGone(t *testing.T) {
before := c.Subscriptions()
ctx, cancel := context.WithCancel(context.Background())
time.AfterFunc(200*time.Millisecond, cancel)
start := time.Now()
_, ok, _, err := c.HearFirst(ctx, []string{"mesh.mod.mesh-knowledge.event.reviewed"}, time.Minute, nil)
start, within := time.Now(), mt.Bound(t)
_, ok, _, err := c.HearFirst(ctx, []string{"mesh.mod.mesh-knowledge.event.reviewed"}, within, nil)
if ok || !errors.Is(err, context.Canceled) {
t.Errorf("a cancelled wait answered %v, %v", ok, err)
}
if took := time.Since(start); took > mt.Bound { // 1754/AC4: at the cancel, not at its timeout of a minute
if took := time.Since(start); took > within/2 { // 1754/AC4: at the cancel, not at its own timeout
t.Errorf("a cancelled wait ended after %s", took)
}
if after := c.Subscriptions(); after != before {