Commit b63ca1e9 authored by Kale Blankenship's avatar Kale Blankenship Committed by Brad Fitzpatrick

net/http: add test for http2 Server WriteTimeout

Current handling of WriteTimeout for http2 does not
extend the timeout on new streams. Disable the WriteTimeout
in http2 for 1.8 release.

Updates #18437

Change-Id: I20480432ab176f115464434645defb56ebeb6ece
Reviewed-on: https://go-review.googlesource.com/34723Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 9e199702
...@@ -535,6 +535,57 @@ func TestServerTimeouts(t *testing.T) { ...@@ -535,6 +535,57 @@ func TestServerTimeouts(t *testing.T) {
} }
} }
// Test that the HTTP/2 server handles Server.WriteTimeout (Issue 18437)
func TestHTTP2WriteDeadlineExtendedOnNewRequest(t *testing.T) {
t.Skip("disabled until Issue 18437 is fixed")
if testing.Short() {
t.Skip("skipping in short mode")
}
setParallel(t)
defer afterTest(t)
ts := httptest.NewUnstartedServer(HandlerFunc(func(res ResponseWriter, req *Request) {}))
ts.Config.WriteTimeout = 250 * time.Millisecond
ts.TLS = &tls.Config{NextProtos: []string{"h2"}}
ts.StartTLS()
defer ts.Close()
tr := newTLSTransport(t, ts)
defer tr.CloseIdleConnections()
if err := ExportHttp2ConfigureTransport(tr); err != nil {
t.Fatal(err)
}
c := &Client{Transport: tr}
for i := 1; i <= 3; i++ {
req, err := NewRequest("GET", ts.URL, nil)
if err != nil {
t.Fatal(err)
}
// fail test if no response after 1 second
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()
req = req.WithContext(ctx)
r, err := c.Do(req)
select {
case <-ctx.Done():
if ctx.Err() == context.DeadlineExceeded {
t.Fatalf("http2 Get #%d response timed out", i)
}
default:
}
if err != nil {
t.Fatalf("http2 Get #%d: %v", i, err)
}
r.Body.Close()
if r.ProtoMajor != 2 {
t.Fatalf("http2 Get expected HTTP/2.0, got %q", r.Proto)
}
time.Sleep(ts.Config.WriteTimeout / 2)
}
}
// golang.org/issue/4741 -- setting only a write timeout that triggers // golang.org/issue/4741 -- setting only a write timeout that triggers
// shouldn't cause a handler to block forever on reads (next HTTP // shouldn't cause a handler to block forever on reads (next HTTP
// request) that will never happen. // request) that will never happen.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment