net/http: maybe deflake TestCancelRequestMidBody_h2 on linux-noopt builder

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>
This commit is contained in:
Brad Fitzpatrick 2015-12-15 17:20:05 +00:00
parent 99fb19194c
commit 479c47e478

View 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)