func TestMain(m *testing.M) { flag.Parse() exitCode := m.Run() if exitCode == 0 { // Only do extra checks if the tests were successful. if err := goroutines.IdentifyLeaks(nil); err != nil { fmt.Fprintf(os.Stderr, "Found goroutine leaks on successful test run: %v", err) exitCode = 1 } if err := checkAllChannels(); err != nil { fmt.Fprintf(os.Stderr, "Found unclosed channels on successful test run: %v", err) exitCode = 1 } } os.Exit(exitCode) }
func (ts *TestServer) verifyNoGoroutinesLeaked() { if _leakedGoroutine.Load() == 1 { ts.Log("Skipping check for leaked goroutines because of a previous leak.") return } err := goroutines.IdentifyLeaks(ts.verifyOpts) if err == nil { // No leaks, nothing to do. return } if isFirstLeak := _leakedGoroutine.CAS(0, 1); !isFirstLeak { ts.Log("Skipping check for leaked goroutines because of a previous leak.") return } if ts.Failed() { // If we've already failed this test, don't pollute the test output with // more failures. return } ts.Error(err.Error()) }