mirror of
https://github.com/golang/go
synced 2024-11-23 20:00:04 -07:00
net/http: add test that panic in a handler signals an error to the client
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>
This commit is contained in:
parent
982274c96d
commit
a0ab6cd685
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user