Skip to content

Commit 5447d28

Browse files
committed
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.
1 parent cc9234c commit 5447d28

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

test/utils/ktesting/contexthelper.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ func withTimeout(ctx context.Context, tb TB, timeout time.Duration, timeoutCause
5959
// No need to set a cause here. The cause or error of
6060
// the parent context will be used.
6161
case <-after.C:
62+
// Code using this tCtx may or may not log the
63+
// information above when it runs into the
64+
// cancellation. It's better if we do it, just to be on
65+
// the safe side.
66+
//
67+
// Would be nice to log this with the source code location
68+
// of our caller, but testing.Logf does not support that.
69+
tb.Logf("\nWARNING: %s\n", timeoutCause)
6270
cancel(canceledError(timeoutCause))
6371
}
6472
}()

0 commit comments

Comments
 (0)