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

Method TestGoAwayStreamIDSmallerThanCreatedStreams

test/goaway_test.go:658–708  ·  view source on GitHub ↗

TestGoAwayStreamIDSmallerThanCreatedStreams tests the scenario where a server sends a goaway with a stream id that is smaller than some created streams on the client, while the client is simultaneously creating new streams. This should not induce a deadlock.

(t *testing.T)

Source from the content-addressed store, hash-verified

656// the client, while the client is simultaneously creating new streams. This
657// should not induce a deadlock.
658func (s) TestGoAwayStreamIDSmallerThanCreatedStreams(t *testing.T) {
659 lis, err := net.Listen("tcp", "localhost:0")
660 if err != nil {
661 t.Fatalf("error listening: %v", err)
662 }
663
664 ctCh := testutils.NewChannel()
665 go func() {
666 conn, err := lis.Accept()
667 if err != nil {
668 t.Errorf("error in lis.Accept(): %v", err)
669 }
670 ct := newClientTester(t, conn)
671 ctCh.Send(ct)
672 }()
673
674 cc, err := grpc.NewClient(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
675 if err != nil {
676 t.Fatalf("grpc.NewClient(%q) = %v", lis.Addr().String(), err)
677 }
678 defer cc.Close()
679 cc.Connect()
680
681 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
682 defer cancel()
683
684 val, err := ctCh.Receive(ctx)
685 if err != nil {
686 t.Fatalf("timeout waiting for client transport (should be given after http2 creation)")
687 }
688 ct := val.(*clientTester)
689
690 tc := testgrpc.NewTestServiceClient(cc)
691 someStreamsCreated := grpcsync.NewEvent()
692 goAwayWritten := grpcsync.NewEvent()
693 go func() {
694 for i := 0; i < 20; i++ {
695 if i == 10 {
696 <-goAwayWritten.Done()
697 }
698 tc.FullDuplexCall(ctx)
699 if i == 4 {
700 someStreamsCreated.Fire()
701 }
702 }
703 }()
704
705 <-someStreamsCreated.Done()
706 ct.writeGoAway(1, http2.ErrCodeNo, []byte{})
707 goAwayWritten.Fire()
708}
709
710// TestTwoGoAwayPingFrames tests the scenario where you get two go away ping
711// frames from the client during graceful shutdown. This should not crash the

Callers

nothing calls this directly

Calls 15

SendMethod · 0.95
ReceiveMethod · 0.95
DoneMethod · 0.95
FullDuplexCallMethod · 0.95
FireMethod · 0.95
NewChannelFunction · 0.92
NewClientFunction · 0.92
WithTransportCredentialsFunction · 0.92
NewCredentialsFunction · 0.92
NewEventFunction · 0.92
newClientTesterFunction · 0.85
FatalfMethod · 0.65

Tested by

no test coverage detected