You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.3 KiB

  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.
  4. // +build go1.9
  5. package http2
  6. import (
  7. "context"
  8. "net/http"
  9. "reflect"
  10. "testing"
  11. "time"
  12. )
  13. func TestServerGracefulShutdown(t *testing.T) {
  14. var st *serverTester
  15. handlerDone := make(chan struct{})
  16. st = newServerTester(t, func(w http.ResponseWriter, r *http.Request) {
  17. defer close(handlerDone)
  18. go st.ts.Config.Shutdown(context.Background())
  19. ga := st.wantGoAway()
  20. if ga.ErrCode != ErrCodeNo {
  21. t.Errorf("GOAWAY error = %v; want ErrCodeNo", ga.ErrCode)
  22. }
  23. if ga.LastStreamID != 1 {
  24. t.Errorf("GOAWAY LastStreamID = %v; want 1", ga.LastStreamID)
  25. }
  26. w.Header().Set("x-foo", "bar")
  27. })
  28. defer st.Close()
  29. st.greet()
  30. st.bodylessReq1()
  31. select {
  32. case <-handlerDone:
  33. case <-time.After(5 * time.Second):
  34. t.Fatalf("server did not shutdown?")
  35. }
  36. hf := st.wantHeaders()
  37. goth := st.decodeHeader(hf.HeaderBlockFragment())
  38. wanth := [][2]string{
  39. {":status", "200"},
  40. {"x-foo", "bar"},
  41. {"content-length", "0"},
  42. }
  43. if !reflect.DeepEqual(goth, wanth) {
  44. t.Errorf("Got headers %v; want %v", goth, wanth)
  45. }
  46. n, err := st.cc.Read([]byte{0})
  47. if n != 0 || err == nil {
  48. t.Errorf("Read = %v, %v; want 0, non-nil", n, err)
  49. }
  50. }