RequireSend will send the given value over the chan and then return. If the context expires before the send succeeds, it will fail the test. Safety: Must only be called from the Go routine that created `t`.
(ctx context.Context, t testing.TB, c chan<- A, a A)
| 50 | // |
| 51 | // Safety: Must only be called from the Go routine that created `t`. |
| 52 | func RequireSend[A any](ctx context.Context, t testing.TB, c chan<- A, a A) { |
| 53 | t.Helper() |
| 54 | select { |
| 55 | case <-ctx.Done(): |
| 56 | require.Fail(t, "RequireSend: context expired") |
| 57 | case c <- a: |
| 58 | // OK! |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | // SoftTryReceive will attempt to receive a value from the chan and return it. If |
| 63 | // the context expires before a value can be received, it will mark the test as |