Documentation
¶
Index ¶
- Constants
- Variables
- func Until(fn func() bool, options ...Option) error
- func UntilComplete(fn RetriableFunc, options ...Option) (any, error)
- func UntilOrFail(t test.Failer, fn func() bool, options ...Option)
- func UntilSuccess(fn func() error, options ...Option) error
- func UntilSuccessOrFail(t test.Failer, fn func() error, options ...Option)
- type Option
- type RetriableFunc
Constants ¶
const (
// DefaultTimeout the default timeout for the entire retry operation
DefaultTimeout = time.Second * 30
// DefaultDelay the default delay between successive retry attempts
DefaultDelay = time.Millisecond * 10
// DefaultConverge the default converge, requiring something to succeed one time
DefaultConverge = 1
)
Variables ¶
var ErrConditionNotMet = errors.New("expected condition not met")
Functions ¶
func Until ¶
func Until(fn func() bool, options ...Option) error
Until retries the given function until it returns true or hits the timeout
func UntilComplete ¶
func UntilComplete(fn RetriableFunc, options ...Option) (any, error)
UntilComplete retries the given function, until there is a timeout, or until the function indicates that it has completed. Once complete, the returned value and error are returned.
func UntilOrFail ¶
func UntilOrFail(t test.Failer, fn func() bool, options ...Option)
UntilOrFail calls Until, and fails t with Fatalf if it ends up returning an error
func UntilSuccess ¶
func UntilSuccess(fn func() error, options ...Option) error
UntilSuccess retries the given function until success, timeout, or until the passed-in function returns nil.
func UntilSuccessOrFail ¶
func UntilSuccessOrFail(t test.Failer, fn func() error, options ...Option)
UntilSuccessOrFail calls UntilSuccess, and fails t with Fatalf if it ends up returning an error
Types ¶
type Option ¶
type Option func(cfg *config)
Option for a retry operation.
func BackoffDelay ¶
func BackoffDelay(delay time.Duration) Option
func Converge ¶
func Converge(successes int) Option
Converge sets the number of successes in a row needed to count a success. This is useful to avoid the case where tests like `coin.Flip() == HEADS` will always return success due to random variance.
func Delay ¶
func Delay(delay time.Duration) Option
Delay sets the delay between successive retry attempts.
func MaxAttempts ¶
func MaxAttempts(attempts int) Option
MaxAttempts allows defining a maximum number of attempts. If unset, only timeout is considered.
type RetriableFunc ¶
type RetriableFunc func() (result any, completed bool, err error)
RetriableFunc a function that can be retried.