test: extend must-happen event wait bounds #472

Merged
admin merged 2 commits from test/remaining-eventual-waits into dev 2026-10-19 07:24:27 +00:00
3 changed files with 3 additions and 2 deletions
Showing only changes of commit 674b63ebd7 - Show all commits
+1 -1
View File
@@ -45,7 +45,7 @@ func TestRunningAttemptExpiresAtItsDeadline(t *testing.T) {
c.notifyExpiryChangedLocked()
c.mu.Unlock()
deadline := time.Now().Add(time.Second)
deadline := time.Now().Add(eventualWait)
for time.Now().Before(deadline) {
c.mu.Lock()
state := job.State
+1 -1
View File
@@ -563,7 +563,7 @@ func TestEventDrivenCollectionRetriesFailureWithBackoff(t *testing.T) {
if err := os.Remove(blocker); err != nil {
t.Fatal(err)
}
deadline := time.Now().Add(time.Second)
deadline := time.Now().Add(eventualWait)
for time.Now().Before(deadline) {
held, err := store.Has(ctx, cid)
if err != nil {
+1
View File
@@ -88,6 +88,7 @@ Every statement of hand-written code must be executed by some test; `make cover`
- **A check that cannot fire should not be written.** If an error cannot happen, do not branch on it; say why in a comment instead.
- **Time is passed in, not waited for.** Garbage collection takes the current time as an argument so tests can ask what happens an hour or a week from now.
- **Timing-dependent tests are a bug.** Coverage and results must be the same on every run.
- **Give must-happen events a load-tolerant bound.** Waits for an event that should occur (such as a reconnect or a retry) use the package's `eventualWait` bound, not a one-second deadline; tests for something that must *not* happen keep a short observation window. A passing test returns as soon as the event arrives.
- **Intervals are shortened, not waited out.** What a real node does every few seconds or minutes (a worker reporting in, a follower asking what to hold, a host checking its place on a relay, a cluster comparing pins) is a package variable that a test makes shorter for its own length, with helpers such as `replicateQuickly`, `quickCluster`, `relayQuickly` and `reportQuickly`. A test then waits for the outcome with `waitFor` or `waitForOutput`, not with a sleep. [`timers.md`](timers.md) lists every timer in the daemon and why it is one.
Tests that need a node start a real one in-process on a loopback port (`startPool`, `startDaemon`). Every node in a test has its own key and connects over TLS like a real one; `cli` runs a command as the owner of the test node it is addressed to, and `as` runs one from another node's point of view.