ktesting: log warning on timeout

How exactly a test reacts when its context times out is unclear. In the case of
scheduler_perf, the apiserver started to shut down and the test failure then
was about not being able to reach the apiserver, which was a bit confusing.

To make it more obvious why the shutdown starts, a WARNING message gets added
to the test output by ktesting before cancellation and thus before any other
output related to that cancellation.
This commit is contained in:
Patrick Ohly 2024-08-23 14:24:43 +02:00
parent cc9234cffd
commit 5447d28c0d

View File

@ -59,6 +59,14 @@ func withTimeout(ctx context.Context, tb TB, timeout time.Duration, timeoutCause
// No need to set a cause here. The cause or error of // No need to set a cause here. The cause or error of
// the parent context will be used. // the parent context will be used.
case <-after.C: case <-after.C:
// Code using this tCtx may or may not log the
// information above when it runs into the
// cancellation. It's better if we do it, just to be on
// the safe side.
//
// Would be nice to log this with the source code location
// of our caller, but testing.Logf does not support that.
tb.Logf("\nWARNING: %s\n", timeoutCause)
cancel(canceledError(timeoutCause)) cancel(canceledError(timeoutCause))
} }
}() }()