From 5447d28c0d47d5236101001a224e940f2fce808c Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Fri, 23 Aug 2024 14:24:43 +0200 Subject: [PATCH] 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. --- test/utils/ktesting/contexthelper.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/utils/ktesting/contexthelper.go b/test/utils/ktesting/contexthelper.go index 28d2b245934..bcfdd4d284e 100644 --- a/test/utils/ktesting/contexthelper.go +++ b/test/utils/ktesting/contexthelper.go @@ -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 // the parent context will be used. 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)) } }()