Poll repeatedly evaluates condition until we either timeout, or it succeeds.
(t testing.TB, d time.Duration, want any, have func() any)
| 8 | |
| 9 | // Poll repeatedly evaluates condition until we either timeout, or it succeeds. |
| 10 | func Poll(t testing.TB, d time.Duration, want any, have func() any) { |
| 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 | } |