| 1 | package testutils |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | "time" |
| 6 | ) |
| 7 | |
| 8 | // WaitChan waits for a value to be sent on a channel, or for a timeout to |
| 9 | // occur. If the timeout is reached, the test will fail. |
| 10 | func WaitChan[T any](tb testing.TB, ch <-chan T, timeout time.Duration) { |
| 11 | tb.Helper() |
| 12 | |
| 13 | select { |
| 14 | case <-ch: |
| 15 | return |
| 16 | case <-time.After(timeout): |
| 17 | tb.Fatalf("timeout waiting for channel") |
| 18 | } |
| 19 | } |