package retry
import "github.com/hashicorp/serf/testutil/retry"
Package retry provides support for repeating operations in tests.
A sample retry operation looks like this:
func TestX(t *testing.T) { retry.Run(t, func(r *retry.R) { if err := foo(); err != nil { r.Fatal("f: ", err) } }) }
Index ¶
- func Run(t Failer, f func(r *R))
- func RunWith(r Retryer, t Failer, f func(r *R))
- type Counter
- type Failer
- type R
- func (r *R) Check(err error)
- func (r *R) Error(args ...interface{})
- func (r *R) Errorf(format string, args ...interface{})
- func (r *R) FailNow()
- func (r *R) Fatal(args ...interface{})
- func (r *R) Fatalf(format string, args ...interface{})
- type Retryer
- type Timer
Functions ¶
func Run ¶
func RunWith ¶
Types ¶
type Counter ¶
Counter repeats an operation a given number of times and waits between subsequent operations.
func ThreeTimes ¶
func ThreeTimes() *Counter
ThreeTimes repeats an operation three times and waits 25ms in between.
func (*Counter) NextOr ¶
type Failer ¶
type Failer interface { // Log is called for the final test output Log(args ...interface{}) // FailNow is called when the retrying is abandoned. FailNow() }
Failer is an interface compatible with testing.T.
type R ¶
type R struct {
// contains filtered or unexported fields
}
R provides context for the retryer.
func (*R) Check ¶
func (*R) Error ¶
func (r *R) Error(args ...interface{})
func (*R) Errorf ¶
func (*R) FailNow ¶
func (r *R) FailNow()
func (*R) Fatal ¶
func (r *R) Fatal(args ...interface{})
func (*R) Fatalf ¶
type Retryer ¶
type Retryer interface { // NextOr returns true if the operation should be repeated. // Otherwise, it calls fail and returns false. NextOr(fail func()) bool }
Retryer provides an interface for repeating operations until they succeed or an exit condition is met.
type Timer ¶
type Timer struct { Timeout time.Duration Wait time.Duration // contains filtered or unexported fields }
Timer repeats an operation for a given amount of time and waits between subsequent operations.
func DefaultFailer ¶
func DefaultFailer() *Timer
DefaultFailer provides default retry.Run() behavior for unit tests.
func TwoSeconds ¶
func TwoSeconds() *Timer
TwoSeconds repeats an operation for two seconds and waits 25ms in between.
func (*Timer) NextOr ¶
Source Files ¶
- Version
- v0.10.2 (latest)
- Published
- Jan 14, 2025
- Platform
- linux/amd64
- Imports
- 6 packages
- Last checked
- 1 week ago –
Tools for package owners.