Test: log number of active read/write pumps in case of error.

Also dump goroutines to help tracking down what is blocking cleanup.
This commit is contained in:
Joachim Bauch
2023-01-18 14:26:40 +01:00
parent 89637c0a51
commit 6395b87577
2 changed files with 8 additions and 2 deletions
+2 -1
View File
@@ -284,7 +284,8 @@ func WaitForHub(ctx context.Context, t *testing.T, h *Hub) {
case <-ctx.Done():
h.mu.Lock()
h.ru.Lock()
t.Errorf("Error waiting for clients %+v / rooms %+v / sessions %+v to terminate: %s", h.clients, h.rooms, h.sessions, ctx.Err())
dumpGoroutines()
t.Errorf("Error waiting for clients %+v / rooms %+v / sessions %+v / %d read / %d write to terminate: %s", h.clients, h.rooms, h.sessions, readActive, writeActive, ctx.Err())
h.ru.Unlock()
h.mu.Unlock()
return
+6 -1
View File
@@ -68,7 +68,12 @@ func ensureNoGoroutinesLeak(t *testing.T, f func(t *testing.T)) {
}
if after != before {
profile.WriteTo(os.Stderr, 2) // nolint
dumpGoroutines()
t.Fatalf("Number of Go routines has changed from %d to %d", before, after)
}
}
func dumpGoroutines() {
profile := pprof.Lookup("goroutine")
profile.WriteTo(os.Stderr, 2) // nolint
}