2016-03-11 02:52:46 +00:00
|
|
|
package acme
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestWaitForTimeout(t *testing.T) {
|
|
|
|
c := make(chan error)
|
|
|
|
go func() {
|
2016-03-11 03:51:02 +00:00
|
|
|
err := WaitFor(3*time.Second, 1*time.Second, func() (bool, error) {
|
2016-03-11 02:52:46 +00:00
|
|
|
return false, nil
|
|
|
|
})
|
|
|
|
c <- err
|
|
|
|
}()
|
|
|
|
|
|
|
|
timeout := time.After(4 * time.Second)
|
|
|
|
select {
|
|
|
|
case <-timeout:
|
|
|
|
t.Fatal("timeout exceeded")
|
|
|
|
case err := <-c:
|
|
|
|
if err == nil {
|
|
|
|
t.Errorf("expected timeout error; got %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|