Skip to content

Commit c2ef005

Browse files
committed
net/http: run more tests in http2 mode
Failing ones are marked skipped. Fixes #13543 (was just a test issue) Updates #13555 (to be fixed later) Updates #13556 (to be fixed later) Updates #13557 (to be fixed later) Fixes bug in golang.org/cl/17428 (http1 now uses HTTP status 431, not 413) Change-Id: I8f7431fee35f2fc081cfe2c232ae75a00800a60b Reviewed-on: https://go-review.googlesource.com/17683 Reviewed-by: Blake Mizerany <[email protected]> Reviewed-by: Emmanuel Odeke <[email protected]> Reviewed-by: Burcu Dogan <[email protected]> Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 07f9c25 commit c2ef005

File tree

7 files changed

+144
-105
lines changed

7 files changed

+144
-105
lines changed

src/net/http/client_test.go

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ func TestClient(t *testing.T) {
8383
}
8484
}
8585

86-
func TestClientHead_h1(t *testing.T) { testClientHead(t, false) }
87-
func TestClientHead_h2(t *testing.T) { testClientHead(t, true) }
86+
func TestClientHead_h1(t *testing.T) { testClientHead(t, h1Mode) }
87+
func TestClientHead_h2(t *testing.T) { testClientHead(t, h2Mode) }
8888

