From 2a7f9723ec1738b21cecc851e1e9a09c6a59249d Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Sun, 23 Oct 2022 12:57:28 +0200 Subject: [PATCH] e2e framework: fix incorrect backtrace in Failf Commit 99e909603467a36050e046b7274627debc47959e was only supposed to remove the FailfWithOffset function, but it also changed the behavior by skipping one additional stack frame. That makes no sense and is inconsistent with Fail, which also logs the direct caller. --- test/e2e/framework/log.go | 6 +++--- test/e2e/framework/log_test.go | 6 +++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/test/e2e/framework/log.go b/test/e2e/framework/log.go index 27d5fd84c34..875df20fcec 100644 --- a/test/e2e/framework/log.go +++ b/test/e2e/framework/log.go @@ -41,11 +41,11 @@ func Logf(format string, args ...interface{}) { log("INFO", format, args...) } -// Failf logs the fail info, including a stack trace starts at 2 levels above its caller -// (for example, for call chain f -> g -> Failf("foo", ...) error would be logged for "f"). +// Failf logs the fail info, including a stack trace starts with its direct caller +// (for example, for call chain f -> g -> Failf("foo", ...) error would be logged for "g"). func Failf(format string, args ...interface{}) { msg := fmt.Sprintf(format, args...) - skip := 2 + skip := 1 log("FAIL", "%s\n\nFull Stack Trace\n%s", msg, PrunedStack(skip)) fail(nowStamp()+": "+msg, skip) panic("unreachable") diff --git a/test/e2e/framework/log_test.go b/test/e2e/framework/log_test.go index e1efb52131b..8eff74c06dd 100644 --- a/test/e2e/framework/log_test.go +++ b/test/e2e/framework/log_test.go @@ -154,10 +154,14 @@ k8s.io/kubernetes/test/e2e/framework_test.glob..func1.5() FAIL: I'm failing. Full Stack Trace +k8s.io/kubernetes/test/e2e/framework_test.glob..func1.3.1(...) + log_test.go:56 k8s.io/kubernetes/test/e2e/framework_test.glob..func1.3() log_test.go:57` + commonOutput, Failure: "I'm failing.", - Stack: `k8s.io/kubernetes/test/e2e/framework_test.glob..func1.3() + Stack: `k8s.io/kubernetes/test/e2e/framework_test.glob..func1.3.1(...) + log_test.go:56 +k8s.io/kubernetes/test/e2e/framework_test.glob..func1.3() log_test.go:57`, }, output.TestResult{