Merge pull request #108408 from aojea/integration_leaks

integration framework: log number of leaked goroutines
This commit is contained in:
Kubernetes Prow Robot 2022-03-01 08:53:59 -08:00 committed by GitHub
commit c67a19dde9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -172,12 +172,30 @@ func EtcdMain(tests func() int) {
// Bail out early when -help was given as parameter.
flag.Parse()
before := runtime.NumGoroutine()
stop, err := startEtcd()
if err != nil {
klog.Fatalf("cannot run integration tests: unable to start etcd: %v", err)
}
result := tests()
stop() // Don't defer this. See os.Exit documentation.
// Log the number of goroutines leaked.
// TODO: we should work on reducing this as much as possible.
var dg int
for i := 0; i < 10; i++ {
// Leave some room for goroutines we can not get rid of
// like k8s.io/klog/v2.(*loggingT).flushDaemon()
// TODO: adjust this number based on a more exhaustive analysis.
if dg = runtime.NumGoroutine() - before; dg <= 4 {
os.Exit(result)
}
// Allow goroutines to schedule and die off.
runtime.Gosched()
time.Sleep(100 * time.Millisecond)
}
after := runtime.NumGoroutine()
klog.Infof("unexpected number of goroutines: before: %d after %d", before, after)
os.Exit(result)
}