Skip to content

Commit 9a2ccc2

Browse files
author
Jiatong Wang
committed
Dump the stacktrace while an error occurs
Signed-off-by: Jiatong Wang <[email protected]>
1 parent 90df64b commit 9a2ccc2

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

test/e2e/framework/util.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"path"
3333
"path/filepath"
3434
"regexp"
35+
"runtime/debug"
3536
"sort"
3637
"strconv"
3738
"strings"
@@ -1359,16 +1360,28 @@ func RandomSuffix() string {
13591360

13601361
// ExpectEqual expects the specified two are the same, otherwise an exception raises
13611362
func ExpectEqual(actual interface{}, extra interface{}, explain ...interface{}) {
1363+
if isEqual, _ := gomega.Equal(extra).Match(actual); !isEqual {
1364+
e2elog.Logf("Unexpected unequal occurred: %v and %v", actual, extra)
1365+
debug.PrintStack()
1366+
}
13621367
gomega.Expect(actual).To(gomega.Equal(extra), explain...)
13631368
}
13641369

13651370
// ExpectNotEqual expects the specified two are not the same, otherwise an exception raises
13661371
func ExpectNotEqual(actual interface{}, extra interface{}, explain ...interface{}) {
1372+
if isEqual, _ := gomega.Equal(extra).Match(actual); isEqual {
1373+
e2elog.Logf("Expect to be unequal: %v and %v", actual, extra)
1374+
debug.PrintStack()
1375+
}
13671376
gomega.Expect(actual).NotTo(gomega.Equal(extra), explain...)
13681377
}
13691378

13701379
// ExpectError expects an error happens, otherwise an exception raises
13711380
func ExpectError(err error, explain ...interface{}) {
1381+
if err == nil {
1382+
e2elog.Logf("Expect error to occur.")
1383+
debug.PrintStack()
1384+
}
13721385
gomega.Expect(err).To(gomega.HaveOccurred(), explain...)
13731386
}
13741387

@@ -1382,6 +1395,7 @@ func ExpectNoError(err error, explain ...interface{}) {
13821395
func ExpectNoErrorWithOffset(offset int, err error, explain ...interface{}) {
13831396
if err != nil {
13841397
e2elog.Logf("Unexpected error occurred: %v", err)
1398+
debug.PrintStack()
13851399
}
13861400
gomega.ExpectWithOffset(1+offset, err).NotTo(gomega.HaveOccurred(), explain...)
13871401
}
@@ -1396,6 +1410,9 @@ func ExpectNoErrorWithRetries(fn func() error, maxRetries int, explain ...interf
13961410
}
13971411
e2elog.Logf("(Attempt %d of %d) Unexpected error occurred: %v", i+1, maxRetries, err)
13981412
}
1413+
if err != nil {
1414+
debug.PrintStack()
1415+
}
13991416
gomega.ExpectWithOffset(1, err).NotTo(gomega.HaveOccurred(), explain...)
14001417
}
14011418

0 commit comments

Comments
 (0)