Skip to content

Commit

Permalink
http2: workaround TCPConn CloseWrite not being supported on Plan 9
Browse files Browse the repository at this point in the history
This stops the tests from hanging on Plan 9.

Fixes golang/go#35904
Updates golang/go#17906

Change-Id: I2bcbb131629b217a99f9496cda0399ce21eb3020
Reviewed-on: https://go-review.googlesource.com/c/net/+/209417
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
  • Loading branch information
fhs authored and bradfitz committed Dec 4, 2019
1 parent ef20fe5 commit 5ee1b9f
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions http2/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,10 @@ func testTransportReqBodyAfterResponse(t *testing.T, status int) {
ct := newClientTester(t)
ct.client = func() error {
defer ct.cc.(*net.TCPConn).CloseWrite()
if runtime.GOOS == "plan9" {
// CloseWrite not supported on Plan 9; Issue 17906
defer ct.cc.(*net.TCPConn).Close()
}
defer close(clientDone)

var n int64 // atomic
Expand Down Expand Up @@ -2693,6 +2697,10 @@ func testTransportUsesGoAwayDebugError(t *testing.T, failMidBody bool) {
ct.fr.WriteGoAway(5, ErrCodeNo, []byte(goAwayDebugData))
ct.fr.WriteGoAway(5, goAwayErrCode, nil)
ct.sc.(*net.TCPConn).CloseWrite()
if runtime.GOOS == "plan9" {
// CloseWrite not supported on Plan 9; Issue 17906
ct.sc.(*net.TCPConn).Close()
}
<-clientDone
return nil
}
Expand Down Expand Up @@ -2821,6 +2829,10 @@ func TestTransportAdjustsFlowControl(t *testing.T) {

ct.client = func() error {
defer ct.cc.(*net.TCPConn).CloseWrite()
if runtime.GOOS == "plan9" {
// CloseWrite not supported on Plan 9; Issue 17906
defer ct.cc.(*net.TCPConn).Close()
}
defer close(clientDone)

req, _ := http.NewRequest("POST", "https://dummy.tld/", struct{ io.Reader }{io.LimitReader(neverEnding('A'), bodySize)})
Expand Down Expand Up @@ -3449,6 +3461,10 @@ func TestTransportRetryAfterRefusedStream(t *testing.T) {
ct := newClientTester(t)
ct.client = func() error {
defer ct.cc.(*net.TCPConn).CloseWrite()
if runtime.GOOS == "plan9" {
// CloseWrite not supported on Plan 9; Issue 17906
defer ct.cc.(*net.TCPConn).Close()
}
defer close(clientDone)
req, _ := http.NewRequest("GET", "https://dummy.tld/", nil)
resp, err := ct.tr.RoundTrip(req)
Expand Down Expand Up @@ -3515,6 +3531,10 @@ func TestTransportRetryHasLimit(t *testing.T) {
ct := newClientTester(t)
ct.client = func() error {
defer ct.cc.(*net.TCPConn).CloseWrite()
if runtime.GOOS == "plan9" {
// CloseWrite not supported on Plan 9; Issue 17906
defer ct.cc.(*net.TCPConn).Close()
}
defer close(clientDone)
req, _ := http.NewRequest("GET", "https://dummy.tld/", nil)
resp, err := ct.tr.RoundTrip(req)
Expand Down Expand Up @@ -3563,6 +3583,10 @@ func TestTransportResponseDataBeforeHeaders(t *testing.T) {
ct := newClientTester(t)
ct.client = func() error {
defer ct.cc.(*net.TCPConn).CloseWrite()
if runtime.GOOS == "plan9" {
// CloseWrite not supported on Plan 9; Issue 17906
defer ct.cc.(*net.TCPConn).Close()
}
req := httptest.NewRequest("GET", "https://dummy.tld/", nil)
// First request is normal to ensure the check is per stream and not per connection.
_, err := ct.tr.RoundTrip(req)
Expand Down Expand Up @@ -3675,6 +3699,10 @@ func TestTransportRequestsStallAtServerLimit(t *testing.T) {
wg.Wait()
close(clientDone)
ct.cc.(*net.TCPConn).CloseWrite()
if runtime.GOOS == "plan9" {
// CloseWrite not supported on Plan 9; Issue 17906
ct.cc.(*net.TCPConn).Close()
}
}()
for k := 0; k < maxConcurrent+2; k++ {
wg.Add(1)
Expand Down Expand Up @@ -4295,6 +4323,10 @@ func testTransportBodyReadError(t *testing.T, body []byte) {
ct := newClientTester(t)
ct.client = func() error {
defer ct.cc.(*net.TCPConn).CloseWrite()
if runtime.GOOS == "plan9" {
// CloseWrite not supported on Plan 9; Issue 17906
defer ct.cc.(*net.TCPConn).Close()
}
defer close(clientDone)

checkNoStreams := func() error {
Expand Down Expand Up @@ -4383,6 +4415,10 @@ func TestTransportBodyEagerEndStream(t *testing.T) {
ct := newClientTester(t)
ct.client = func() error {
defer ct.cc.(*net.TCPConn).CloseWrite()
if runtime.GOOS == "plan9" {
// CloseWrite not supported on Plan 9; Issue 17906
defer ct.cc.(*net.TCPConn).Close()
}
body := strings.NewReader(reqBody)
req, err := http.NewRequest("PUT", "https://dummy.tld/", body)
if err != nil {
Expand Down

0 comments on commit 5ee1b9f

Please sign in to comment.