mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 19:31:44 +00:00
Merge pull request #108408 from aojea/integration_leaks
integration framework: log number of leaked goroutines
This commit is contained in:
commit
c67a19dde9
@ -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)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user