1 // Copyright 2017 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
17 func TestServerGracefulShutdown(t *testing.T) {
19 handlerDone := make(chan struct{})
20 st = newServerTester(t, func(w http.ResponseWriter, r *http.Request) {
21 defer close(handlerDone)
22 go st.ts.Config.Shutdown(context.Background())
25 if ga.ErrCode != ErrCodeNo {
26 t.Errorf("GOAWAY error = %v; want ErrCodeNo", ga.ErrCode)
28 if ga.LastStreamID != 1 {
29 t.Errorf("GOAWAY LastStreamID = %v; want 1", ga.LastStreamID)
32 w.Header().Set("x-foo", "bar")
41 case <-time.After(5 * time.Second):
42 t.Fatalf("server did not shutdown?")
44 hf := st.wantHeaders()
45 goth := st.decodeHeader(hf.HeaderBlockFragment())
49 {"content-type", "text/plain; charset=utf-8"},
50 {"content-length", "0"},
52 if !reflect.DeepEqual(goth, wanth) {
53 t.Errorf("Got headers %v; want %v", goth, wanth)
56 n, err := st.cc.Read([]byte{0})
57 if n != 0 || err == nil {
58 t.Errorf("Read = %v, %v; want 0, non-nil", n, err)