diff options
author | Andrew Gerrand <adg@golang.org> | 2011-10-19 08:23:13 +1100 |
---|---|---|
committer | Andrew Gerrand <adg@golang.org> | 2011-10-19 08:23:13 +1100 |
commit | aa42881ed03c23b89f7eab87768f8669851bc0cc (patch) | |
tree | e82d94e4b774ea87f27af6648a373464dff3eda6 | |
parent | b1fd528db5305d85c6dfabd8ff7d0656c7f97a39 (diff) | |
download | go-aa42881ed03c23b89f7eab87768f8669851bc0cc.tar.gz go-aa42881ed03c23b89f7eab87768f8669851bc0cc.zip |
http: add test for panic inside hijacked request
R=golang-dev, rsc, rsc
CC=golang-dev
https://golang.org/cl/5283052
-rw-r--r-- | src/pkg/http/serve_test.go | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/pkg/http/serve_test.go b/src/pkg/http/serve_test.go index 731a3279f0..2ff66d5ce5 100644 --- a/src/pkg/http/serve_test.go +++ b/src/pkg/http/serve_test.go @@ -864,6 +864,14 @@ func TestZeroLengthPostAndResponse(t *testing.T) { } func TestHandlerPanic(t *testing.T) { + testHandlerPanic(t, false) +} + +func TestHandlerPanicWithHijack(t *testing.T) { + testHandlerPanic(t, true) +} + +func testHandlerPanic(t *testing.T, withHijack bool) { // Unlike the other tests that set the log output to ioutil.Discard // to quiet the output, this test uses a pipe. The pipe serves three // purposes: @@ -884,7 +892,14 @@ func TestHandlerPanic(t *testing.T) { log.SetOutput(pw) defer log.SetOutput(os.Stderr) - ts := httptest.NewServer(HandlerFunc(func(ResponseWriter, *Request) { + ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) { + if withHijack { + rwc, _, err := w.(Hijacker).Hijack() + if err != nil { + t.Logf("unexpected error: %v", err) + } + defer rwc.Close() + } panic("intentional death for testing") })) defer ts.Close() |