@@ -3738,7 +3738,7 @@ func (s) TestClientStreaming_ReturnErrorAfterSendAndClose(t *testing.T) {
37383738 }
37393739}
37403740
3741- // Tests that a client receives a cardinality violation error for unary
3741+ // Tests that client receives a cardinality violation error for unary
37423742// RPCs if the server doesn't send a message before returning status OK.
37433743func (s ) TestUnaryRPC_ServerSendsOnlyTrailersWithOK (t * testing.T ) {
37443744 lis , err := testutils .LocalTCPListener ()
@@ -3769,8 +3769,8 @@ func (s) TestUnaryRPC_ServerSendsOnlyTrailersWithOK(t *testing.T) {
37693769 }
37703770}
37713771
3772- // Tests that client will receive cardinality violations when calling
3773- // RecvMsg() multiple times for non-streaming response streams .
3772+ // Tests the behavior for unary RPC when client calls RecvMsg() twice.
3773+ // Second call to RecvMsg should fail with io.EOF .
37743774func (s ) TestUnaryRPC_ClientCallRecvMsgTwice (t * testing.T ) {
37753775 e := tcpTLSEnv
37763776 te := newTest (t , e )
@@ -3801,13 +3801,67 @@ func (s) TestUnaryRPC_ClientCallRecvMsgTwice(t *testing.T) {
38013801 t .Fatalf ("stream.RecvMsg() = %v , want <nil>" , err )
38023802 }
38033803
3804- if err = stream .RecvMsg (resp ); status .Code (err ) != codes .Internal {
3804+ if err = stream .RecvMsg (resp ); err != io .EOF {
3805+ t .Errorf ("stream.RecvMsg() = %v, want error %v" , err , io .EOF )
3806+ }
3807+ }
3808+
3809+ // Tests the behavior for unary RPC when server calls SendMsg() twice.
3810+ // Client should fail with cardinality violation error.
3811+ func (s ) TestUnaryRPC_ServerCallSendMsgTwice (t * testing.T ) {
3812+ lis , err := testutils .LocalTCPListener ()
3813+ if err != nil {
3814+ t .Fatal (err )
3815+ }
3816+ defer lis .Close ()
3817+
3818+ s := grpc .NewServer ()
3819+ serviceDesc := grpc.ServiceDesc {
3820+ ServiceName : "grpc.testing.TestService" ,
3821+ HandlerType : (* any )(nil ),
3822+ Methods : []grpc.MethodDesc {},
3823+ Streams : []grpc.StreamDesc {
3824+ {
3825+ StreamName : "UnaryCall" ,
3826+ Handler : func (_ any , stream grpc.ServerStream ) error {
3827+ if err := stream .RecvMsg (& testpb.Empty {}); err != nil {
3828+ t .Errorf ("stream.RecvMsg() = %v, want <nil>" , err )
3829+ }
3830+
3831+ if err = stream .SendMsg (& testpb.Empty {}); err != nil {
3832+ t .Errorf ("stream.SendMsg() = %v, want <nil>" , err )
3833+ }
3834+
3835+ if err = stream .SendMsg (& testpb.Empty {}); err != nil {
3836+ t .Errorf ("stream.SendMsg() = %v, want <nil>" , err )
3837+ }
3838+ return nil
3839+ },
3840+ ClientStreams : false ,
3841+ ServerStreams : false ,
3842+ },
3843+ },
3844+ }
3845+ s .RegisterService (& serviceDesc , & testServer {})
3846+ go s .Serve (lis )
3847+ defer s .Stop ()
3848+
3849+ ctx , cancel := context .WithTimeout (context .Background (), defaultTestTimeout )
3850+ defer cancel ()
3851+ cc , err := grpc .NewClient (lis .Addr ().String (), grpc .WithTransportCredentials (insecure .NewCredentials ()))
3852+ if err != nil {
3853+ t .Fatalf ("grpc.NewClient(%q) failed unexpectedly: %v" , lis .Addr (), err )
3854+ }
3855+ defer cc .Close ()
3856+
3857+ client := testgrpc .NewTestServiceClient (cc )
3858+ if _ , err = client .UnaryCall (ctx , & testpb.SimpleRequest {}); status .Code (err ) != codes .Internal {
38053859 t .Errorf ("stream.RecvMsg() = %v, want error %v" , status .Code (err ), codes .Internal )
38063860 }
38073861}
38083862
3809- // Tests that client will receive cardinality violations when calling
3810- // RecvMsg() multiple times for non-streaming response streams .
3863+ // Tests the behavior for client-streaming RPC when client calls RecvMsg() twice.
3864+ // Second call to RecvMsg should fail with io.EOF .
38113865func (s ) TestClientStreaming_ClientCallRecvMsgTwice (t * testing.T ) {
38123866 ss := stubserver.StubServer {
38133867 StreamingInputCallF : func (stream testgrpc.TestService_StreamingInputCallServer ) error {
@@ -3838,8 +3892,8 @@ func (s) TestClientStreaming_ClientCallRecvMsgTwice(t *testing.T) {
38383892 if err := stream .RecvMsg (resp ); err != nil {
38393893 t .Fatalf ("stream.RecvMsg() = %v , want <nil>" , err )
38403894 }
3841- if err = stream .RecvMsg (resp ); status . Code ( err ) != codes . Internal {
3842- t .Errorf ("stream.RecvMsg() = %v, want error %v" , status . Code ( err ), codes . Internal )
3895+ if err = stream .RecvMsg (resp ); err != io . EOF {
3896+ t .Errorf ("stream.RecvMsg() = %v, want error %v" , err , io . EOF )
38433897 }
38443898}
38453899
0 commit comments