1
0
mirror of https://github.com/golang/go synced 2024-11-19 21:54:40 -07:00

net/http: fix flaky TestTransportCancelBeforeResponseHeaders test

Add a couple more cases where we convert random network I/O errors
into errRequestCanceled if the request was forcefully aborted.

It failed ~1/1000 times without -race, or very easily with -race.
(due to -race randomizing some scheduling)

Fixes #11894

Change-Id: Ib1c123ce1eebdd88642da28a5948ca4f30581907
Reviewed-on: https://go-review.googlesource.com/18287
Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
Brad Fitzpatrick 2016-01-06 19:52:51 +00:00
parent af768fdd34
commit fb394017f1
2 changed files with 6 additions and 1 deletions

View File

@ -1423,6 +1423,9 @@ WaitResponse:
select { select {
case err := <-writeErrCh: case err := <-writeErrCh:
if err != nil { if err != nil {
if pc.isCanceled() {
err = errRequestCanceled
}
re = responseAndError{err: beforeRespHeaderError{err}} re = responseAndError{err: beforeRespHeaderError{err}}
pc.close(fmt.Errorf("write error: %v", err)) pc.close(fmt.Errorf("write error: %v", err))
break WaitResponse break WaitResponse
@ -1446,6 +1449,9 @@ WaitResponse:
re = responseAndError{err: errTimeout} re = responseAndError{err: errTimeout}
break WaitResponse break WaitResponse
case re = <-resc: case re = <-resc:
if re.err != nil && pc.isCanceled() {
re.err = errRequestCanceled
}
break WaitResponse break WaitResponse
case <-cancelChan: case <-cancelChan:
pc.t.CancelRequest(req.Request) pc.t.CancelRequest(req.Request)

View File

@ -1649,7 +1649,6 @@ func TestCancelRequestWithChannelBeforeDo(t *testing.T) {
// Issue 11020. The returned error message should be errRequestCanceled // Issue 11020. The returned error message should be errRequestCanceled
func TestTransportCancelBeforeResponseHeaders(t *testing.T) { func TestTransportCancelBeforeResponseHeaders(t *testing.T) {
setFlaky(t, 11894)
defer afterTest(t) defer afterTest(t)
serverConnCh := make(chan net.Conn, 1) serverConnCh := make(chan net.Conn, 1)