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