(t *testing.T)
| 393 | } |
| 394 | |
| 395 | func goroutineLeakCheck(t *testing.T) { |
| 396 | goroutines := func() (int, []byte) { |
| 397 | p := pprof.Lookup("goroutine") |
| 398 | b := new(bytes.Buffer) |
| 399 | p.WriteTo(b, 1) |
| 400 | return p.Count(), b.Bytes() |
| 401 | } |
| 402 | |
| 403 | startGoroutines, startStacks := goroutines() |
| 404 | t.Cleanup(func() { |
| 405 | if t.Failed() { |
| 406 | return |
| 407 | } |
| 408 | // Give goroutines time to exit, if they need it. |
| 409 | for i := 0; i < 10000; i++ { |
| 410 | if runtime.NumGoroutine() <= startGoroutines { |
| 411 | return |
| 412 | } |
| 413 | time.Sleep(1 * time.Millisecond) |
| 414 | } |
| 415 | endGoroutines, endStacks := goroutines() |
| 416 | t.Logf("starting stacks:\n%s\n", startStacks) |
| 417 | t.Logf("ending stacks:\n%s\n", endStacks) |
| 418 | t.Fatalf("expected %d goroutines, got %d, leak?", startGoroutines, endGoroutines) |
| 419 | }) |
| 420 | } |
| 421 | |
| 422 | type fakeBindSized struct { |
| 423 | size int |
no test coverage detected