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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user