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

Method TestFlowControlLogicalRace

test/end2end_test.go:4962–5026  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

4960}
4961
4962func (s) TestFlowControlLogicalRace(t *testing.T) {
4963 // Test for a regression of https://github.com/grpc/grpc-go/issues/632,
4964 // and other flow control bugs.
4965
4966 const (
4967 itemCount = 100
4968 itemSize = 1 << 10
4969 recvCount = 2
4970 maxFailures = 3
4971 )
4972
4973 requestCount := 3000
4974 if raceMode {
4975 requestCount = 1000
4976 }
4977
4978 lis, err := net.Listen("tcp", "localhost:0")
4979 if err != nil {
4980 t.Fatalf("Failed to listen: %v", err)
4981 }
4982 defer lis.Close()
4983
4984 s := grpc.NewServer()
4985 testgrpc.RegisterTestServiceServer(s, &flowControlLogicalRaceServer{
4986 itemCount: itemCount,
4987 itemSize: itemSize,
4988 })
4989 defer s.Stop()
4990
4991 go s.Serve(lis)
4992
4993 cc, err := grpc.NewClient(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
4994 if err != nil {
4995 t.Fatalf("grpc.NewClient(%q) = %v", lis.Addr().String(), err)
4996 }
4997 defer cc.Close()
4998 cl := testgrpc.NewTestServiceClient(cc)
4999
5000 failures := 0
5001 for i := 0; i < requestCount; i++ {
5002 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
5003 output, err := cl.StreamingOutputCall(ctx, &testpb.StreamingOutputCallRequest{})
5004 if err != nil {
5005 t.Fatalf("StreamingOutputCall; err = %q", err)
5006 }
5007
5008 for j := 0; j < recvCount; j++ {
5009 if _, err := output.Recv(); err != nil {
5010 if err == io.EOF || status.Code(err) == codes.DeadlineExceeded {
5011 t.Errorf("got %d responses to request %d", j, i)
5012 failures++
5013 break
5014 }
5015 t.Fatalf("Recv; err = %q", err)
5016 }
5017 }
5018 cancel()
5019

Callers

nothing calls this directly

Calls 14

StreamingOutputCallMethod · 0.95
NewServerFunction · 0.92
NewClientFunction · 0.92
WithTransportCredentialsFunction · 0.92
NewCredentialsFunction · 0.92
CodeMethod · 0.80
FatalfMethod · 0.65
CloseMethod · 0.65
StopMethod · 0.65
ServeMethod · 0.65
StringMethod · 0.65
RecvMethod · 0.65

Tested by

no test coverage detected