diff --git a/test/e2e/cloud/gcp/cluster_upgrade.go b/test/e2e/cloud/gcp/cluster_upgrade.go index e0c6e9e7aa2..3619ff0733c 100644 --- a/test/e2e/cloud/gcp/cluster_upgrade.go +++ b/test/e2e/cloud/gcp/cluster_upgrade.go @@ -416,7 +416,7 @@ func finalizeUpgradeTest(start time.Time, tc *junit.TestCase) { Value: fmt.Sprintf("%s\n\n%s", r.Message, r.FullStackTrace), }, } - case ginkgowrapper.SkipPanic: + case e2eskipper.SkipPanic: tc.Skipped = fmt.Sprintf("%s:%d %q", r.Filename, r.Line, r.Message) default: tc.Errors = []*junit.Error{ diff --git a/test/e2e/framework/ginkgowrapper/wrapper.go b/test/e2e/framework/ginkgowrapper/wrapper.go index 1cb3de1afdd..190a28fd368 100644 --- a/test/e2e/framework/ginkgowrapper/wrapper.go +++ b/test/e2e/framework/ginkgowrapper/wrapper.go @@ -67,44 +67,6 @@ func Fail(message string, callerSkip ...int) { ginkgo.Fail(message, skip) } -// SkipPanic is the value that will be panicked from Skip. -type SkipPanic struct { - Message string // The failure message passed to Fail - Filename string // The filename that is the source of the failure - Line int // The line number of the filename that is the source of the failure - FullStackTrace string // A full stack trace starting at the source of the failure -} - -// String makes SkipPanic look like the old Ginkgo panic when printed. -func (SkipPanic) String() string { return ginkgo.GINKGO_PANIC } - -// Skip wraps ginkgo.Skip so that it panics with more useful -// information about why the test is being skipped. This function will -// panic with a SkipPanic. -func Skip(message string, callerSkip ...int) { - skip := 1 - if len(callerSkip) > 0 { - skip += callerSkip[0] - } - - _, file, line, _ := runtime.Caller(skip) - sp := SkipPanic{ - Message: message, - Filename: file, - Line: line, - FullStackTrace: pruneStack(skip), - } - - defer func() { - e := recover() - if e != nil { - panic(sp) - } - }() - - ginkgo.Skip(message, skip) -} - // ginkgo adds a lot of test running infrastructure to the stack, so // we filter those out var stackSkipPattern = regexp.MustCompile(`onsi/ginkgo`) diff --git a/test/e2e/framework/skipper/BUILD b/test/e2e/framework/skipper/BUILD index 9f55973ada5..2a738a0283c 100644 --- a/test/e2e/framework/skipper/BUILD +++ b/test/e2e/framework/skipper/BUILD @@ -16,8 +16,8 @@ go_library( "//staging/src/k8s.io/client-go/dynamic:go_default_library", "//staging/src/k8s.io/client-go/kubernetes:go_default_library", "//test/e2e/framework:go_default_library", - "//test/e2e/framework/ginkgowrapper:go_default_library", "//test/e2e/framework/ssh:go_default_library", + "//vendor/github.com/onsi/ginkgo:go_default_library", ], ) diff --git a/test/e2e/framework/skipper/skipper.go b/test/e2e/framework/skipper/skipper.go index b43904c9016..94f762f439e 100644 --- a/test/e2e/framework/skipper/skipper.go +++ b/test/e2e/framework/skipper/skipper.go @@ -17,7 +17,14 @@ limitations under the License. package skipper import ( + "bufio" + "bytes" "fmt" + "github.com/onsi/ginkgo" + "regexp" + "runtime" + "runtime/debug" + "strings" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -29,7 +36,6 @@ import ( clientset "k8s.io/client-go/kubernetes" "k8s.io/kubernetes/pkg/features" "k8s.io/kubernetes/test/e2e/framework" - "k8s.io/kubernetes/test/e2e/framework/ginkgowrapper" e2essh "k8s.io/kubernetes/test/e2e/framework/ssh" ) @@ -39,7 +45,73 @@ var TestContext framework.TestContextType func skipInternalf(caller int, format string, args ...interface{}) { msg := fmt.Sprintf(format, args...) framework.Logf("INFO", msg) - ginkgowrapper.Skip(msg, caller+1) + skip(msg, caller+1) +} + +// SkipPanic is the value that will be panicked from Skip. +type SkipPanic struct { + Message string // The failure message passed to Fail + Filename string // The filename that is the source of the failure + Line int // The line number of the filename that is the source of the failure + FullStackTrace string // A full stack trace starting at the source of the failure +} + +// String makes SkipPanic look like the old Ginkgo panic when printed. +func (SkipPanic) String() string { return ginkgo.GINKGO_PANIC } + +// Skip wraps ginkgo.Skip so that it panics with more useful +// information about why the test is being skipped. This function will +// panic with a SkipPanic. +func skip(message string, callerSkip ...int) { + skip := 1 + if len(callerSkip) > 0 { + skip += callerSkip[0] + } + + _, file, line, _ := runtime.Caller(skip) + sp := SkipPanic{ + Message: message, + Filename: file, + Line: line, + FullStackTrace: pruneStack(skip), + } + + defer func() { + e := recover() + if e != nil { + panic(sp) + } + }() + + ginkgo.Skip(message, skip) +} + +// ginkgo adds a lot of test running infrastructure to the stack, so +// we filter those out +var stackSkipPattern = regexp.MustCompile(`onsi/ginkgo`) + +func pruneStack(skip int) string { + skip += 2 // one for pruneStack and one for debug.Stack + stack := debug.Stack() + scanner := bufio.NewScanner(bytes.NewBuffer(stack)) + var prunedStack []string + + // skip the top of the stack + for i := 0; i < 2*skip+1; i++ { + scanner.Scan() + } + + for scanner.Scan() { + if stackSkipPattern.Match(scanner.Bytes()) { + scanner.Scan() // these come in pairs + } else { + prunedStack = append(prunedStack, scanner.Text()) + scanner.Scan() // these come in pairs + prunedStack = append(prunedStack, scanner.Text()) + } + } + + return strings.Join(prunedStack, "\n") } // Skipf skips with information about why the test is being skipped.