summaryrefslogtreecommitdiff
path: root/libgo/go/net/http/main_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/net/http/main_test.go')
-rw-r--r--libgo/go/net/http/main_test.go42
1 files changed, 34 insertions, 8 deletions
diff --git a/libgo/go/net/http/main_test.go b/libgo/go/net/http/main_test.go
index 299cd7b2d2..438bd2e58f 100644
--- a/libgo/go/net/http/main_test.go
+++ b/libgo/go/net/http/main_test.go
@@ -5,8 +5,9 @@
package http_test
import (
- "flag"
"fmt"
+ "io/ioutil"
+ "log"
"net/http"
"os"
"runtime"
@@ -16,7 +17,7 @@ import (
"time"
)
-var flaky = flag.Bool("flaky", false, "run known-flaky tests too")
+var quietLog = log.New(ioutil.Discard, "", 0)
func TestMain(m *testing.M) {
v := m.Run()
@@ -91,12 +92,6 @@ func setParallel(t *testing.T) {
}
}
-func setFlaky(t *testing.T, issue int) {
- if !*flaky {
- t.Skipf("skipping known flaky test; see golang.org/issue/%d", issue)
- }
-}
-
func afterTest(t testing.TB) {
http.DefaultTransport.(*http.Transport).CloseIdleConnections()
if testing.Short() {
@@ -129,3 +124,34 @@ func afterTest(t testing.TB) {
}
t.Errorf("Test appears to have leaked %s:\n%s", bad, stacks)
}
+
+// 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
+}
+
+func closeClient(c *http.Client) {
+ c.Transport.(*http.Transport).CloseIdleConnections()
+}