|
|
@@ -14,6 +14,7 @@ import (
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"testing"
|
|
|
+ "time"
|
|
|
|
|
|
"golang.org/x/net/http2/hpack"
|
|
|
)
|
|
|
@@ -197,3 +198,30 @@ func TestSorterPoolAllocs(t *testing.T) {
|
|
|
t.Logf("Keys allocs = %v; want <1", allocs)
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+// waitCondition reports whether fn eventually returned true,
|
|
|
+// checking immediately and then every checkEvery amount,
|
|
|
+// until waitFor has elapsed, at which point it returns false.
|
|
|
+func waitCondition(waitFor, checkEvery time.Duration, fn func() bool) bool {
|
|
|
+ deadline := time.Now().Add(waitFor)
|
|
|
+ for time.Now().Before(deadline) {
|
|
|
+ if fn() {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ time.Sleep(checkEvery)
|
|
|
+ }
|
|
|
+ return false
|
|
|
+}
|
|
|
+
|
|
|
+// waitErrCondition is like waitCondition but with errors instead of bools.
|
|
|
+func waitErrCondition(waitFor, checkEvery time.Duration, fn func() error) error {
|
|
|
+ deadline := time.Now().Add(waitFor)
|
|
|
+ var err error
|
|
|
+ for time.Now().Before(deadline) {
|
|
|
+ if err = fn(); err == nil {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ time.Sleep(checkEvery)
|
|
|
+ }
|
|
|
+ return err
|
|
|
+}
|