Swap to using gotestsum for retrying flaky tests

This commit is contained in:
David Dworken
2023-10-21 15:41:32 -07:00
parent 4e0788dccc
commit df9c6e8786
4 changed files with 21 additions and 106 deletions

View File

@ -114,89 +114,6 @@ func (z zshTester) ShellName() string {
return "zsh"
}
func runTestsWithRetries(parentT *testing.T, testName string, testFunc func(t testing.TB)) {
numRetries := 3
if testutils.IsGithubAction() {
numRetries = 5
}
runTestsWithExtraRetries(parentT, testName, testFunc, numRetries)
}
func runTestsWithExtraRetries(parentT *testing.T, testName string, testFunc func(t testing.TB), numRetries int) {
for i := 1; i <= numRetries; i++ {
rt := &retryingTester{nil, i == numRetries, true, testName, numRetries}
parentT.Run(fmt.Sprintf("%s/%d", testName, i), func(t *testing.T) {
rt.T = t
testFunc(rt)
})
if rt.succeeded {
if GLOBAL_STATSD != nil {
GLOBAL_STATSD.Incr("test_status", []string{"result:passed", "test:" + testName, "os:" + runtime.GOOS}, 1.0)
GLOBAL_STATSD.Distribution("test_retry_count", float64(i), []string{"test:" + testName, "os:" + runtime.GOOS}, 1.0)
}
break
} else {
if GLOBAL_STATSD != nil {
GLOBAL_STATSD.Incr("test_status", []string{"result:failed", "test:" + testName, "os:" + runtime.GOOS}, 1.0)
}
}
}
}
type retryingTester struct {
*testing.T
isFinalRun bool
succeeded bool
testName string
numRetries int
}
func (t *retryingTester) Fatalf(format string, args ...any) {
t.T.Helper()
t.succeeded = false
if t.isFinalRun {
if GLOBAL_STATSD != nil {
GLOBAL_STATSD.Incr("test_failure", []string{"test:" + t.testName, "os:" + runtime.GOOS}, 1.0)
GLOBAL_STATSD.Distribution("test_retry_count", float64(t.numRetries), []string{"test:" + t.testName, "os:" + runtime.GOOS}, 1.0)
}
t.T.Fatalf(format, args...)
} else {
testutils.TestLog(t.T, fmt.Sprintf("retryingTester: Ignoring fatalf for non-final run: %#v", fmt.Sprintf(format, args...)))
}
t.SkipNow()
}
func (t *retryingTester) Errorf(format string, args ...any) {
t.T.Helper()
t.succeeded = false
if t.isFinalRun {
t.T.Errorf(format, args...)
} else {
testutils.TestLog(t.T, fmt.Sprintf("retryingTester: Ignoring errorf for non-final run: %#v", fmt.Sprintf(format, args...)))
}
t.SkipNow()
}
func (t *retryingTester) FailNow() {
t.succeeded = false
if t.isFinalRun {
t.T.FailNow()
} else {
testutils.TestLog(t.T, "retryingTester: Ignoring FailNow for non-final run")
// Still terminate execution via SkipNow() since FailNow() means we should stop the current test
t.T.SkipNow()
}
}
func (t *retryingTester) Fail() {
t.succeeded = false
if t.isFinalRun {
t.T.Fail()
} else {
testutils.TestLog(t.T, "retryingTester: Ignoring Fail for non-final run")
}
}
type OnlineStatus int64
const (