Make tests that wait for concurrent work wait on the event or a condition with a long deadline (issue 1814)

A test that slept a fixed time and then asserted what a goroutine, process or
watcher did failed under the checker's load. Each now waits for its positive
evidence (a started baseline, a call counted, a state reached) within 30 s, and
the concurrency-limit tests meet at a barrier instead of overlapping by sleep.

Claude-Session: https://claude.ai/code/session_01NcbgfJ9Gum47zkFKWRaovL
This commit is contained in:
2026-11-01 17:24:19 +01:00
parent 3d1a450406
commit b3fcf408f2
52 changed files with 144 additions and 91 deletions
@@ -39,7 +39,7 @@ func aToolRunner(t *testing.T, b *aBus) *toolRunner {
func (r *toolRunner) ask(body string) Answered {
r.t.Helper()
var a Answered
deadline := time.Now().Add(10 * time.Second)
deadline := time.Now().Add(30 * time.Second)
for {
msg, err := r.nc.Request(AskSubject(node), []byte(body), 2*time.Second)
if err == nil {
@@ -83,7 +83,7 @@ func (b *aBus) placed(t *testing.T, module string) {
func until(t *testing.T, heard chan string, want string) {
t.Helper()
deadline := time.After(10 * time.Second)
deadline := time.After(30 * time.Second)
for {
select {
case got := <-heard:
@@ -404,10 +404,10 @@ func aClient(t *testing.T, b *aBus, e *engine, state string) (*Client, func()) {
func eventually(t *testing.T, what string, ok func() bool) {
t.Helper()
deadline := time.Now().Add(10 * time.Second)
deadline := time.Now().Add(30 * time.Second)
for !ok() {
if time.Now().After(deadline) {
t.Fatalf("not within 10s: %s", what)
t.Fatalf("not within 30s: %s", what)
}
time.Sleep(20 * time.Millisecond)
}
@@ -502,7 +502,8 @@ func TestNatsAChangeRefillsWritesOnceAndTheProgramTakesIt(t *testing.T) {
// again (ADR 0349 clause 5), which answers unchanged, so the program is not reloaded for it.
b.config(t, "dunst", "font-size", "15")
b.config(t, "dunst", "geometry", `"300x5"`)
time.Sleep(300 * time.Millisecond)
eventually(t, "the node-engine is asked for the file again by each fill", func() bool { _, asked := e.counts(dunstrc); return asked >= 3 })
time.Sleep(300 * time.Millisecond) // any stray extra write would come now
if moved, asked := e.counts(dunstrc); moved != 2 || asked != 3 {
t.Errorf("two values wrote dunstrc %d times (asked %d); want 2 and 3: the program is reloaded once a change, "+
"the file asked again each fill", moved, asked)
@@ -83,7 +83,7 @@ func TestWatchSocketWakesWhenTheSocketIsMadeAndWhenItsDirectoryReturns(t *testin
t.Helper()
select {
case <-up:
case <-time.After(5 * time.Second):
case <-time.After(30 * time.Second):
t.Fatalf("no wake for %s", what)
}
}