RequireEventuallyContains is a thread safe eventual checker for the buffer content
(t testing.TB, v string)
| 63 | |
| 64 | // RequireEventuallyContains is a thread safe eventual checker for the buffer content |
| 65 | func (b *SafeBuffer) RequireEventuallyContains(t testing.TB, v string) { |
| 66 | t.Helper() |
| 67 | var bufContents strings.Builder |
| 68 | poll.WaitOn(t, func(logt poll.LogT) poll.Result { |
| 69 | bufContents.Reset() |
| 70 | b.m.Lock() |
| 71 | defer b.m.Unlock() |
| 72 | if _, err := b.b.WriteTo(&bufContents); err != nil { |
| 73 | return poll.Error(fmt.Errorf("failed to copy from buffer. Error: %w", err)) |
| 74 | } |
| 75 | if !strings.Contains(bufContents.String(), v) { |
| 76 | return poll.Continue( |
| 77 | "buffer does not contain %q\n============\n%s\n============", |
| 78 | v, &bufContents) |
| 79 | } |
| 80 | return poll.Success() |
| 81 | }, |
| 82 | // 10s: container startup on Docker Desktop (macOS) with VM overhead |
| 83 | // can take 3-8s vs <1s on native Linux CI |
| 84 | poll.WithTimeout(10*time.Second), |
| 85 | poll.WithDelay(20*time.Millisecond), |
| 86 | ) |
| 87 | } |