Skip to content

Commit

Permalink
test(internal): Add fatal to stop retrying (#11148)
Browse files Browse the repository at this point in the history
  • Loading branch information
bhshkh authored Nov 26, 2024
1 parent 3005f5a commit 85112bd
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions internal/testutil/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ func Retry(t *testing.T, maxAttempts int, sleep time.Duration, f func(r *R)) boo
t.Fail()
}

if r.fatal {
t.Logf("Fatal failure after %d attempts:%s", attempt, r.log.String())
t.Fail()
return false
}

time.Sleep(sleep)
}
return false
Expand All @@ -70,6 +76,11 @@ func RetryWithoutTest(maxAttempts int, sleep time.Duration, f func(r *R)) bool {
return false
}

if r.fatal {
r.Logf("Fatal failure after %d attempts:%s", attempt, r.log.String())
return false
}

time.Sleep(sleep)
}
return false
Expand All @@ -81,6 +92,7 @@ type R struct {
Attempt int

failed bool
fatal bool
log *bytes.Buffer
}

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

// Fatalf is equivalent to Errorf but will not retry.
func (r *R) Fatalf(s string, v ...interface{}) {
r.Errorf(s, v...)
r.fatal = true
}

// Logf formats its arguments and records it in the error log.
// The text is only printed for the final unsuccessful run or the first successful run.
func (r *R) Logf(s string, v ...interface{}) {
Expand Down

0 comments on commit 85112bd

Please sign in to comment.