Skip to content

Commit a2ade45

Browse files
committed
net/http: improve test reliability
Fixes #4852 R=golang-dev, adg CC=golang-dev https://golang.org/cl/7374045
1 parent c6f23bb commit a2ade45

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/pkg/net/http/transport_test.go

+22-2
Original file line numberDiff line numberDiff line change
@@ -970,6 +970,7 @@ func TestIssue4191_InfiniteGetTimeout(t *testing.T) {
970970
io.Copy(w, neverEnding('a'))
971971
})
972972
ts := httptest.NewServer(mux)
973+
timeout := 100 * time.Millisecond
973974

974975
client := &Client{
975976
Transport: &Transport{
@@ -978,7 +979,7 @@ func TestIssue4191_InfiniteGetTimeout(t *testing.T) {
978979
if err != nil {
979980
return nil, err
980981
}
981-
conn.SetDeadline(time.Now().Add(100 * time.Millisecond))
982+
conn.SetDeadline(time.Now().Add(timeout))
982983
if debug {
983984
conn = NewLoggingConn("client", conn)
984985
}
@@ -988,6 +989,7 @@ func TestIssue4191_InfiniteGetTimeout(t *testing.T) {
988989
},
989990
}
990991

992+
getFailed := false
991993
nRuns := 5
992994
if testing.Short() {
993995
nRuns = 1
@@ -998,6 +1000,14 @@ func TestIssue4191_InfiniteGetTimeout(t *testing.T) {
9981000
}
9991001
sres, err := client.Get(ts.URL + "/get")
10001002
if err != nil {
1003+
if !getFailed {
1004+
// Make the timeout longer, once.
1005+
getFailed = true
1006+
t.Logf("increasing timeout")
1007+
i--
1008+
timeout *= 10
1009+
continue
1010+
}
10011011
t.Errorf("Error issuing GET: %v", err)
10021012
break
10031013
}
@@ -1024,6 +1034,7 @@ func TestIssue4191_InfiniteGetToPutTimeout(t *testing.T) {
10241034
io.Copy(ioutil.Discard, r.Body)
10251035
})
10261036
ts := httptest.NewServer(mux)
1037+
timeout := 100 * time.Millisecond
10271038

10281039
client := &Client{
10291040
Transport: &Transport{
@@ -1032,7 +1043,7 @@ func TestIssue4191_InfiniteGetToPutTimeout(t *testing.T) {
10321043
if err != nil {
10331044
return nil, err
10341045
}
1035-
conn.SetDeadline(time.Now().Add(100 * time.Millisecond))
1046+
conn.SetDeadline(time.Now().Add(timeout))
10361047
if debug {
10371048
conn = NewLoggingConn("client", conn)
10381049
}
@@ -1042,6 +1053,7 @@ func TestIssue4191_InfiniteGetToPutTimeout(t *testing.T) {
10421053
},
10431054
}
10441055

1056+
getFailed := false
10451057
nRuns := 5
10461058
if testing.Short() {
10471059
nRuns = 1
@@ -1052,6 +1064,14 @@ func TestIssue4191_InfiniteGetToPutTimeout(t *testing.T) {
10521064
}
10531065
sres, err := client.Get(ts.URL + "/get")
10541066
if err != nil {
1067+
if !getFailed {
1068+
// Make the timeout longer, once.
1069+
getFailed = true
1070+
t.Logf("increasing timeout")
1071+
i--
1072+
timeout *= 10
1073+
continue
1074+
}
10551075
t.Errorf("Error issuing GET: %v", err)
10561076
break
10571077
}

0 commit comments

Comments
 (0)