mirror of
https://github.com/strukturag/nextcloud-spreed-signaling
synced 2024-05-13 11:06:33 +02:00
Dump previous goroutines if leakcheck fails.
This commit is contained in:
parent
a8180194ef
commit
0d15971506
|
@ -288,7 +288,7 @@ func WaitForHub(ctx context.Context, t *testing.T, h *Hub) {
|
|||
case <-ctx.Done():
|
||||
h.mu.Lock()
|
||||
h.ru.Lock()
|
||||
dumpGoroutines()
|
||||
dumpGoroutines("", os.Stderr)
|
||||
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()
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
package signaling
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"os"
|
||||
"os/signal"
|
||||
"runtime/pprof"
|
||||
|
@ -53,6 +55,8 @@ func ensureNoGoroutinesLeak(t *testing.T, f func(t *testing.T)) {
|
|||
// go routines
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
before := profile.Count()
|
||||
var prev bytes.Buffer
|
||||
dumpGoroutines("Before:", &prev)
|
||||
|
||||
t.Run("leakcheck", f)
|
||||
|
||||
|
@ -68,12 +72,16 @@ func ensureNoGoroutinesLeak(t *testing.T, f func(t *testing.T)) {
|
|||
}
|
||||
|
||||
if after != before {
|
||||
dumpGoroutines()
|
||||
io.Copy(os.Stderr, &prev) // nolint
|
||||
dumpGoroutines("After:", os.Stderr)
|
||||
t.Fatalf("Number of Go routines has changed from %d to %d", before, after)
|
||||
}
|
||||
}
|
||||
|
||||
func dumpGoroutines() {
|
||||
func dumpGoroutines(prefix string, w io.Writer) {
|
||||
if prefix != "" {
|
||||
io.WriteString(w, prefix+"\n") // nolint
|
||||
}
|
||||
profile := pprof.Lookup("goroutine")
|
||||
profile.WriteTo(os.Stderr, 2) // nolint
|
||||
profile.WriteTo(w, 2) // nolint
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue