Archived
closedNames waits for the verb's own connection by name, not the first closed one (issue 543) #252
@@ -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.
|
// A silence acts, so it is still its own process; it dials, and finds no such condition.
|
||||||
_, _ = handlers["conditions"](context.Background(),
|
_, _ = handlers["conditions"](context.Background(),
|
||||||
json.RawMessage(`{"silence":"bus.nothing.here","for":"1h","why":"a test"}`))
|
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
|
found := false
|
||||||
for _, n := range names {
|
for _, n := range names {
|
||||||
found = found || n == "mesh-controller verb conditions"
|
found = found || n == "mesh-controller verb conditions"
|
||||||
|
|||||||
@@ -84,8 +84,12 @@ func asAProcess(t *testing.T, url string) {
|
|||||||
t.Setenv(broker.CertificateVar, "")
|
t.Setenv(broker.CertificateVar, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
// closedNames are the names of the connections the bus saw closed.
|
// closedNames are the names of the connections the bus saw closed, waited for by want's own name: the
|
||||||
func closedNames(t *testing.T, bus *server.Server) []string {
|
// 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()
|
t.Helper()
|
||||||
deadline := time.Now().Add(5 * time.Second)
|
deadline := time.Now().Add(5 * time.Second)
|
||||||
var names []string
|
var names []string
|
||||||
@@ -95,10 +99,14 @@ func closedNames(t *testing.T, bus *server.Server) []string {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
names = names[:0]
|
names = names[:0]
|
||||||
|
found := false
|
||||||
for _, c := range connz.Conns {
|
for _, c := range connz.Conns {
|
||||||
names = append(names, c.Name)
|
names = append(names, c.Name)
|
||||||
|
if c.Name == want {
|
||||||
|
found = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if len(names) > 0 {
|
if found {
|
||||||
return names
|
return names
|
||||||
}
|
}
|
||||||
time.Sleep(50 * time.Millisecond)
|
time.Sleep(50 * time.Millisecond)
|
||||||
|
|||||||
Reference in New Issue
Block a user