aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@golang.org>2016-11-21 14:58:23 +0000
committerBrad Fitzpatrick <bradfitz@golang.org>2016-11-21 20:27:27 +0000
commit35231ec7c6a6d9277bf6ac53cb0142e4d37c2ece (patch)
tree9e87ccf756e1bd65ea80cb711d81773669cd45bd /src
parent01b4ddb37724b0cd0a1f0a62956f9e0e706bb10c (diff)
downloadgo-35231ec7c6a6d9277bf6ac53cb0142e4d37c2ece.tar.xz
net/http: deflake TestClientTimeout
Should fix flakes like: https://build.golang.org/log/c8da331317064227f38d5ef57ed7dba563ba1b38 --- FAIL: TestClientTimeout_h1 (0.35s) client_test.go:1263: timeout after 200ms waiting for timeout of 100ms FAIL Change-Id: I0a4dba607524e8d7a00f498e27d9598acde5d222 Reviewed-on: https://go-review.googlesource.com/33420 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src')
-rw-r--r--src/net/http/client_test.go19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/net/http/client_test.go b/src/net/http/client_test.go
index 943f6f89c7..a5f58cb5cb 100644
--- a/src/net/http/client_test.go
+++ b/src/net/http/client_test.go
@@ -1188,9 +1188,7 @@ func TestClientTimeout_h2(t *testing.T) { testClientTimeout(t, h2Mode) }
func testClientTimeout(t *testing.T, h2 bool) {
setParallel(t)
defer afterTest(t)
- testDone := make(chan struct{})
-
- const timeout = 100 * time.Millisecond
+ testDone := make(chan struct{}) // closed in defer below
sawRoot := make(chan bool, 1)
sawSlow := make(chan bool, 1)
@@ -1204,21 +1202,22 @@ func testClientTimeout(t *testing.T, h2 bool) {
sawSlow <- true
w.Write([]byte("Hello"))
w.(Flusher).Flush()
- select {
- case <-testDone:
- case <-time.After(timeout * 10):
- }
+ <-testDone
return
}
}))
defer cst.close()
- defer close(testDone)
+ defer close(testDone) // before cst.close, to unblock /slow handler
+
+ // 200ms should be long enough to get a normal request (the /
+ // handler), but not so long that it makes the test slow.
+ const timeout = 200 * time.Millisecond
cst.c.Timeout = timeout
res, err := cst.c.Get(cst.ts.URL)
if err != nil {
if strings.Contains(err.Error(), "Client.Timeout") {
- t.Skip("host too slow to get fast resource in 100ms")
+ t.Skipf("host too slow to get fast resource in %v", timeout)
}
t.Fatal(err)
}
@@ -1244,7 +1243,7 @@ func testClientTimeout(t *testing.T, h2 bool) {
res.Body.Close()
}()
- const failTime = timeout * 2
+ const failTime = 5 * time.Second
select {
case err := <-errc:
if err == nil {