From 7630072e630979f73e05464c126a251e5412fc2b Mon Sep 17 00:00:00 2001 From: jochen Date: Mon, 12 Oct 2026 13:05:15 +0200 Subject: [PATCH] Wait for the verb's own connection by name, not the first closed one (issue 543) closedNames returned as soon as the bus's closed-connections list held anything, which could be the test's own setup connection closing before the verb subprocess's connection did. That raced TestAVerbsOwnProcessNamesItsConnection red about once in 80 runs. It now waits until the connection it is named for appears, or the deadline passes. --- cmd/mesh-controller/reconnects_test.go | 2 +- cmd/mesh-controller/replay327_test.go | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/cmd/mesh-controller/reconnects_test.go b/cmd/mesh-controller/reconnects_test.go index d6b26b95..4f43f5e3 100644 --- a/cmd/mesh-controller/reconnects_test.go +++ b/cmd/mesh-controller/reconnects_test.go @@ -80,7 +80,7 @@ func TestAVerbsOwnProcessNamesItsConnection(t *testing.T) { // A silence acts, so it is still its own process; it dials, and finds no such condition. _, _ = handlers["conditions"](context.Background(), json.RawMessage(`{"silence":"bus.nothing.here","for":"1h","why":"a test"}`)) - names := closedNames(t, bus) + names := closedNames(t, bus, "mesh-controller verb conditions") found := false for _, n := range names { found = found || n == "mesh-controller verb conditions" diff --git a/cmd/mesh-controller/replay327_test.go b/cmd/mesh-controller/replay327_test.go index 73f2cc14..bac8296d 100644 --- a/cmd/mesh-controller/replay327_test.go +++ b/cmd/mesh-controller/replay327_test.go @@ -84,8 +84,12 @@ func asAProcess(t *testing.T, url string) { t.Setenv(broker.CertificateVar, "") } -// closedNames are the names of the connections the bus saw closed. -func closedNames(t *testing.T, bus *server.Server) []string { +// closedNames are the names of the connections the bus saw closed, waited for by want's own name: the +// bus can register another connection's close first (the test's own setup connection, say), so returning +// on the first non-empty list names whichever closed first, not necessarily the one being waited for +// (novox/hq issue 543). closedNames instead waits until want itself appears among the closed connections, +// or the deadline passes, and returns whatever names it last saw either way. +func closedNames(t *testing.T, bus *server.Server, want string) []string { t.Helper() deadline := time.Now().Add(5 * time.Second) var names []string @@ -95,10 +99,14 @@ func closedNames(t *testing.T, bus *server.Server) []string { t.Fatal(err) } names = names[:0] + found := false for _, c := range connz.Conns { names = append(names, c.Name) + if c.Name == want { + found = true + } } - if len(names) > 0 { + if found { return names } time.Sleep(50 * time.Millisecond)