Documentation ¶
Overview ¶
Package poll provides tools for testing asynchronous code.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WaitOn ¶
WaitOn a condition or until a timeout. Poll by calling check and exit when check returns a done Result. To fail a test and exit polling with an error return a error result.
Example ¶
desired := 10 check := func(t LogT) Result { actual, err := numOfProcesses() if err != nil { return Error(errors.Wrapf(err, "failed to get number of processes: %s")) } if actual == desired { return Success() } t.Logf("waiting on process count to be %d...", desired) return Continue("number of processes is %d, not %d", actual, desired) } WaitOn(t, check)
Output:
Types ¶
type LogT ¶
type LogT interface { Log(args ...interface{}) Logf(format string, args ...interface{}) }
LogT is a logging interface that is passed to the WaitOn check function
type Result ¶
type Result interface { // Error indicates that the check failed and polling should stop, and the // the has failed Error() error // Done indicates that polling should stop, and the test should proceed Done() bool // Message provides the most recent state when polling has not completed Message() string }
Result of a check performed by WaitOn
func Continue ¶
Continue returns a Result that indicates to WaitOn that it should continue polling. The message text will be used as the failure message if the timeout is reached.
type SettingOp ¶
type SettingOp func(config *Settings)
SettingOp is a function which accepts and modifies Settings
Example ¶
check := func(t LogT) Result { if isDesiredState() { return Success() } return Continue("state is: %s", getState()) } WaitOn(t, check, WithTimeout(30*time.Second), WithDelay(15*time.Millisecond))
Output:
Click to show internal directories.
Click to hide internal directories.