blob: ea377ba5303e35f8d6abbb70b49fb97a20ce02fd [file] [log] [blame]
package poll_test
import (
"time"
"github.com/gotestyourself/gotestyourself/poll"
"github.com/pkg/errors"
)
var t poll.TestingT
func numOfProcesses() (int, error) {
return 0, nil
}
func ExampleWaitOn() {
desired := 10
check := func(t poll.LogT) poll.Result {
actual, err := numOfProcesses()
if err != nil {
return poll.Error(errors.Wrapf(err, "failed to get number of processes: %s"))
}
if actual == desired {
return poll.Success()
}
t.Logf("waiting on process count to be %d...", desired)
return poll.Continue("number of processes is %d, not %d", actual, desired)
}
poll.WaitOn(t, check)
}
func isDesiredState() bool { return false }
func getState() string { return "" }
func ExampleSettingOp() {
check := func(t poll.LogT) poll.Result {
if isDesiredState() {
return poll.Success()
}
return poll.Continue("state is: %s", getState())
}
poll.WaitOn(t, check, poll.WithTimeout(30*time.Second), poll.WithDelay(15*time.Millisecond))
}