lego/platform/wait/wait_test.go

27 lines
430 B
Go
Raw Permalink Normal View History

2019-03-11 16:56:48 +00:00
package wait
import (
"testing"
"time"
)
func TestForTimeout(t *testing.T) {
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) {
return false, nil
})
}()
2021-05-14 15:37:45 +00:00
timeout := time.After(6 * time.Second)
select {
case <-timeout:
t.Fatal("timeout exceeded")
case err := <-c:
if err == nil {
t.Errorf("expected timeout error; got %v", err)
}
2021-05-14 15:37:45 +00:00
t.Logf("%v", err)
}
}