8989
func testClientHead(t *testing.T, h2 bool) {
9090
defer afterTest(t)
@@ -496,8 +496,8 @@ func (j *RecordingJar) logf(format string, args ...interface{}) {
496496
fmt.Fprintf(&j.log, format, args...)
497497
}
498498

499-
func TestStreamingGet_h1(t *testing.T) { testStreamingGet(t, false) }
500-
func TestStreamingGet_h2(t *testing.T) { testStreamingGet(t, true) }
499+
func TestStreamingGet_h1(t *testing.T) { testStreamingGet(t, h1Mode) }
500+
func TestStreamingGet_h2(t *testing.T) { testStreamingGet(t, h2Mode) }
501501

502502
func testStreamingGet(t *testing.T, h2 bool) {
503503
defer afterTest(t)
@@ -772,11 +772,11 @@ func TestHTTPSClientDetectsHTTPServer(t *testing.T) {
772772

773773
// Verify Response.ContentLength is populated. https://golang.org/issue/4126
774774
func TestClientHeadContentLength_h1(t *testing.T) {
775-
testClientHeadContentLength(t, false)
775+
testClientHeadContentLength(t, h1Mode)
776776
}
777777

778778
func TestClientHeadContentLength_h2(t *testing.T) {
779-
testClientHeadContentLength(t, true)
779+
testClientHeadContentLength(t, h2Mode)
780780
}
781781

782782
func testClientHeadContentLength(t *testing.T, h2 bool) {
@@ -1037,14 +1037,8 @@ func TestClientTimeout_Headers(t *testing.T) {
10371037
}
10381038
}
10391039

1040-
func TestClientRedirectEatsBody_h1(t *testing.T) {
1041-
testClientRedirectEatsBody(t, false)
1042-
}
1043-
1044-
func TestClientRedirectEatsBody_h2(t *testing.T) {
1045-
testClientRedirectEatsBody(t, true)
1046-
}
1047-
1040+
func TestClientRedirectEatsBody_h1(t *testing.T) { testClientRedirectEatsBody(t, h1Mode) }
1041+
func TestClientRedirectEatsBody_h2(t *testing.T) { testClientRedirectEatsBody(t, h2Mode) }
10481042
func testClientRedirectEatsBody(t *testing.T, h2 bool) {
10491043
defer afterTest(t)
10501044
saw := make(chan string, 2)
@@ -1093,9 +1087,14 @@ func (f eofReaderFunc) Read(p []byte) (n int, err error) {
10931087
return 0, io.EOF
10941088
}
10951089

1096-
func TestClientTrailers(t *testing.T) {
1090+
func TestClientTrailers_h1(t *testing.T) { testClientTrailers(t, h1Mode) }
1091+
func TestClientTrailers_h2(t *testing.T) {
1092+
t.Skip("skipping in http2 mode; golang.org/issue/13557")
1093+
testClientTrailers(t, h2Mode)
1094+
}
1095+
func testClientTrailers(t *testing.T, h2 bool) {
10971096
defer afterTest(t)
1098-
ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) {
1097+
cst := newClientServerTest(t, h2, HandlerFunc(func(w ResponseWriter, r *Request) {
10991098
w.Header().Set("Connection", "close")
11001099
w.Header().Set("Trailer", "Server-Trailer-A, Server-Trailer-B")
11011100
w.Header().Add("Trailer", "Server-Trailer-C")
@@ -1129,10 +1128,10 @@ func TestClientTrailers(t *testing.T) {
11291128
w.Header().Set("Server-Trailer-A", "valuea")
11301129
w.Header().Set("Server-Trailer-C", "valuec") // skipping B
11311130
}))
1132-
defer ts.Close()
1131+
defer cst.close()
11331132

11341133
var req *Request
1135-
req, _ = NewRequest("POST", ts.URL, io.MultiReader(
1134+
req, _ = NewRequest("POST", cst.ts.URL, io.MultiReader(
11361135
eofReaderFunc(func() {
11371136
req.Trailer["Client-Trailer-A"] = []string{"valuea"}
11381137
}),
@@ -1146,7 +1145,7 @@ func TestClientTrailers(t *testing.T) {
11461145
"Client-Trailer-B": nil, // to be set later
11471146
}
11481147
req.ContentLength = -1
1149-
res, err := DefaultClient.Do(req)
1148+
res, err := cst.c.Do(req)
11501149
if err != nil {
11511150
t.Fatal(err)
11521151
}

src/net/http/clientserver_test.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ func (t *clientServerTest) close() {
3737
t.ts.Close()
3838
}
3939

40+
const (
41+
h1Mode = false
42+
h2Mode = true
43+
)
44+
4045
func newClientServerTest(t *testing.T, h2 bool, h Handler) *clientServerTest {
4146
cst := &clientServerTest{
4247
t: t,
@@ -87,8 +92,8 @@ func TestNewClientServerTest(t *testing.T) {
8792
}
8893
}
8994

90-
func TestChunkedResponseHeaders_h1(t *testing.T) { testChunkedResponseHeaders(t, false) }
91-
func TestChunkedResponseHeaders_h2(t *testing.T) { testChunkedResponseHeaders(t, true) }
95+
func TestChunkedResponseHeaders_h1(t *testing.T) { testChunkedResponseHeaders(t, h1Mode) }
96+
func TestChunkedResponseHeaders_h2(t *testing.T) { testChunkedResponseHeaders(t, h2Mode) }
9297

9398
func testChunkedResponseHeaders(t *testing.T, h2 bool) {
9499
defer afterTest(t)
@@ -354,8 +359,6 @@ func TestH12_HandlerWritesTooMuch(t *testing.T) {
354359
}.run(t)
355360
}
356361

357-
// TODO: TestH12_Trailers
358-
359362
// Verify that both our HTTP/1 and HTTP/2 request and auto-decompress gzip.
360363
// Some hosts send gzip even if you don't ask for it; see golang.org/issue/13298
361364
func TestH12_AutoGzip(t *testing.T) {
@@ -375,8 +378,8 @@ func TestH12_AutoGzip(t *testing.T) {
375378
// Test304Responses verifies that 304s don't declare that they're
376379
// chunking in their response headers and aren't allowed to produce
377380
// output.
378-
func Test304Responses_h1(t *testing.T) { test304Responses(t, false) }
379-
func Test304Responses_h2(t *testing.T) { test304Responses(t, true) }
381+
func Test304Responses_h1(t *testing.T) { test304Responses(t, h1Mode) }
382+
func Test304Responses_h2(t *testing.T) { test304Responses(t, h2Mode) }
380383

381384
func test304Responses(t *testing.T, h2 bool) {
382385
defer afterTest(t)

src/net/http/fs_test.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -477,14 +477,27 @@ func TestServeFileFromCWD(t *testing.T) {
477477
}
478478
}
479479

480-
func TestServeFileWithContentEncoding(t *testing.T) {
480+
// Tests that ServeFile doesn't add a Content-Length if a Content-Encoding is
481+
// specified.
482+
func TestServeFileWithContentEncoding_h1(t *testing.T) { testServeFileWithContentEncoding(t, h1Mode) }
483+
func TestServeFileWithContentEncoding_h2(t *testing.T) { testServeFileWithContentEncoding(t, h2Mode) }
484+
func testServeFileWithContentEncoding(t *testing.T, h2 bool) {
481485
defer afterTest(t)
482-
ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) {
486+
cst := newClientServerTest(t, h2, HandlerFunc(func(w ResponseWriter, r *Request) {
483487
w.Header().Set("Content-Encoding", "foo")
484488
ServeFile(w, r, "testdata/file")
489+
490+
// Because the testdata is so small, it would fit in
491+
// both the h1 and h2 Server's write buffers. For h1,
492+
// sendfile is used, though, forcing a header flush at
493+
// the io.Copy. http2 doesn't do a header flush so
494+
// buffers all 11 bytes and then adds its own
495+
// Content-Length. To prevent the Server's
496+
// Content-Length and test ServeFile only, flush here.
497+
w.(Flusher).Flush()
485498
}))
486-
defer ts.Close()
487-
resp, err := Get(ts.URL)
499+
defer cst.close()
500+
resp, err := cst.c.Get(cst.ts.URL)
488501
if err != nil {
489502
t.Fatal(err)
490503
}

src/net/http/request_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,8 @@ func TestParseMultipartForm(t *testing.T) {
176176
}
177177
}
178178

179-
func TestRedirect_h1(t *testing.T) { testRedirect(t, false) }
180-
func TestRedirect_h2(t *testing.T) { testRedirect(t, true) }
181-
179+
func TestRedirect_h1(t *testing.T) { testRedirect(t, h1Mode) }
180+
func TestRedirect_h2(t *testing.T) { testRedirect(t, h2Mode) }
182181
func testRedirect(t *testing.T, h2 bool) {
183182
defer afterTest(t)
184183
cst := newClientServerTest(t, h2, HandlerFunc(func(w ResponseWriter, r *Request) {

0 commit comments

Comments
 (0)