testify icon indicating copy to clipboard operation
testify copied to clipboard

Wondering if it is valuable to this feature or one already exists?

Open hu13 opened this issue 3 years ago • 0 comments

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)
	}
}

hu13 avatar Sep 14 '22 21:09 hu13