Skip to content

Commit 85112bd

Browse files
authored
test(internal): Add fatal to stop retrying (#11148)
1 parent 3005f5a commit 85112bd

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

internal/testutil/retry.go

+18
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ func Retry(t *testing.T, maxAttempts int, sleep time.Duration, f func(r *R)) boo
4545
t.Fail()
4646
}
4747

48+
if r.fatal {
49+
t.Logf("Fatal failure after %d attempts:%s", attempt, r.log.String())
50+
t.Fail()
51+
return false
52+
}
53+
4854
time.Sleep(sleep)
4955
}
5056
return false
@@ -70,6 +76,11 @@ func RetryWithoutTest(maxAttempts int, sleep time.Duration, f func(r *R)) bool {
7076
return false
7177
}
7278

79+
if r.fatal {
80+
r.Logf("Fatal failure after %d attempts:%s", attempt, r.log.String())
81+
return false
82+
}
83+
7384
time.Sleep(sleep)
7485
}
7586
return false
@@ -81,6 +92,7 @@ type R struct {
8192
Attempt int
8293

8394
failed bool
95+
fatal bool
8496
log *bytes.Buffer
8597
}
8698

@@ -95,6 +107,12 @@ func (r *R) Errorf(s string, v ...interface{}) {
95107
r.Fail()
96108
}
97109

110+
// Fatalf is equivalent to Errorf but will not retry.
111+
func (r *R) Fatalf(s string, v ...interface{}) {
112+
r.Errorf(s, v...)
113+
r.fatal = true
114+
}
115+
98116
// Logf formats its arguments and records it in the error log.
99117
// The text is only printed for the final unsuccessful run or the first successful run.
100118
func (r *R) Logf(s string, v ...interface{}) {

0 commit comments

Comments
 (0)