]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: maybe deflake TestCancelRequestMidBody_h2 on linux-noopt builder
authorBrad Fitzpatrick <bradfitz@golang.org>
Tue, 15 Dec 2015 17:20:05 +0000 (17:20 +0000)
committerBrad Fitzpatrick <bradfitz@golang.org>
Tue, 15 Dec 2015 21:07:46 +0000 (21:07 +0000)
This might deflake it. Or it'll at least give us more debugging clues.

Fixes #13626 maybe

Change-Id: Ie8cd0375d60dad033ec6a64830a90e7b9152a3d9
Reviewed-on: https://go-review.googlesource.com/17825
Reviewed-by: Austin Clements <austin@google.com>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>

src/net/http/clientserver_test.go

index ccead3f4fe82e052b007f73c39a6e2c670992198..e54091f3b8118225f514200429280bd968171996 100644 (file)
@@ -430,7 +430,6 @@ func testCancelRequestMidBody(t *testing.T, h2 bool) {
                didFlush <- true
                <-unblock
                io.WriteString(w, ", world.")
-               <-unblock
        }))
        defer cst.close()
        defer close(unblock)
@@ -445,11 +444,22 @@ func testCancelRequestMidBody(t *testing.T, h2 bool) {
        }
        defer res.Body.Close()
        <-didFlush
+
+       // Read a bit before we cancel. (Issue 13626)
+       // We should have "Hello" at least sitting there.
+       firstRead := make([]byte, 10)
+       n, err := res.Body.Read(firstRead)
+       if err != nil {
+               t.Fatal(err)
+       }
+       firstRead = firstRead[:n]
+
        close(cancel)
 
-       slurp, err := ioutil.ReadAll(res.Body)
-       if string(slurp) != "Hello" {
-               t.Errorf("Read %q; want Hello", slurp)
+       rest, err := ioutil.ReadAll(res.Body)
+       all := string(firstRead) + string(rest)
+       if all != "Hello" {
+               t.Errorf("Read %q (%q + %q); want Hello", all, firstRead, rest)
        }
        if !reflect.DeepEqual(err, ExportErrRequestCanceled) {
                t.Errorf("ReadAll error = %v; want %v", err, ExportErrRequestCanceled)