MCPcopy
hub / github.com/grafana/dskit / Poll

Function Poll

test/poll.go:10–24  ·  view source on GitHub ↗

Poll repeatedly calls a function until the function returns the correct response or until poll timeout.

(t testing.TB, d time.Duration, want interface{}, have func() interface{})

Source from the content-addressed store, hash-verified

8
9// Poll repeatedly calls a function until the function returns the correct response or until poll timeout.
10func Poll(t testing.TB, d time.Duration, want interface{}, have func() interface{}) {
11 t.Helper()
12 deadline := time.Now().Add(d)
13 for !time.Now().After(deadline) {
14
15 if reflect.DeepEqual(want, have()) {
16 return
17 }
18 time.Sleep(d / 100)
19 }
20 h := have()
21 if !reflect.DeepEqual(want, h) {
22 t.Fatalf("expected %v, got %v", want, h)
23 }
24}

Calls 5

HelperMethod · 0.80
FatalfMethod · 0.80
AddMethod · 0.65
AfterMethod · 0.65
SleepMethod · 0.65