Dump the stacktrace while an error occurs

Signed-off-by: Jiatong Wang <wangjiatong@vmware.com>
This commit is contained in:
Jiatong Wang 2019-08-05 00:27:29 -07:00
parent 90df64b75b
commit 9a2ccc2c4f

View File

@ -32,6 +32,7 @@ import (
"path"
"path/filepath"
"regexp"
"runtime/debug"
"sort"
"strconv"
"strings"
@ -1359,16 +1360,28 @@ func RandomSuffix() string {
// ExpectEqual expects the specified two are the same, otherwise an exception raises
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...)
}
// ExpectNotEqual expects the specified two are not the same, otherwise an exception raises
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...)
}
// ExpectError expects an error happens, otherwise an exception raises
func ExpectError(err error, explain ...interface{}) {
if err == nil {
e2elog.Logf("Expect error to occur.")
debug.PrintStack()
}
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{}) {
if err != nil {
e2elog.Logf("Unexpected error occurred: %v", err)
debug.PrintStack()
}
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)
}
if err != nil {
debug.PrintStack()
}
gomega.ExpectWithOffset(1, err).NotTo(gomega.HaveOccurred(), explain...)
}