I've found the following test helpers useful (especially when paired with testing/synctest):
func requireBlocked[T any](t *testing.T, ch <-chan T) {
t.Helper()
select {
case r := <-ch:
t.Fatalf("Channel receive should have blocked, but got: %v", r)
default:
// OK.
}
}
func requireUnblocked[T any](t *testing.T, ch <-chan T) (r T) {
t.Helper()
select {
case r = <-ch:
default:
t.Fatalf("Channel receive should not have been blocked")
}
return
}
These seem like they could be useful assertions to include.
I've found the following test helpers useful (especially when paired with
testing/synctest):These seem like they could be useful assertions to include.