2019-03-11 16:56:48 +00:00
|
|
|
package wait
|
2016-03-11 02:52:46 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2018-12-06 21:50:17 +00:00
|
|
|
func TestForTimeout(t *testing.T) {
|
2016-03-11 02:52:46 +00:00
|
|
|
c := make(chan error)
|
|
|
|
go func() {
|
2020-12-09 19:52:21 +00:00
|
|
|
c <- For("", 3*time.Second, 1*time.Second, func() (bool, error) {
|
2016-03-11 02:52:46 +00:00
|
|
|
return false, nil
|
|
|
|
})
|
|
|
|
}()
|
|
|
|
|
2020-12-09 19:52:21 +00:00
|
|
|
timeout := time.After(5 * time.Second)
|
2016-03-11 02:52:46 +00:00
|
|
|
select {
|
|
|
|
case <-timeout:
|
|
|
|
t.Fatal("timeout exceeded")
|
|
|
|
case err := <-c:
|
|
|
|
if err == nil {
|
|
|
|
t.Errorf("expected timeout error; got %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|