WaitFor polls until predicate returns true or the timeout expires. Returns the captured list at the moment predicate first matched (or the last seen list on timeout). Tests typically call Tick(ctx) on the worker once then WaitFor(..., 0) for an immediate check; the timeout exists for cases where the
(t *testing.T, timeout time.Duration, predicate func([]SubscriberCaptured) bool)
| 290 | // the worker once then WaitFor(..., 0) for an immediate check; the |
| 291 | // timeout exists for cases where the publisher may still be in flight. |
| 292 | func (s *SubscriberReceiverResult) WaitFor(t *testing.T, timeout time.Duration, predicate func([]SubscriberCaptured) bool) []SubscriberCaptured { |
| 293 | t.Helper() |
| 294 | deadline := time.Now().Add(timeout) |
| 295 | for { |
| 296 | got := s.Captured() |
| 297 | if predicate(got) { |
| 298 | return got |
| 299 | } |
| 300 | if time.Now().After(deadline) { |
| 301 | return got |
| 302 | } |
| 303 | time.Sleep(20 * time.Millisecond) |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | // SubscriberReceiver returns a multi-path HTTP receiver wired for the |
| 308 | // new webhook-resource envelope. Routes work as plain paths under the |