diff --git a/internal/broker/system_exports_live_test.go b/internal/broker/system_exports_live_test.go index 2b53441e..194dd68e 100644 --- a/internal/broker/system_exports_live_test.go +++ b/internal/broker/system_exports_live_test.go @@ -104,15 +104,23 @@ func TestNatsTheSystemAccountsExportsReachMeshOnAReload(t *testing.T) { // 1147/ } // Another user connects and disconnects: the watchman hears both, and the events name that user. gitea, _ := connect("one.gitea") + // The server says each connection's own events too, the watchman's among them, and may say its connect after the + // subscription is made (issue 1169): the event looked for is the one naming the other user, whatever comes before it. hears := func(ch chan *nats.Msg, what string) { t.Helper() - select { - case m := <-ch: - if !strings.Contains(string(m.Data), "one.gitea") { - t.Errorf("the %s event does not name the user that connected: %s", what, m.Data) + bound := time.After(5 * time.Second) + var others []string + for { + select { + case m := <-ch: + if strings.Contains(string(m.Data), "one.gitea") { + return + } + others = append(others, string(m.Data)) + case <-bound: + t.Errorf("the watchman did not hear another user's %s; it heard only %q", what, others) + return } - case <-time.After(5 * time.Second): - t.Errorf("the watchman did not hear another user's %s", what) } } hears(connects, "connect")