MCPcopy
hub / github.com/grpc/grpc-go / TestTwoGoAwayPingFrames

Method TestTwoGoAwayPingFrames

test/goaway_test.go:713–764  ·  view source on GitHub ↗

TestTwoGoAwayPingFrames tests the scenario where you get two go away ping frames from the client during graceful shutdown. This should not crash the server.

(t *testing.T)

Source from the content-addressed store, hash-verified

711// frames from the client during graceful shutdown. This should not crash the
712// server.
713func (s) TestTwoGoAwayPingFrames(t *testing.T) {
714 lis, err := net.Listen("tcp", "localhost:0")
715 if err != nil {
716 t.Fatalf("Failed to listen: %v", err)
717 }
718 defer lis.Close()
719 s := grpc.NewServer()
720 defer s.Stop()
721 go s.Serve(lis)
722
723 conn, err := net.DialTimeout("tcp", lis.Addr().String(), defaultTestTimeout)
724 if err != nil {
725 t.Fatalf("Failed to dial: %v", err)
726 }
727
728 st := newServerTesterFromConn(t, conn)
729 st.greet()
730 pingReceivedClientSide := testutils.NewChannel()
731 go func() {
732 for {
733 f, err := st.readFrame()
734 if err != nil {
735 return
736 }
737 switch f.(type) {
738 case *http2.GoAwayFrame:
739 case *http2.PingFrame:
740 pingReceivedClientSide.Send(nil)
741 default:
742 t.Errorf("server tester received unexpected frame type %T", f)
743 }
744 }
745 }()
746 gsDone := testutils.NewChannel()
747 go func() {
748 s.GracefulStop()
749 gsDone.Send(nil)
750 }()
751 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
752 defer cancel()
753 if _, err := pingReceivedClientSide.Receive(ctx); err != nil {
754 t.Fatalf("Error waiting for ping frame client side from graceful shutdown: %v", err)
755 }
756 // Write two goaway pings here.
757 st.writePing(true, [8]byte{1, 6, 1, 8, 0, 3, 3, 9})
758 st.writePing(true, [8]byte{1, 6, 1, 8, 0, 3, 3, 9})
759 // Close the conn to finish up the Graceful Shutdown process.
760 conn.Close()
761 if _, err := gsDone.Receive(ctx); err != nil {
762 t.Fatalf("Error waiting for graceful shutdown of the server: %v", err)
763 }
764}
765
766// TestClientSendsAGoAway tests the scenario where you get a go away ping
767// frames from the client during graceful shutdown.

Callers

nothing calls this directly

Calls 15

SendMethod · 0.95
ReceiveMethod · 0.95
NewServerFunction · 0.92
NewChannelFunction · 0.92
newServerTesterFromConnFunction · 0.85
writePingMethod · 0.80
FatalfMethod · 0.65
CloseMethod · 0.65
StopMethod · 0.65
ServeMethod · 0.65
StringMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected