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)