wait

package
v0.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 14, 2022 License: MPL-2.0 Imports: 5 Imported by: 8

Documentation

Overview

Package wait provides constructs for waiting on conditionals within specified constraints.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTimeoutExceeded      = errors.New("wait: timeout exceeded")
	ErrAttemptsExceeded     = errors.New("wait: attempts exceeded")
	ErrConditionUnsatisfied = errors.New("wait: condition unsatisfied")
	ErrNoFunction           = errors.New("wait: no function specified")
)

Functions

This section is empty.

Types

type Constraint

type Constraint struct {
	// contains filtered or unexported fields
}

A Constraint is something a test assertions can wait on before marking the result to be a failure. A Constraint that uses Timeout will retry a function until the timeout expires. A Constraint that uses Attempts will retry a function until the number of attempts is exhausted. The interval between retry attempts can be configured with Gap.

func On

func On(opts ...Option) *Constraint

On creates a new Constraint with configuration set by opts.

Timeout is used to set a maximum amount of time to wait for success. Attempts is used to set a maximum number of attempts to wait for success. Gap is used to control the amount of time to wait between retries.

func (*Constraint) Run

func (c *Constraint) Run() error

Run the Constraint and produce an error result.

type Option

type Option func(*Constraint)

Option is used to configure a Constraint.

func Attempts

func Attempts(max int) Option

Attempts sets the maximum number of attempts to allow before giving up and marking the result as a failure.

If set, the timeout constraint is disabled.

By default a max timeout is used and the number of attempts is unlimited.

func BoolFunc

func BoolFunc(f func() bool) Option

BoolFunc will retry f while it returns false, or until a wait constraint threshold is exceeded.

func ErrorFunc

func ErrorFunc(f func() error) Option

ErrorFunc will retry f while it returns a non-nil error, or until a wait constraint threshold is exceeded.

func Gap

func Gap(duration time.Duration) Option

Gap sets the amount of time to wait between attempts.

Default 250 milliseconds.

func TestFunc

func TestFunc(f func() (bool, error)) Option

TestFunc will retry f while it returns false, or until a wait constraint threshold is exceeded. If f never succeeds, the latest returned error is wrapped into the result.

func Timeout

func Timeout(duration time.Duration) Option

Timeout sets the maximum amount of time to allow before giving up and marking the result as a failure.

If set, the max attempts constraint is disabled.

Default 3 seconds.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL