mirror of
https://github.com/strukturag/nextcloud-spreed-signaling
synced 2024-05-10 17:46:33 +02:00
Test: Fix counting / comparing of goroutines.
This commit is contained in:
parent
58bbe76b06
commit
5a12959821
|
@ -29,29 +29,27 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func ensureNoGoroutinesLeak(t *testing.T, f func()) {
|
func ensureNoGoroutinesLeak(t *testing.T, f func()) {
|
||||||
|
profile := pprof.Lookup("goroutine")
|
||||||
// Give time for things to settle before capturing the number of
|
// Give time for things to settle before capturing the number of
|
||||||
// go routines
|
// go routines
|
||||||
time.Sleep(500 * time.Millisecond)
|
time.Sleep(500 * time.Millisecond)
|
||||||
before := pprof.Lookup("goroutine")
|
before := profile.Count()
|
||||||
|
|
||||||
f()
|
f()
|
||||||
|
|
||||||
var after *pprof.Profile
|
var after int
|
||||||
// Give time for things to settle before capturing the number of
|
// Give time for things to settle before capturing the number of
|
||||||
// go routines
|
// go routines
|
||||||
timeout := time.Now().Add(time.Second)
|
timeout := time.Now().Add(time.Second)
|
||||||
for time.Now().Before(timeout) {
|
for time.Now().Before(timeout) {
|
||||||
after = pprof.Lookup("goroutine")
|
after = profile.Count()
|
||||||
if after.Count() == before.Count() {
|
if after == before {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if after.Count() != before.Count() {
|
if after != before {
|
||||||
os.Stderr.WriteString("Before:\n")
|
profile.WriteTo(os.Stderr, 2) // nolint
|
||||||
before.WriteTo(os.Stderr, 1) // nolint
|
t.Fatalf("Number of Go routines has changed in %s from %d to %d", t.Name(), before, after)
|
||||||
os.Stderr.WriteString("After:\n")
|
|
||||||
after.WriteTo(os.Stderr, 1) // nolint
|
|
||||||
t.Fatalf("Number of Go routines has changed in %s", t.Name())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue