]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: add test that panic in a handler signals an error to the client
authorBrad Fitzpatrick <bradfitz@golang.org>
Tue, 12 Apr 2016 00:22:39 +0000 (00:22 +0000)
committerBrad Fitzpatrick <bradfitz@golang.org>
Tue, 12 Apr 2016 23:33:00 +0000 (23:33 +0000)
Change-Id: Iba40edc9ddad62534b06c5af20bbc3dd3dc14d0a
Reviewed-on: https://go-review.googlesource.com/21881
Reviewed-by: Andrew Gerrand <adg@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/net/http/clientserver_test.go

index c2bab378e3a33ef51c925305fa96bf60b85dacf3..f7213823650131a92ab67188549ba01ee5feb1da 100644 (file)
@@ -1123,6 +1123,34 @@ func testBogusStatusWorks(t *testing.T, h2 bool) {
        }
 }
 
+func TestInterruptWithPanic_h1(t *testing.T) { testInterruptWithPanic(t, h1Mode) }
+func TestInterruptWithPanic_h2(t *testing.T) { testInterruptWithPanic(t, h2Mode) }
+func testInterruptWithPanic(t *testing.T, h2 bool) {
+       log.SetOutput(ioutil.Discard) // is noisy otherwise
+       defer log.SetOutput(os.Stderr)
+
+       const msg = "hello"
+       defer afterTest(t)
+       cst := newClientServerTest(t, h2, HandlerFunc(func(w ResponseWriter, r *Request) {
+               io.WriteString(w, msg)
+               w.(Flusher).Flush()
+               panic("no more")
+       }))
+       defer cst.close()
+       res, err := cst.c.Get(cst.ts.URL)
+       if err != nil {
+               t.Fatal(err)
+       }
+       defer res.Body.Close()
+       slurp, err := ioutil.ReadAll(res.Body)
+       if string(slurp) != msg {
+               t.Errorf("client read %q; want %q", slurp, msg)
+       }
+       if err == nil {
+               t.Errorf("client read all successfully; want some error")
+       }
+}
+
 type noteCloseConn struct {
        net.Conn
        closeFunc func()