Skip to content

Commit 21015cf

Browse files
committed
all: enable disabled HTTP/2 tests
Update net/http to enable tests that pass with the latest update to the vendored x/net. Update a few tests: Windows apparently doesn't guarantee that time.Since(time.Now()) is >=0, so to set a definitely-expired write deadline, use a time firmly in the past rather than now. Put a backoff loop on TestServerReadTimeout to avoid failures when the timeout expires mid-TLS-handshake. (The TLS handshake timeout is set to min(ReadTimeout, WriteTimeout, ReadHeaderTimeout); there's no way to set a long TLS handshake timeout and a short read timeout.) Don't close the http.Server in TestServerWriteTimeout while the handler may still be executing, since this can result in us getting the wrong error. Change the GOOS=js fake net implementation to properly return ErrDeadlineExceeded when a read/write deadline is exceeded, rather than EAGAIN. For #49837 For #54136 Change-Id: Id8a4ff6ac58336ff212dda3c8799b320cd6b9c19 Reviewed-on: https://go-review.googlesource.com/c/go/+/449935 Reviewed-by: Bryan Mills <[email protected]> Run-TryBot: Damien Neil <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent 69ca0a8 commit 21015cf

File tree

3 files changed

+28
-49
lines changed

3 files changed

+28
-49
lines changed

