...
1 package poll_test
2
3 import (
4 "fmt"
5 "time"
6
7 "gotest.tools/v3/poll"
8 )
9
10 var t poll.TestingT
11
12 func numOfProcesses() (int, error) {
13 return 0, nil
14 }
15
16 func ExampleWaitOn() {
17 desired := 10
18
19 check := func(t poll.LogT) poll.Result {
20 actual, err := numOfProcesses()
21 if err != nil {
22 return poll.Error(fmt.Errorf("failed to get number of processes: %w", err))
23 }
24 if actual == desired {
25 return poll.Success()
26 }
27 t.Logf("waiting on process count to be %d...", desired)
28 return poll.Continue("number of processes is %d, not %d", actual, desired)
29 }
30
31 poll.WaitOn(t, check)
32 }
33
34 func isDesiredState() bool { return false }
35 func getState() string { return "" }
36
37 func ExampleSettingOp() {
38 check := func(poll.LogT) poll.Result {
39 if isDesiredState() {
40 return poll.Success()
41 }
42 return poll.Continue("state is: %s", getState())
43 }
44 poll.WaitOn(t, check, poll.WithTimeout(30*time.Second), poll.WithDelay(15*time.Millisecond))
45 }
46
View as plain text