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:
parent
af768fdd34
commit
fb394017f1
@ -1423,6 +1423,9 @@ WaitResponse:
|
||||
select {
|
||||
case err := <-writeErrCh:
|
||||
if err != nil {
|
||||
if pc.isCanceled() {
|
||||
err = errRequestCanceled
|
||||
}
|
||||
re = responseAndError{err: beforeRespHeaderError{err}}
|
||||
pc.close(fmt.Errorf("write error: %v", err))
|
||||
break WaitResponse
|
||||
@ -1446,6 +1449,9 @@ WaitResponse:
|
||||
re = responseAndError{err: errTimeout}
|
||||
break WaitResponse
|
||||
case re = <-resc:
|
||||
if re.err != nil && pc.isCanceled() {
|
||||
re.err = errRequestCanceled
|
||||
}
|
||||
break WaitResponse
|
||||
case <-cancelChan:
|
||||
pc.t.CancelRequest(req.Request)
|
||||
|
@ -1649,7 +1649,6 @@ func TestCancelRequestWithChannelBeforeDo(t *testing.T) {
|
||||
|
||||
// Issue 11020. The returned error message should be errRequestCanceled
|
||||
func TestTransportCancelBeforeResponseHeaders(t *testing.T) {
|
||||
setFlaky(t, 11894)
|
||||
defer afterTest(t)
|
||||
|
||||
serverConnCh := make(chan net.Conn, 1)
|
||||
|
Loading…
Reference in New Issue
Block a user