]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: deflake TestServerTimeouts maybe
authorBrad Fitzpatrick <bradfitz@golang.org>
Thu, 15 Dec 2016 16:18:45 +0000 (16:18 +0000)
committerBrad Fitzpatrick <bradfitz@golang.org>
Thu, 15 Dec 2016 23:32:24 +0000 (23:32 +0000)
I haven't been able to reproduce this one, but change a few suspect
things in this test. Notably, using the global "Get" function and thus
using the DefaultTransport was buggy in a parallel test. Then add some error
checks and close a TCP connection.

Hopefully the failure wasn't timing-related.

Fixes #18036 (I hope)

Change-Id: I4904e42e40b26d488cf82111424a1d4d46f42dae
Reviewed-on: https://go-review.googlesource.com/34490
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/net/http/serve_test.go

index 593b1f3cdd5ef7e05a9a2c7fb9d83c4640671c8f..ab3c3461d7df1d4f9beed3496e7ff8203d7b5075 100644 (file)
@@ -481,11 +481,11 @@ func TestServerTimeouts(t *testing.T) {
        if err != nil {
                t.Fatalf("http Get #1: %v", err)
        }
-       got, _ := ioutil.ReadAll(r.Body)
+       got, err := ioutil.ReadAll(r.Body)
        expected := "req=1"
-       if string(got) != expected {
-               t.Errorf("Unexpected response for request #1; got %q; expected %q",
-                       string(got), expected)
+       if string(got) != expected || err != nil {
+               t.Errorf("Unexpected response for request #1; got %q ,%v; expected %q, nil",
+                       string(got), err, expected)
        }
 
        // Slow client that should timeout.
@@ -496,6 +496,7 @@ func TestServerTimeouts(t *testing.T) {
        }
        buf := make([]byte, 1)
        n, err := conn.Read(buf)
+       conn.Close()
        latency := time.Since(t1)
        if n != 0 || err != io.EOF {
                t.Errorf("Read = %v, %v, wanted %v, %v", n, err, 0, io.EOF)
@@ -507,14 +508,14 @@ func TestServerTimeouts(t *testing.T) {
        // Hit the HTTP server successfully again, verifying that the
        // previous slow connection didn't run our handler.  (that we
        // get "req=2", not "req=3")
-       r, err = Get(ts.URL)
+       r, err = c.Get(ts.URL)
        if err != nil {
                t.Fatalf("http Get #2: %v", err)
        }
-       got, _ = ioutil.ReadAll(r.Body)
+       got, err = ioutil.ReadAll(r.Body)
        expected = "req=2"
-       if string(got) != expected {
-               t.Errorf("Get #2 got %q, want %q", string(got), expected)
+       if string(got) != expected || err != nil {
+               t.Errorf("Get #2 got %q, %v, want %q, nil", string(got), err, expected)
        }
 
        if !testing.Short() {