mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
e2e framework: remove injection of failures and skips into GinkgoWriter
Ginkgo's timeline support will do that for us now.
This commit is contained in:
parent
f4a837affb
commit
463d42aebf
@ -17,14 +17,10 @@ limitations under the License.
|
|||||||
package framework
|
package framework
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
|
||||||
"runtime/debug"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/onsi/ginkgo/v2"
|
"github.com/onsi/ginkgo/v2"
|
||||||
// TODO: Remove the following imports (ref: https://github.com/kubernetes/kubernetes/issues/81245)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func nowStamp() string {
|
func nowStamp() string {
|
||||||
@ -45,61 +41,9 @@ func Logf(format string, args ...interface{}) {
|
|||||||
func Failf(format string, args ...interface{}) {
|
func Failf(format string, args ...interface{}) {
|
||||||
msg := fmt.Sprintf(format, args...)
|
msg := fmt.Sprintf(format, args...)
|
||||||
skip := 1
|
skip := 1
|
||||||
log("FAIL", "%s\n\nFull Stack Trace\n%s", msg, PrunedStack(skip))
|
ginkgo.Fail(msg, skip)
|
||||||
ginkgo.Fail(nowStamp()+": "+msg, skip)
|
|
||||||
panic("unreachable")
|
panic("unreachable")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fail is a replacement for ginkgo.Fail which logs the problem as it occurs
|
// Fail is an alias for ginkgo.Fail.
|
||||||
// together with a stack trace and then calls ginkgowrapper.Fail.
|
var Fail = ginkgo.Fail
|
||||||
func Fail(msg string, callerSkip ...int) {
|
|
||||||
skip := 1
|
|
||||||
if len(callerSkip) > 0 {
|
|
||||||
skip += callerSkip[0]
|
|
||||||
}
|
|
||||||
log("FAIL", "%s\n\nFull Stack Trace\n%s", msg, PrunedStack(skip))
|
|
||||||
ginkgo.Fail(nowStamp()+": "+msg, skip)
|
|
||||||
}
|
|
||||||
|
|
||||||
var codeFilterRE = regexp.MustCompile(`/github.com/onsi/ginkgo/v2/`)
|
|
||||||
|
|
||||||
// PrunedStack is a wrapper around debug.Stack() that removes information
|
|
||||||
// about the current goroutine and optionally skips some of the initial stack entries.
|
|
||||||
// With skip == 0, the returned stack will start with the caller of PruneStack.
|
|
||||||
// From the remaining entries it automatically filters out useless ones like
|
|
||||||
// entries coming from Ginkgo.
|
|
||||||
//
|
|
||||||
// This is a modified copy of PruneStack in https://github.com/onsi/ginkgo/v2/blob/f90f37d87fa6b1dd9625e2b1e83c23ffae3de228/internal/codelocation/code_location.go#L25:
|
|
||||||
// - simplified API and thus renamed (calls debug.Stack() instead of taking a parameter)
|
|
||||||
// - source code filtering updated to be specific to Kubernetes
|
|
||||||
// - optimized to use bytes and in-place slice filtering from
|
|
||||||
// https://github.com/golang/go/wiki/SliceTricks#filter-in-place
|
|
||||||
func PrunedStack(skip int) []byte {
|
|
||||||
fullStackTrace := debug.Stack()
|
|
||||||
stack := bytes.Split(fullStackTrace, []byte("\n"))
|
|
||||||
// Ensure that the even entries are the method names and
|
|
||||||
// the odd entries the source code information.
|
|
||||||
if len(stack) > 0 && bytes.HasPrefix(stack[0], []byte("goroutine ")) {
|
|
||||||
// Ignore "goroutine 29 [running]:" line.
|
|
||||||
stack = stack[1:]
|
|
||||||
}
|
|
||||||
// The "+2" is for skipping over:
|
|
||||||
// - runtime/debug.Stack()
|
|
||||||
// - PrunedStack()
|
|
||||||
skip += 2
|
|
||||||
if len(stack) > 2*skip {
|
|
||||||
stack = stack[2*skip:]
|
|
||||||
}
|
|
||||||
n := 0
|
|
||||||
for i := 0; i < len(stack)/2; i++ {
|
|
||||||
// We filter out based on the source code file name.
|
|
||||||
if !codeFilterRE.Match([]byte(stack[i*2+1])) {
|
|
||||||
stack[n] = stack[i*2]
|
|
||||||
stack[n+1] = stack[i*2+1]
|
|
||||||
n += 2
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stack = stack[:n]
|
|
||||||
|
|
||||||
return bytes.Join(stack, []byte("\n"))
|
|
||||||
}
|
|
||||||
|
@ -38,8 +38,6 @@ import (
|
|||||||
|
|
||||||
func skipInternalf(caller int, format string, args ...interface{}) {
|
func skipInternalf(caller int, format string, args ...interface{}) {
|
||||||
msg := fmt.Sprintf(format, args...)
|
msg := fmt.Sprintf(format, args...)
|
||||||
// Long term this should get replaced with https://github.com/onsi/ginkgo/issues/1069.
|
|
||||||
framework.Logf(msg)
|
|
||||||
ginkgo.Skip(msg, caller+1)
|
ginkgo.Skip(msg, caller+1)
|
||||||
panic("unreachable")
|
panic("unreachable")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user