You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ktesting: tone down warning about leaked test goroutine
Not terminating immediately is fairly normal: many controllers
log "terminating" messages while they shut down, which often is
right after test completion, if that is when the test cancels the
context and then doesn't wait for goroutines (which is often
not possible).
Therefore the warning now only gets printed if that happens after more than 10
seconds since test completion, and then the warning is only printed as an info
message, not an error.
logger.WithCallDepth(1).Error(nil, "WARNING: test kept at least one goroutine running after test completion", "callstack", string(dbg.Stacks(false)))
254
-
l.shared.goroutineWarningDone=true
271
+
duration:=time.Since(l.shared.stopTime)
272
+
ifduration>stopGracePeriod {
273
+
274
+
logger.WithCallDepth(1).Info("WARNING: test kept at least one goroutine running after test completion", "timeSinceCompletion", duration.Round(time.Second), "callstack", string(dbg.Stacks(false)))
// All lines from the callstack get stripped. We can be sure that it was non-empty because otherwise we wouldn't
216
221
// have the < > markers.
217
222
//
218
223
// Full output:
219
-
// testinglogger_test.go:194] "WARNING: test kept at least one goroutine running after test completion" logger="TestStop/Sub leaked goroutine" callstack=<
224
+
// testinglogger_test.go:194] "WARNING: test kept at least one goroutine running after test completion" logger="TestStop/Sub leaked goroutine.me" completed=true timeSinceCompletion="15s" callstack=<
expected:=fmt.Sprintf(`testinglogger_test.go:%d] "WARNING: test kept at least one goroutine running after test completion" logger="TestStop/Sub leaked goroutine" callstack=<
237
-
>
238
-
testinglogger_test.go:%d] "simple info message" logger="TestStop/Sub leaked goroutine"
241
+
expected:=fmt.Sprintf(`testinglogger_test.go:%d] "simple info message" logger="TestStop/Sub leaked goroutine"
testinglogger_test.go:%d] "WARNING: test kept at least one goroutine running after test completion" logger="TestStop/Sub leaked goroutine.me" completed=true timeSinceCompletion="<...>s" callstack=<
244
+
>
240
245
testinglogger_test.go:%d] "complex info message" logger="TestStop/Sub leaked goroutine.me" completed=true anotherValue=1
241
246
`,
242
-
line+1, line+1, line+2, line+3)
247
+
line+1, line+2, line+4, line+4)
243
248
ifactual!=expected {
244
249
t.Errorf("Output does not match. Expected:\n%s\nActual:\n%s\n", expected, actual)
0 commit comments