testify
testify copied to clipboard
Wondering if it is valuable to this feature or one already exists?
Basically, my application have tests that will wait for sometimes to receive a value from a channel. However, we want to fail quickly after a specified time out. I would write a function like the one below to achieve this; I am wondering if it is valuable to have this built into testify?
func ErrorIfNoChanVal(t *testing.T, timedOut time.Duration, c <-chan struct{}, errMsg string) {
ti := time.NewTicker(timedOut)
defer ti.Stop()
select {
case <-c:
case <-ti.C:
require.FailNow(t, errMsg)
}
}