src/net/http/responsecontroller_test.go

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ import (
1313

1414
func TestResponseControllerFlush(t *testing.T) { run(t, testResponseControllerFlush) }
1515
func testResponseControllerFlush(t *testing.T, mode testMode) {
16-
if mode == http2Mode {
17-
t.Skip("skip until h2_bundle.go is updated")
18-
}
1916
continuec := make(chan struct{})
2017
cst := newClientServerTest(t, mode, HandlerFunc(func(w ResponseWriter, r *Request) {
2118
ctl := NewResponseController(w)
@@ -49,9 +46,6 @@ func testResponseControllerFlush(t *testing.T, mode testMode) {
4946

5047
func TestResponseControllerHijack(t *testing.T) { run(t, testResponseControllerHijack) }
5148
func testResponseControllerHijack(t *testing.T, mode testMode) {
52-
if mode == http2Mode {
53-
t.Skip("skip until h2_bundle.go is updated")
54-
}
5549
const header = "X-Header"
5650
const value = "set"
5751
cst := newClientServerTest(t, mode, HandlerFunc(func(w ResponseWriter, r *Request) {
@@ -83,16 +77,13 @@ func TestResponseControllerSetPastWriteDeadline(t *testing.T) {
8377
run(t, testResponseControllerSetPastWriteDeadline)
8478
}
8579
func testResponseControllerSetPastWriteDeadline(t *testing.T, mode testMode) {
86-
if mode == http2Mode {
87-
t.Skip("skip until h2_bundle.go is updated")
88-
}
8980
cst := newClientServerTest(t, mode, HandlerFunc(func(w ResponseWriter, r *Request) {
9081
ctl := NewResponseController(w)
9182
w.Write([]byte("one"))
9283
if err := ctl.Flush(); err != nil {
9384
t.Errorf("before setting deadline: ctl.Flush() = %v, want nil", err)
9485
}
95-
if err := ctl.SetWriteDeadline(time.Now()); err != nil {
86+
if err := ctl.SetWriteDeadline(time.Now().Add(-10 * time.Second)); err != nil {
9687
t.Errorf("ctl.SetWriteDeadline() = %v, want nil", err)
9788
}
9889

@@ -128,9 +119,6 @@ func TestResponseControllerSetFutureWriteDeadline(t *testing.T) {
128119
run(t, testResponseControllerSetFutureWriteDeadline)
129120
}
130121
func testResponseControllerSetFutureWriteDeadline(t *testing.T, mode testMode) {
131-
if mode == http2Mode {
132-
t.Skip("skip until h2_bundle.go is updated")
133-
}
134122
errc := make(chan error, 1)
135123
startwritec := make(chan struct{})
136124
cst := newClientServerTest(t, mode, HandlerFunc(func(w ResponseWriter, r *Request) {
@@ -167,9 +155,6 @@ func TestResponseControllerSetPastReadDeadline(t *testing.T) {
167155
run(t, testResponseControllerSetPastReadDeadline)
168156
}
169157
func testResponseControllerSetPastReadDeadline(t *testing.T, mode testMode) {
170-
if mode == http2Mode {
171-
t.Skip("skip until h2_bundle.go is updated")
172-
}
173158
readc := make(chan struct{})
174159
cst := newClientServerTest(t, mode, HandlerFunc(func(w ResponseWriter, r *Request) {
175160
ctl := NewResponseController(w)
@@ -223,9 +208,6 @@ func TestResponseControllerSetFutureReadDeadline(t *testing.T) {
223208
run(t, testResponseControllerSetFutureReadDeadline)
224209
}
225210
func testResponseControllerSetFutureReadDeadline(t *testing.T, mode testMode) {
226-
if mode == http2Mode {
227-
t.Skip("skip until h2_bundle.go is updated")
228-
}
229211
respBody := "response body"
230212
cst := newClientServerTest(t, mode, HandlerFunc(func(w ResponseWriter, req *Request) {
231213
ctl := NewResponseController(w)
@@ -261,9 +243,6 @@ func (w wrapWriter) Unwrap() ResponseWriter {
261243

262244
func TestWrappedResponseController(t *testing.T) { run(t, testWrappedResponseController) }
263245
func testWrappedResponseController(t *testing.T, mode testMode) {
264-
if mode == http2Mode {
265-
t.Skip("skip until h2_bundle.go is updated")
266-
}
267246
cst := newClientServerTest(t, mode, HandlerFunc(func(w ResponseWriter, r *Request) {
268247
ctl := NewResponseController(w)
269248
if err := ctl.Flush(); err != nil {

src/net/http/serve_test.go

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -738,37 +738,37 @@ func testServerTimeoutsWithTimeout(t *testing.T, timeout time.Duration, mode tes
738738

739739
func TestServerReadTimeout(t *testing.T) { run(t, testServerReadTimeout) }
740740
func testServerReadTimeout(t *testing.T, mode testMode) {
741-
if mode == http2Mode {
742-
t.Skip("https://go.dev/issue/49837")
743-
}
744741
respBody := "response body"
745-
cst := newClientServerTest(t, mode, HandlerFunc(func(res ResponseWriter, req *Request) {
746-
_, err := io.Copy(io.Discard, req.Body)
747-
if !errors.Is(err, os.ErrDeadlineExceeded) {
748-
t.Errorf("server timed out reading request body: got err %v; want os.ErrDeadlineExceeded", err)
742+
for timeout := 5 * time.Millisecond; ; timeout *= 2 {
743+
cst := newClientServerTest(t, mode, HandlerFunc(func(res ResponseWriter, req *Request) {
744+
_, err := io.Copy(io.Discard, req.Body)
745+
if !errors.Is(err, os.ErrDeadlineExceeded) {
746+
t.Errorf("server timed out reading request body: got err %v; want os.ErrDeadlineExceeded", err)
747+
}
748+
res.Write([]byte(respBody))
749+
}), func(ts *httptest.Server) {
750+
ts.Config.ReadHeaderTimeout = -1 // don't time out while reading headers
751+
ts.Config.ReadTimeout = timeout
752+
})
753+
pr, pw := io.Pipe()
754+
res, err := cst.c.Post(cst.ts.URL, "text/apocryphal", pr)
755+
if err != nil {
756+
t.Logf("Get error, retrying: %v", err)
757+
cst.close()
758+
continue
749759
}
750-
res.Write([]byte(respBody))
751-
}), func(ts *httptest.Server) {
752-
ts.Config.ReadTimeout = 5 * time.Millisecond
753-
})
754-
pr, pw := io.Pipe()
755-
res, err := cst.c.Post(cst.ts.URL, "text/apocryphal", pr)
756-
if err != nil {
757-
t.Fatal(err)
758-
}
759-
defer res.Body.Close()
760-
got, err := io.ReadAll(res.Body)
761-
if string(got) != respBody || err != nil {
762-
t.Errorf("client read response body: %q, %v; want %q, nil", string(got), err, respBody)
760+
defer res.Body.Close()
761+
got, err := io.ReadAll(res.Body)
762+
if string(got) != respBody || err != nil {
763+
t.Errorf("client read response body: %q, %v; want %q, nil", string(got), err, respBody)
764+
}
765+
pw.Close()
766+
break
763767
}
764-
pw.Close()
765768
}
766769

767770
func TestServerWriteTimeout(t *testing.T) { run(t, testServerWriteTimeout) }
768771
func testServerWriteTimeout(t *testing.T, mode testMode) {
769-
if mode == http2Mode {
770-
t.Skip("https://go.dev/issue/56478")
771-
}
772772
for timeout := 5 * time.Millisecond; ; timeout *= 2 {
773773
errc := make(chan error, 2)
774774
cst := newClientServerTest(t, mode, HandlerFunc(func(res ResponseWriter, req *Request) {
@@ -790,7 +790,6 @@ func testServerWriteTimeout(t *testing.T, mode testMode) {
790790
if err == nil {
791791
t.Errorf("client reading from truncated request body: got nil error, want non-nil")
792792
}
793-
cst.close()
794793
select {
795794
case <-errc:
796795
err = <-errc // io.Copy error
@@ -801,6 +800,7 @@ func testServerWriteTimeout(t *testing.T, mode testMode) {
801800
default:
802801
// The write timeout expired before the handler started.
803802
t.Logf("handler didn't run, retrying")
803+
cst.close()
804804
}
805805
}
806806
}

src/net/net_fake.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func (p *bufferedPipe) Read(b []byte) (int, error) {
194194
if !p.rDeadline.IsZero() {
195195
d := time.Until(p.rDeadline)
196196
if d <= 0 {
197-
return 0, syscall.EAGAIN
197+
return 0, os.ErrDeadlineExceeded
198198
}
199199
time.AfterFunc(d, p.rCond.Broadcast)
200200
}
@@ -221,7 +221,7 @@ func (p *bufferedPipe) Write(b []byte) (int, error) {
221221
if !p.wDeadline.IsZero() {
222222
d := time.Until(p.wDeadline)
223223
if d <= 0 {
224-
return 0, syscall.EAGAIN
224+
return 0, os.ErrDeadlineExceeded
225225
}
226226
time.AfterFunc(d, p.wCond.Broadcast)
227227
}

0 commit comments

Comments
 (0)