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:
@@ -138,8 +138,8 @@ func TestTheToolRunnerStartedByItsEntryServesABundleOverTheSeatListItReads(t *te
|
||||
if err != nil {
|
||||
t.Errorf("serve ended with %v", err)
|
||||
}
|
||||
case <-time.After(mt.Bound):
|
||||
t.Errorf("the tool runner did not stop within %s", mt.Bound)
|
||||
case <-time.After(mt.Bound(t)):
|
||||
t.Errorf("the tool runner did not stop within %s", mt.Bound(t))
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -199,7 +199,7 @@ func TestTheToolRunnerStartedByItsEntryServesABundleOverTheSeatListItReads(t *te
|
||||
}
|
||||
readPage := func(cursor string) paged {
|
||||
t.Helper()
|
||||
answered, err := asker.AskWithin("ledger.page", map[string]any{"cursor": cursor}, "", mt.Bound)
|
||||
answered, err := asker.AskWithin("ledger.page", map[string]any{"cursor": cursor}, "", mt.Bound(t))
|
||||
var p paged
|
||||
if err != nil || json.Unmarshal(answered.Result, &p) != nil || p.Error != nil {
|
||||
t.Fatalf("the page after %q was answered %.300s, %v", cursor, answered.Result, err)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -210,7 +210,7 @@ func TestTheMeshsToolsAreFoundByAddress(t *testing.T) {
|
||||
}
|
||||
defer stopLate()
|
||||
var found string
|
||||
for deadline := time.Now().Add(mt.Bound); time.Now().Before(deadline); {
|
||||
for deadline := time.Now().Add(mt.Bound(t)); time.Now().Before(deadline); {
|
||||
found, _ = call(t, endpoint, "mesh_search", map[string]any{"query": "gamma given"})
|
||||
if strings.Contains(found, "desk/gamma.given") {
|
||||
break
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -57,9 +57,9 @@ func URL(t *testing.T) string {
|
||||
t.Fatalf("a bus for this test could not be made: %v", err)
|
||||
}
|
||||
go s.Start()
|
||||
if !s.ReadyForConnections(Bound) {
|
||||
if !s.ReadyForConnections(Bound(t)) {
|
||||
s.Shutdown()
|
||||
t.Fatalf("a bus for this test did not come up within %s", Bound)
|
||||
t.Fatal("a bus for this test did not come up within its bound")
|
||||
}
|
||||
url := s.ClientURL()
|
||||
buses.Store(t, url)
|
||||
@@ -260,20 +260,46 @@ func Fixture(name string) string {
|
||||
return filepath.Join(filepath.Dir(here), "..", "..", "test", "fixtures", name)
|
||||
}
|
||||
|
||||
// Bound is how long a test waits for what the bus is to carry (an event, an answer, a watch's change, a key's expiry, a
|
||||
// bus coming up) before it fails: 30 s, which a loaded build node stays within, where a few seconds did not (issue 1754:
|
||||
// a 1 s key's expire not heard in 5 s on a loaded build node; fix-a-bug-met-twice). It only ends a wait that never hears
|
||||
// what it waits for: a wait that hears ends then, so a passing test is no longer for it. One bound for every such wait,
|
||||
// well under the integration step's own 30 minutes (principle 11), never a few seconds written into a test (1754/AC1).
|
||||
const Bound = 30 * time.Second
|
||||
// Bound is how long, from now, a test waits for what the bus is to carry (an event, an answer, a watch's change, a key's
|
||||
// expiry, a bus coming up) before it fails: the test's own deadline, go test's -timeout that the build step sets, less
|
||||
// cleanupMargin for the test's cleanup, never a few seconds written into a test (issue 1754: a 1 s key's expire not heard
|
||||
// in 5 s on a loaded build node; the lead's answers on the issue of 2026-11-23 20:00 and of round 2, principles 11 and 7;
|
||||
// 1754/AC1). It only ends a wait that never hears what it waits for: a wait that hears ends then, so a passing test is no
|
||||
// longer for it. With less than the margin left it answers what is left, at least a millisecond, so a cleanup's wait runs
|
||||
// to the deadline and go test's own timeout names the test (principle 3).
|
||||
func Bound(t *testing.T) time.Duration {
|
||||
deadline, ok := t.Deadline()
|
||||
if !ok {
|
||||
deadline = started.Add(goTestTimeout)
|
||||
}
|
||||
return boundOf(time.Until(deadline))
|
||||
}
|
||||
|
||||
// Until retries while the bus answers "no responders" — something not yet served — until Bound has passed: a deadline, so
|
||||
// a try that itself waits does not multiply it (fix-a-bug-met-twice: a fixed bound a loaded machine overruns, fixed for
|
||||
// every package that waits here).
|
||||
// boundOf is Bound for what is left until the deadline.
|
||||
func boundOf(left time.Duration) time.Duration {
|
||||
if left > cleanupMargin {
|
||||
return left - cleanupMargin
|
||||
}
|
||||
return max(left, time.Millisecond)
|
||||
}
|
||||
|
||||
// cleanupMargin is what Bound leaves of a test's deadline for its cleanup: 30 s, the longest bound these tests used
|
||||
// (Until's), which covers their cleanups (the lead's answer on issue 1754, round 2).
|
||||
const cleanupMargin = 30 * time.Second
|
||||
|
||||
// goTestTimeout is go test's own default -timeout, the deadline of a run that names none, from the run's start.
|
||||
const goTestTimeout = 10 * time.Minute
|
||||
|
||||
// started is when this test binary began.
|
||||
var started = time.Now()
|
||||
|
||||
// Until retries while the bus answers "no responders" — something not yet served — until the test's Bound has passed: a
|
||||
// deadline, so a try that itself waits does not multiply it (fix-a-bug-met-twice: a fixed bound a loaded machine overruns,
|
||||
// fixed for every package that waits here).
|
||||
func Until(t *testing.T, try func() error) {
|
||||
t.Helper()
|
||||
var err error
|
||||
for deadline := time.Now().Add(Bound); ; time.Sleep(100 * time.Millisecond) {
|
||||
for deadline := time.Now().Add(Bound(t)); ; time.Sleep(100 * time.Millisecond) {
|
||||
if err = try(); err == nil {
|
||||
return
|
||||
}
|
||||
@@ -390,7 +416,7 @@ func (m *Mesh) BucketKeyTTL(t *testing.T, name string) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), Bound)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), Bound(t))
|
||||
defer cancel()
|
||||
if _, err := js.CreateKeyValue(ctx, jetstream.KeyValueConfig{Bucket: name, History: 1, MaxValueSize: 256 * 1024,
|
||||
LimitMarkerTTL: time.Minute}); err != nil {
|
||||
|
||||
@@ -13,6 +13,31 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// 1754/AC1: a wait's bound is the test's deadline less the cleanup margin, and what is left once less than the margin is,
|
||||
// never zero or less (the lead's answer on issue 1754, round 2).
|
||||
func TestABoundIsTheTestsDeadlineLessItsCleanupMargin(t *testing.T) {
|
||||
for _, row := range []struct{ left, want time.Duration }{
|
||||
{10 * time.Minute, 10*time.Minute - cleanupMargin},
|
||||
{cleanupMargin + time.Second, time.Second},
|
||||
{cleanupMargin, cleanupMargin},
|
||||
{time.Second, time.Second},
|
||||
{0, time.Millisecond},
|
||||
{-time.Minute, time.Millisecond},
|
||||
} {
|
||||
if got := boundOf(row.left); got != row.want {
|
||||
t.Errorf("with %s left the bound is %s, want %s", row.left, got, row.want)
|
||||
}
|
||||
}
|
||||
deadline, ok := t.Deadline()
|
||||
if !ok {
|
||||
deadline = started.Add(goTestTimeout)
|
||||
}
|
||||
left := time.Until(deadline)
|
||||
if b := Bound(t); b <= 0 || b > left-cleanupMargin {
|
||||
t.Errorf("this test's bound is %s, with %s left until its deadline", b, left)
|
||||
}
|
||||
}
|
||||
|
||||
// waitBound is, for each call that waits, which argument is its bound.
|
||||
var waitBound = map[string]int{
|
||||
"After": 0, "NewTimer": 0, "WithTimeout": 1, "NextMsg": 0, "ReadyForConnections": 0, "Request": 2, "RequestMsg": 1,
|
||||
@@ -20,10 +45,10 @@ var waitBound = map[string]int{
|
||||
}
|
||||
|
||||
// 1754/AC1: no test that starts a bus (a test file importing this package, and this package itself) waits for what the
|
||||
// bus carries with a fixed bound of a second or more under Bound: each such wait names Bound. A few seconds is what a
|
||||
// loaded build node overran (issue 1754: state_counter_test.go's 5 s for a 1 s key's expire, failed on a build node);
|
||||
// a bound under a second is the bound under test or the window an absence is given, and is not this guard's.
|
||||
func TestNoWaitOnTheBusHasAFixedBoundUnderTheSharedOne(t *testing.T) {
|
||||
// bus carries with a fixed bound of a second or more: each such wait takes the test's own deadline, Bound(t). A few
|
||||
// seconds is what a loaded build node overran (issue 1754: state_counter_test.go's 5 s for a 1 s key's expire, failed on
|
||||
// a build node); a bound under a second is the bound under test or the window an absence is given, and is not this guard's.
|
||||
func TestNoWaitOnTheBusHasAFixedBound(t *testing.T) {
|
||||
root := moduleRoot()
|
||||
var found []string
|
||||
err := filepath.WalkDir(root, func(path string, d fs.DirEntry, err error) error {
|
||||
@@ -48,12 +73,12 @@ func TestNoWaitOnTheBusHasAFixedBoundUnderTheSharedOne(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(found) > 0 {
|
||||
t.Errorf("waits on the bus with a fixed bound under meshtest.Bound (%s), which a loaded build node overruns: give each meshtest.Bound\n%s",
|
||||
Bound, strings.Join(found, "\n"))
|
||||
t.Errorf("waits on the bus with a fixed bound, which a loaded build node overruns: give each the test's own, meshtest.Bound(t)\n%s",
|
||||
strings.Join(found, "\n"))
|
||||
}
|
||||
}
|
||||
|
||||
// fixedWaits are the waits of one file that starts a bus whose bound is a constant of a second or more under Bound.
|
||||
// fixedWaits are the waits of one file that starts a bus whose bound is a constant of a second or more.
|
||||
func fixedWaits(t *testing.T, path string, ours bool) []string {
|
||||
t.Helper()
|
||||
fset := token.NewFileSet()
|
||||
@@ -67,7 +92,7 @@ func fixedWaits(t *testing.T, path string, ours bool) []string {
|
||||
consts := packageConsts(t, filepath.Dir(path))
|
||||
var found []string
|
||||
flag := func(what string, bound ast.Expr) {
|
||||
if d, ok := duration(bound, consts); ok && d >= time.Second && d < Bound {
|
||||
if d, ok := duration(bound, consts); ok && d >= time.Second {
|
||||
rel, _ := filepath.Rel(moduleRoot(), fset.Position(bound.Pos()).Filename)
|
||||
found = append(found, rel+":"+strconv.Itoa(fset.Position(bound.Pos()).Line)+": "+what+" "+d.String())
|
||||
}
|
||||
@@ -173,7 +198,7 @@ func packageConsts(t *testing.T, dir string) map[string]ast.Expr {
|
||||
}
|
||||
|
||||
// duration is the value of a constant duration written as the tests write one: a number, time's units, a constant of
|
||||
// the package, and their products and sums. Anything else (a variable, Bound, another package's bound) is not constant.
|
||||
// the package, and their products and sums. Anything else (a variable, Bound(t), another package's bound) is not constant.
|
||||
func duration(e ast.Expr, consts map[string]ast.Expr) (time.Duration, bool) {
|
||||
switch e := e.(type) {
|
||||
case *ast.ParenExpr:
|
||||
@@ -194,7 +219,7 @@ func duration(e ast.Expr, consts map[string]ast.Expr) (time.Duration, bool) {
|
||||
return unit, ok
|
||||
}
|
||||
case *ast.Ident:
|
||||
if v, ok := consts[e.Name]; ok && e.Name != "Bound" {
|
||||
if v, ok := consts[e.Name]; ok {
|
||||
delete(consts, e.Name) // a constant read once, so none refers to itself
|
||||
d, ok := duration(v, consts)
|
||||
consts[e.Name] = v
|
||||
|
||||
@@ -44,7 +44,7 @@ func TestTheRuntimeAnnouncesWhatItServesInTheServicesProtocol(t *testing.T) {
|
||||
defer nc.Close()
|
||||
info := func() micro.Info {
|
||||
t.Helper()
|
||||
msg, err := nc.Request("$SRV.INFO.node-tools.anchor", nil, mt.Bound)
|
||||
msg, err := nc.Request("$SRV.INFO.node-tools.anchor", nil, mt.Bound(t))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -102,13 +102,13 @@ func TestTheRuntimeAnnouncesWhatItServesInTheServicesProtocol(t *testing.T) {
|
||||
}
|
||||
|
||||
// PING answers with the same identity, and a request for another service is not answered.
|
||||
if msg, err := nc.Request("$SRV.PING", nil, mt.Bound); err != nil || !strings.Contains(string(msg.Data), micro.PingResponseType) {
|
||||
if msg, err := nc.Request("$SRV.PING", nil, mt.Bound(t)); err != nil || !strings.Contains(string(msg.Data), micro.PingResponseType) {
|
||||
t.Errorf("ping: %v %v", msg, err)
|
||||
}
|
||||
// alpha is re-issued a plain subject: the announcement says so, and says it is interchangeable.
|
||||
mesh.Issue(t, mt.MembershipOf("alpha", "anchor", true, nil))
|
||||
var after string
|
||||
for deadline := time.Now().Add(mt.Bound); time.Now().Before(deadline); {
|
||||
for deadline := time.Now().Add(mt.Bound(t)); time.Now().Before(deadline); {
|
||||
after = subjects(info())
|
||||
if strings.Contains(after, "mesh.mod.alpha.tool.one|serve.alpha|tool|alpha|||true") {
|
||||
break
|
||||
@@ -139,7 +139,7 @@ func TestTheRunnerStatesTheCapabilitiesOfItsCallsInItsPing(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer nc.Close()
|
||||
msg, err := nc.Request("$SRV.PING.node-tools.anchor", nil, mt.Bound)
|
||||
msg, err := nc.Request("$SRV.PING.node-tools.anchor", nil, mt.Bound(t))
|
||||
if err != nil {
|
||||
t.Fatalf("ping of the instance: %v", err)
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ func TestACallOnTheCallerNamedSubjectReachesTheModuleWithItsCaller(t *testing.T)
|
||||
Result saidCaller `json:"result"`
|
||||
}
|
||||
mt.Until(t, func() error {
|
||||
answer, err := raw.RequestMsg(msg, mt.Bound)
|
||||
answer, err := raw.RequestMsg(msg, mt.Bound(t))
|
||||
if err == nil {
|
||||
err = json.Unmarshal(answer.Data, &reply)
|
||||
}
|
||||
@@ -131,7 +131,7 @@ func TestTheSubjectThatNamesNoCallerStillWorksAndNamesNone(t *testing.T) {
|
||||
Error string `json:"error"`
|
||||
}
|
||||
mt.Until(t, func() error {
|
||||
msg, err := old.Request(subject, body, mt.Bound)
|
||||
msg, err := old.Request(subject, body, mt.Bound(t))
|
||||
if err == nil {
|
||||
err = json.Unmarshal(msg.Data, &reply)
|
||||
}
|
||||
@@ -254,7 +254,7 @@ func TestTheSubjectThatNamesNoCallerStillWorksAndNamesNone(t *testing.T) {
|
||||
for i := 0; i < 3; i++ {
|
||||
go func() { got, err := c.chunkedAsked("seat:mesh-wants.input"); done <- got && err == nil }()
|
||||
}
|
||||
for deadline := time.Now().Add(mt.Bound); c.rereadWaiting() < 2; runtime.Gosched() {
|
||||
for deadline := time.Now().Add(mt.Bound(t)); c.rereadWaiting() < 2; runtime.Gosched() {
|
||||
if time.Now().After(deadline) {
|
||||
t.Fatal("two asks never joined the read running")
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ func TestTheRuntimeHandsAModulesEventsToItsBundleAndAcknowledgesThemOnlyWhenTake
|
||||
// The bundle dies on the first offer: not acknowledged, the bundle is started again and the
|
||||
// event is offered again once its ack wait has passed.
|
||||
mesh.Emit(t, "mesh.mod.alpha.event.happened", map[string]any{"n": 3, "die": true})
|
||||
deadline := time.Now().Add(mt.Bound)
|
||||
deadline := time.Now().Add(mt.Bound(t))
|
||||
for time.Now().Before(deadline) {
|
||||
if countLines(t, log, "handled 2") == 1 && countLines(t, log, "handled 3") == 1 {
|
||||
break
|
||||
|
||||
@@ -41,7 +41,7 @@ func TestALedgerIsWrittenOnlyOnItsModulesLedgerConnection(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)
|
||||
|
||||
@@ -39,7 +39,7 @@ func TestTheLedgerRepairsAreToolsOfEveryLedgerOwner(t *testing.T) {
|
||||
defer stop()
|
||||
asker := connect(t, "console", "workstation")
|
||||
listed := func(module string) (string, error) {
|
||||
answered, err := asker.AskWithin(module+"."+ToolsVerb, map[string]any{}, "", callWithin)
|
||||
answered, err := asker.AskWithin(module+"."+ToolsVerb, map[string]any{}, "", mt.Bound(t))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -75,7 +75,7 @@ func TestTheLedgerRepairsAreToolsOfEveryLedgerOwner(t *testing.T) {
|
||||
plain.Bindings = owner.Bindings
|
||||
}
|
||||
mesh.Issue(t, plain)
|
||||
if _, err := asker.AskWithin("plain.who@anchor", map[string]any{}, "", callWithin); err != nil {
|
||||
if _, err := asker.AskWithin("plain.who@anchor", map[string]any{}, "", mt.Bound(t)); err != nil {
|
||||
t.Fatalf("binding change %d: the first call of plain.who failed: %v — dropped while its tools were served again", round, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -247,7 +247,7 @@ func TestALogAnswersEachVerbOnTheBus(t *testing.T) {
|
||||
if e.Sequence != want || e.Key != "12" {
|
||||
t.Fatalf("the watch handed %d %s, want %d", e.Sequence, e.Key, want)
|
||||
}
|
||||
case <-time.After(mt.Bound):
|
||||
case <-time.After(mt.Bound(t)):
|
||||
t.Fatalf("the watch did not hand entry %d", want)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ func TestABundlesWatchIsHandedTheValueAndEachChange(t *testing.T) {
|
||||
select {
|
||||
case c := <-handed:
|
||||
return c
|
||||
case <-time.After(mt.Bound):
|
||||
case <-time.After(mt.Bound(t)):
|
||||
t.Fatalf("nothing handed: %s", what)
|
||||
}
|
||||
return ProvisionChange{}
|
||||
|
||||
@@ -201,7 +201,7 @@ func announced(t *testing.T) string {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer nc.Close()
|
||||
msg, err := nc.Request("$SRV.INFO.node-tools.anchor", nil, mt.Bound)
|
||||
msg, err := nc.Request("$SRV.INFO.node-tools.anchor", nil, mt.Bound(t))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -26,14 +26,12 @@ func connect(t *testing.T, module, node string) *bus.Conn {
|
||||
return c
|
||||
}
|
||||
|
||||
// callWithin is the tests' own bound on a call (principle 11): the shared meshtest.Bound, which a loaded build node stays
|
||||
// within where 2 s did not (1754/AC1); a call that is never answered fails there, and Until, a deadline of the same bound,
|
||||
// does not try it again past it.
|
||||
const callWithin = mt.Bound
|
||||
|
||||
// call waits the test's own bound, meshtest.Bound(t), where 2 s were what a loaded build node overran (1754/AC1; the lead's
|
||||
// answer on issue 1754 of 2026-11-23 20:00): a call that is never answered fails there, and Until, a deadline of the same
|
||||
// bound, does not try it again past it.
|
||||
func call(t *testing.T, asker *bus.Conn, key string, args any) (string, error) {
|
||||
t.Helper()
|
||||
got, err := asker.AskWithin(key, args, "", callWithin)
|
||||
got, err := asker.AskWithin(key, args, "", mt.Bound(t))
|
||||
return string(got.Result), err
|
||||
}
|
||||
|
||||
@@ -120,7 +118,7 @@ func TestTheNodesRuntimeServesFiveModulesAndFollowsAReissuedMembership(t *testin
|
||||
if subject != "mesh.mod.alpha.event.happened" {
|
||||
t.Errorf("the event landed on %s", subject)
|
||||
}
|
||||
case <-time.After(mt.Bound):
|
||||
case <-time.After(mt.Bound(t)):
|
||||
t.Error("the event never landed")
|
||||
}
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ func TestABundlesSeatTrafficGoesThroughItsModulesBus(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
deadline := time.Now().Add(mt.Bound)
|
||||
deadline := time.Now().Add(mt.Bound(t))
|
||||
for {
|
||||
mu.Lock()
|
||||
n := len(taken)
|
||||
|
||||
@@ -140,8 +140,8 @@ func TestTwoWritersIncrementingOneCounterOnTheBusLoseNoUpdate(t *testing.T) {
|
||||
// revision it read, never zero.
|
||||
// A key's own time to live (issue 1952, mesh-sdk process.State.CreateTTL and RenewTTL): created once, renewed whole by a
|
||||
// put, its end heard by a watch as an expiry; refused, writing nothing, on a bucket that takes none, under a second, and
|
||||
// on an update. 1754/AC2: each change the watch is to hear is waited meshtest.Bound, which a loaded build node stays within:
|
||||
// the 5 s it was given for a 1 s key's expire were overrun on one (main.505).
|
||||
// on an update. 1754/AC2: each change the watch is to hear is waited meshtest.Bound(t), the test's own deadline:
|
||||
// the 5 s it was given for a 1 s key's expire were overrun on a loaded build node (main.505).
|
||||
func TestAStaleWriteIsRefusedAndWritesNothing(t *testing.T) {
|
||||
b := counterBus(t)
|
||||
state := func(verb string, extra map[string]any) (uint64, error) {
|
||||
@@ -266,7 +266,7 @@ func TestAStaleWriteIsRefusedAndWritesNothing(t *testing.T) {
|
||||
if c.Op == "put" && len(ops) == 3 && string(c.Value) != "3" {
|
||||
t.Fatalf("the renewed key holds %s", c.Value)
|
||||
}
|
||||
case <-time.After(mt.Bound):
|
||||
case <-time.After(mt.Bound(t)):
|
||||
t.Fatalf("the watch heard %q, want %q", strings.Join(ops, " "), want)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user