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-17 15:56:26 +01:00
parent 89637c0a51
commit 6395b87577
No known key found for this signature in database
GPG key ID: 77C1D22D53E15F02
2 changed files with 8 additions and 2 deletions

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

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
}