1package testhelper 2 3import ( 4 "fmt" 5 "io" 6 "testing" 7 "time" 8 9 "github.com/stretchr/testify/require" 10) 11 12// ReceiveEOFWithTimeout reads to the end of the stream and will throw an 13// error if a deadlock is suspected 14func ReceiveEOFWithTimeout(t testing.TB, errorFunc func() error) { 15 errCh := make(chan error, 1) 16 go func() { 17 errCh <- errorFunc() 18 }() 19 20 var err error 21 select { 22 case err = <-errCh: 23 case <-time.After(1 * time.Second): 24 err = fmt.Errorf("timed out waiting for EOF") 25 } 26 27 if err != nil { 28 require.Equal(t, io.EOF, err) 29 } 30} 31