MCPcopy Create free account
hub / github.com/encodeous/nylon / goroutineLeakCheck

Function goroutineLeakCheck

polyamide/device/device_test.go:395–420  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

393}
394
395func 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
422type fakeBindSized struct {
423 size int

Callers 2

TestTwoDevicePingFunction · 0.85
TestUpDownFunction · 0.85

Calls 3

WriteToMethod · 0.80
LookupMethod · 0.45
CleanupMethod · 0.45

Tested by

no test coverage detected