Tests the behavior for unary RPC when client calls SendMsg twice. Second call to SendMsg should fail with Internal error.
(t *testing.T)
| 4021 | // Tests the behavior for unary RPC when client calls SendMsg twice. Second call |
| 4022 | // to SendMsg should fail with Internal error. |
| 4023 | func (s) TestUnaryRPC_ClientCallSendMsgTwice(t *testing.T) { |
| 4024 | ss := stubserver.StubServer{ |
| 4025 | UnaryCallF: func(context.Context, *testpb.SimpleRequest) (*testpb.SimpleResponse, error) { |
| 4026 | return &testpb.SimpleResponse{}, nil |
| 4027 | }, |
| 4028 | } |
| 4029 | if err := ss.Start(nil); err != nil { |
| 4030 | t.Fatal("Error starting server:", err) |
| 4031 | } |
| 4032 | defer ss.Stop() |
| 4033 | |
| 4034 | ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) |
| 4035 | defer cancel() |
| 4036 | cc, err := grpc.NewClient(ss.Address, grpc.WithTransportCredentials(local.NewCredentials())) |
| 4037 | if err != nil { |
| 4038 | t.Fatalf("grpc.NewClient(%q) failed unexpectedly: %v", ss.Address, err) |
| 4039 | } |
| 4040 | defer cc.Close() |
| 4041 | |
| 4042 | desc := &grpc.StreamDesc{ |
| 4043 | StreamName: "UnaryCall", |
| 4044 | ServerStreams: false, |
| 4045 | ClientStreams: false, |
| 4046 | } |
| 4047 | |
| 4048 | stream, err := cc.NewStream(ctx, desc, "/grpc.testing.TestService/UnaryCall") |
| 4049 | if err != nil { |
| 4050 | t.Fatalf("cc.NewStream() failed unexpectedly: %v", err) |
| 4051 | } |
| 4052 | |
| 4053 | if err := stream.SendMsg(&testpb.Empty{}); err != nil { |
| 4054 | t.Errorf("stream.SendMsg() = %v, want <nil>", err) |
| 4055 | } |
| 4056 | |
| 4057 | if err := stream.SendMsg(&testpb.Empty{}); status.Code(err) != codes.Internal { |
| 4058 | t.Errorf("stream.SendMsg() = %v, want error %v", status.Code(err), codes.Internal) |
| 4059 | } |
| 4060 | } |
| 4061 | |
| 4062 | // Tests the behavior for server-side streaming RPC when client misbehaves as Bidi-streaming |
| 4063 | // and sends multiple messages. |
nothing calls this directly
no test coverage detected