AssertReceive will receive a value from the chan and return it. If the context expires or the channel is closed before a value can be received, it will mark the test as failed but continue execution. The second return value indicates whether the receive was successful. Safety: can be called from an
(ctx context.Context, t testing.TB, c <-chan A)
| 86 | // |
| 87 | // Safety: can be called from any goroutine. |
| 88 | func AssertReceive[A any](ctx context.Context, t testing.TB, c <-chan A) (A, bool) { |
| 89 | t.Helper() |
| 90 | select { |
| 91 | case <-ctx.Done(): |
| 92 | assert.Fail(t, "AssertReceive: context expired") |
| 93 | var a A |
| 94 | return a, false |
| 95 | case a, ok := <-c: |
| 96 | if !ok { |
| 97 | assert.Fail(t, "AssertReceive: channel closed") |
| 98 | } |
| 99 | return a, ok |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | // AssertSend will send the given value over the chan and then return. If |
| 104 | // the context expires before the send succeeds, it will mark the test as failed |