WaitForCond blocks until cond returns true for the accumulated output, or ctx expires. Returns nil on match, ctx.Err() on timeout. Safe to call from any goroutine.
(ctx context.Context, cond func(string) bool)
| 69 | // output, or ctx expires. Returns nil on match, ctx.Err() on |
| 70 | // timeout. Safe to call from any goroutine. |
| 71 | func (wb *WaitBuffer) WaitForCond(ctx context.Context, cond func(string) bool) error { |
| 72 | wb.mu.Lock() |
| 73 | if cond(wb.buf.String()) { |
| 74 | wb.mu.Unlock() |
| 75 | return nil |
| 76 | } |
| 77 | w := &wbWaiter{ |
| 78 | cond: cond, |
| 79 | ch: make(chan struct{}), |
| 80 | } |
| 81 | wb.waiters = append(wb.waiters, w) |
| 82 | wb.mu.Unlock() |
| 83 | |
| 84 | select { |
| 85 | case <-w.ch: |
| 86 | return nil |
| 87 | case <-ctx.Done(): |
| 88 | return ctx.Err() |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | // RequireWaitFor blocks until the accumulated output contains |
| 93 | // signal or ctx expires. On timeout, fails the test with a |