mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 20:53:33 +00:00
Merge pull request #80979 from jiatongw/e2e/framework/printstack
[e2e] Dump the stacktrace while an error occurs
This commit is contained in:
commit
68d6ec9d4a
@ -32,6 +32,7 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"runtime/debug"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -1359,16 +1360,28 @@ func RandomSuffix() string {
|
|||||||
|
|
||||||
// ExpectEqual expects the specified two are the same, otherwise an exception raises
|
// ExpectEqual expects the specified two are the same, otherwise an exception raises
|
||||||
func ExpectEqual(actual interface{}, extra interface{}, explain ...interface{}) {
|
func ExpectEqual(actual interface{}, extra interface{}, explain ...interface{}) {
|
||||||
|
if isEqual, _ := gomega.Equal(extra).Match(actual); !isEqual {
|
||||||
|
e2elog.Logf("Unexpected unequal occurred: %v and %v", actual, extra)
|
||||||
|
debug.PrintStack()
|
||||||
|
}
|
||||||
gomega.Expect(actual).To(gomega.Equal(extra), explain...)
|
gomega.Expect(actual).To(gomega.Equal(extra), explain...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExpectNotEqual expects the specified two are not the same, otherwise an exception raises
|
// ExpectNotEqual expects the specified two are not the same, otherwise an exception raises
|
||||||
func ExpectNotEqual(actual interface{}, extra interface{}, explain ...interface{}) {
|
func ExpectNotEqual(actual interface{}, extra interface{}, explain ...interface{}) {
|
||||||
|
if isEqual, _ := gomega.Equal(extra).Match(actual); isEqual {
|
||||||
|
e2elog.Logf("Expect to be unequal: %v and %v", actual, extra)
|
||||||
|
debug.PrintStack()
|
||||||
|
}
|
||||||
gomega.Expect(actual).NotTo(gomega.Equal(extra), explain...)
|
gomega.Expect(actual).NotTo(gomega.Equal(extra), explain...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExpectError expects an error happens, otherwise an exception raises
|
// ExpectError expects an error happens, otherwise an exception raises
|
||||||
func ExpectError(err error, explain ...interface{}) {
|
func ExpectError(err error, explain ...interface{}) {
|
||||||
|
if err == nil {
|
||||||
|
e2elog.Logf("Expect error to occur.")
|
||||||
|
debug.PrintStack()
|
||||||
|
}
|
||||||
gomega.Expect(err).To(gomega.HaveOccurred(), explain...)
|
gomega.Expect(err).To(gomega.HaveOccurred(), explain...)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1382,6 +1395,7 @@ func ExpectNoError(err error, explain ...interface{}) {
|
|||||||
func ExpectNoErrorWithOffset(offset int, err error, explain ...interface{}) {
|
func ExpectNoErrorWithOffset(offset int, err error, explain ...interface{}) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
e2elog.Logf("Unexpected error occurred: %v", err)
|
e2elog.Logf("Unexpected error occurred: %v", err)
|
||||||
|
debug.PrintStack()
|
||||||
}
|
}
|
||||||
gomega.ExpectWithOffset(1+offset, err).NotTo(gomega.HaveOccurred(), explain...)
|
gomega.ExpectWithOffset(1+offset, err).NotTo(gomega.HaveOccurred(), explain...)
|
||||||
}
|
}
|
||||||
@ -1396,6 +1410,9 @@ func ExpectNoErrorWithRetries(fn func() error, maxRetries int, explain ...interf
|
|||||||
}
|
}
|
||||||
e2elog.Logf("(Attempt %d of %d) Unexpected error occurred: %v", i+1, maxRetries, err)
|
e2elog.Logf("(Attempt %d of %d) Unexpected error occurred: %v", i+1, maxRetries, err)
|
||||||
}
|
}
|
||||||
|
if err != nil {
|
||||||
|
debug.PrintStack()
|
||||||
|
}
|
||||||
gomega.ExpectWithOffset(1, err).NotTo(gomega.HaveOccurred(), explain...)
|
gomega.ExpectWithOffset(1, err).NotTo(gomega.HaveOccurred(), explain...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user