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 after3850eb8, 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 at309069de. Builds: issue 1754 note 8 (the quick fix), note 9 (1754/AC1 to AC4); principle 11
This commit is contained in:
@@ -35,7 +35,7 @@ func grantedBus(t *testing.T, publish map[string][]string) string {
|
||||
t.Fatal(err)
|
||||
}
|
||||
go s.Start()
|
||||
if !s.ReadyForConnections(10 * time.Second) {
|
||||
if !s.ReadyForConnections(mt.Bound) {
|
||||
t.Fatal("the bus did not come up")
|
||||
}
|
||||
t.Cleanup(s.Shutdown)
|
||||
@@ -92,7 +92,7 @@ func TestACallerFallsBackAtOnceWhereNothingServesTheCallerNamedSubject(t *testin
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if took := time.Since(began); took > 2*time.Second {
|
||||
if took := time.Since(began); took > bus.RequestTimeout/2 { // 1754/AC4: at once, not after the caller-named call's timeout
|
||||
t.Errorf("the fall-back took %s", took)
|
||||
}
|
||||
if got := h.all(); len(got) != 1 || got[0] != "" || !strings.Contains(string(answered.Result), `"caller":""`) {
|
||||
@@ -129,7 +129,7 @@ func TestACallerTheBusRefusesTheCallerNamedSubjectFallsBackAtOnce(t *testing.T)
|
||||
t.Errorf("the refusal was not said: %v", said)
|
||||
}
|
||||
mu.Unlock()
|
||||
if took := time.Since(began); took > 3*time.Second {
|
||||
if took := time.Since(began); took > bus.RequestTimeout/2 { // 1754/AC4: at once, not after RequestTimeout
|
||||
t.Errorf("the refused caller-named call held the caller %s", took)
|
||||
}
|
||||
if got := h.all(); len(got) != 1 || got[0] != "" {
|
||||
@@ -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(3 * time.Second):
|
||||
case <-time.After(mt.Bound):
|
||||
t.Error("the bus did not refuse a call naming another caller")
|
||||
}
|
||||
if got := h.all(); len(got) != 1 || got[0] != "shanks.node-tools" {
|
||||
@@ -248,6 +248,10 @@ func TestACallWaitsTheBoundItsVerbNamesAndTimesOutThere(t *testing.T) {
|
||||
// calls in flight (design 47 H2 H-A-570 (1)): a call heard after the stop began gets no answer from it, no typed fault, and its
|
||||
// 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
|
||||
// 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) {
|
||||
url := mt.URL(t)
|
||||
server := dial(t, url, "ledger", "anchor", "")
|
||||
@@ -267,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}, "", 10*time.Second)
|
||||
_, err := asker.AskWithin("ledger.who", map[string]any{"held": true}, "", mt.Bound)
|
||||
held <- err
|
||||
}()
|
||||
select {
|
||||
case <-began:
|
||||
case <-time.After(10 * time.Second):
|
||||
case <-time.After(mt.Bound):
|
||||
t.Fatal("the call to hold never reached the runner")
|
||||
}
|
||||
server.StopAnswering()
|
||||
at := time.Now()
|
||||
answered, err := asker.AskWithin("ledger.who", map[string]any{}, "", 5*time.Second)
|
||||
if took := time.Since(at); !errors.Is(err, bus.ErrNoResponders) || took > time.Second {
|
||||
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 {
|
||||
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) {
|
||||
@@ -300,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{}, "", 5*time.Second); !errors.Is(err, bus.ErrNoResponders) {
|
||||
if answered, err := asker.AskWithin("ledger.raced", map[string]any{}, "", mt.Bound); !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(10 * time.Second):
|
||||
case <-time.After(mt.Bound):
|
||||
t.Fatal("the heartbeat loop handled no more intervals")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ func TestAnAnswerLargerThanOneMessage(t *testing.T) {
|
||||
if err == nil || !strings.Contains(err.Error(), "more than the bus carries") {
|
||||
t.Fatalf("a module's answer too large for one message read as %v", err)
|
||||
}
|
||||
if took := time.Since(asked); took > 5*time.Second {
|
||||
if took := time.Since(asked); took > bus.RequestTimeout/2 { // 1754/AC4: said at once, not at the call's timeout
|
||||
t.Fatalf("it took %s to say", took)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ func TestTheHolderTakesItsWorkOnceAndAFailureComesBack(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer stop()
|
||||
deadline := time.Now().Add(15 * time.Second)
|
||||
deadline := time.Now().Add(mt.Bound)
|
||||
for {
|
||||
mu.Lock()
|
||||
n := len(got)
|
||||
@@ -212,7 +212,7 @@ func TestAProofIsAskedAndAnsweredAndNeverKept(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if first, err := replies.NextMsg(30 * time.Second); err != nil || string(first.Data) != `{"linked":true}` {
|
||||
if first, err := replies.NextMsg(mt.Bound); 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(30 * time.Second)
|
||||
bound := time.After(mt.Bound)
|
||||
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(5 * time.Second):
|
||||
case <-time.After(mt.Bound):
|
||||
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 > 3*time.Second {
|
||||
if took := time.Since(began); took > mt.Bound { // 1754/AC4: refused at its bound, never waited on for ever
|
||||
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(5 * time.Second):
|
||||
case <-time.After(mt.Bound):
|
||||
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(10 * time.Second) {
|
||||
if !s.ReadyForConnections(mt.Bound) {
|
||||
t.Fatal("the bus did not come up")
|
||||
}
|
||||
t.Cleanup(s.Shutdown)
|
||||
@@ -38,7 +38,7 @@ 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 > 3*time.Second {
|
||||
if took := time.Since(start); took < 300*time.Millisecond || took > mt.Bound { // 1754/AC4: after its timeout, never at once
|
||||
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 +62,7 @@ func TestTheBusRefusesAWaitOutsideTheGrant(t *testing.T) {
|
||||
}
|
||||
done := make(chan result, 1)
|
||||
go func() {
|
||||
h, ok, refused, err := c.HearFirst(context.Background(), []string{other, granted}, 5*time.Second, nil)
|
||||
h, ok, refused, err := c.HearFirst(context.Background(), []string{other, granted}, mt.Bound, nil)
|
||||
if !ok && err == nil {
|
||||
err = errors.New("timed out")
|
||||
}
|
||||
@@ -108,7 +108,7 @@ func TestAWaitEndsWhenItsCallerIsGone(t *testing.T) {
|
||||
if ok || !errors.Is(err, context.Canceled) {
|
||||
t.Errorf("a cancelled wait answered %v, %v", ok, err)
|
||||
}
|
||||
if took := time.Since(start); took > 2*time.Second {
|
||||
if took := time.Since(start); took > mt.Bound { // 1754/AC4: at the cancel, not at its timeout of a minute
|
||||
t.Errorf("a cancelled wait ended after %s", took)
|
||||
}
|
||||
if after := c.Subscriptions(); after != before {
|
||||
|
||||
Reference in New Issue
Block a user