consul/testutil/wait.go

26 lines
351 B
Go
Raw Normal View History

package testutil
import (
"fmt"
2014-05-16 22:49:47 +00:00
"time"
)
const (
2017-04-27 00:42:50 +00:00
wait = 25 * time.Millisecond
timeout = 5 * time.Second
)
2017-04-27 00:42:50 +00:00
func WaitForResult(f func() (bool, error)) error {
stop := time.Now().Add(timeout)
for {
ok, err := f()
if ok {
return nil
}
2017-04-27 00:42:50 +00:00
if time.Now().After(stop) {
return fmt.Errorf("timeout: %s", err)
}
2017-04-27 00:42:50 +00:00
time.Sleep(wait)
}
}