mirror of
https://github.com/ddworken/hishtory.git
synced 2025-08-14 09:08:44 +02:00
Swap to using gotestsum for retrying flaky tests
This commit is contained in:
@ -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 (
|
||||
|
Reference in New Issue
Block a user