Commit a2ade452 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

net/http: improve test reliability

Fixes #4852

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/7374045
parent c6f23bb7
...@@ -970,6 +970,7 @@ func TestIssue4191_InfiniteGetTimeout(t *testing.T) { ...@@ -970,6 +970,7 @@ func TestIssue4191_InfiniteGetTimeout(t *testing.T) {
io.Copy(w, neverEnding('a')) io.Copy(w, neverEnding('a'))
}) })
ts := httptest.NewServer(mux) ts := httptest.NewServer(mux)
timeout := 100 * time.Millisecond
client := &Client{ client := &Client{
Transport: &Transport{ Transport: &Transport{
...@@ -978,7 +979,7 @@ func TestIssue4191_InfiniteGetTimeout(t *testing.T) { ...@@ -978,7 +979,7 @@ func TestIssue4191_InfiniteGetTimeout(t *testing.T) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
conn.SetDeadline(time.Now().Add(100 * time.Millisecond)) conn.SetDeadline(time.Now().Add(timeout))
if debug { if debug {
conn = NewLoggingConn("client", conn) conn = NewLoggingConn("client", conn)
} }
...@@ -988,6 +989,7 @@ func TestIssue4191_InfiniteGetTimeout(t *testing.T) { ...@@ -988,6 +989,7 @@ func TestIssue4191_InfiniteGetTimeout(t *testing.T) {
}, },
} }
getFailed := false
nRuns := 5 nRuns := 5
if testing.Short() { if testing.Short() {
nRuns = 1 nRuns = 1
...@@ -998,6 +1000,14 @@ func TestIssue4191_InfiniteGetTimeout(t *testing.T) { ...@@ -998,6 +1000,14 @@ func TestIssue4191_InfiniteGetTimeout(t *testing.T) {
} }
sres, err := client.Get(ts.URL + "/get") sres, err := client.Get(ts.URL + "/get")
if err != nil { if err != nil {
if !getFailed {
// Make the timeout longer, once.
getFailed = true
t.Logf("increasing timeout")
i--
timeout *= 10
continue
}
t.Errorf("Error issuing GET: %v", err) t.Errorf("Error issuing GET: %v", err)
break break
} }
...@@ -1024,6 +1034,7 @@ func TestIssue4191_InfiniteGetToPutTimeout(t *testing.T) { ...@@ -1024,6 +1034,7 @@ func TestIssue4191_InfiniteGetToPutTimeout(t *testing.T) {
io.Copy(ioutil.Discard, r.Body) io.Copy(ioutil.Discard, r.Body)
}) })
ts := httptest.NewServer(mux) ts := httptest.NewServer(mux)
timeout := 100 * time.Millisecond
client := &Client{ client := &Client{
Transport: &Transport{ Transport: &Transport{
...@@ -1032,7 +1043,7 @@ func TestIssue4191_InfiniteGetToPutTimeout(t *testing.T) { ...@@ -1032,7 +1043,7 @@ func TestIssue4191_InfiniteGetToPutTimeout(t *testing.T) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
conn.SetDeadline(time.Now().Add(100 * time.Millisecond)) conn.SetDeadline(time.Now().Add(timeout))
if debug { if debug {
conn = NewLoggingConn("client", conn) conn = NewLoggingConn("client", conn)
} }
...@@ -1042,6 +1053,7 @@ func TestIssue4191_InfiniteGetToPutTimeout(t *testing.T) { ...@@ -1042,6 +1053,7 @@ func TestIssue4191_InfiniteGetToPutTimeout(t *testing.T) {
}, },
} }
getFailed := false
nRuns := 5 nRuns := 5
if testing.Short() { if testing.Short() {
nRuns = 1 nRuns = 1
...@@ -1052,6 +1064,14 @@ func TestIssue4191_InfiniteGetToPutTimeout(t *testing.T) { ...@@ -1052,6 +1064,14 @@ func TestIssue4191_InfiniteGetToPutTimeout(t *testing.T) {
} }
sres, err := client.Get(ts.URL + "/get") sres, err := client.Get(ts.URL + "/get")
if err != nil { if err != nil {
if !getFailed {
// Make the timeout longer, once.
getFailed = true
t.Logf("increasing timeout")
i--
timeout *= 10
continue
}
t.Errorf("Error issuing GET: %v", err) t.Errorf("Error issuing GET: %v", err)
break break
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment