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

Method TestUnaryRPC_ClientCallSendMsgTwice

test/end2end_test.go:4023–4060  ·  view source on GitHub ↗

Tests the behavior for unary RPC when client calls SendMsg twice. Second call to SendMsg should fail with Internal error.

(t *testing.T)

Source from the content-addressed store, hash-verified

4021// Tests the behavior for unary RPC when client calls SendMsg twice. Second call
4022// to SendMsg should fail with Internal error.
4023func (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.

Callers

nothing calls this directly

Calls 12

StartMethod · 0.95
StopMethod · 0.95
SendMsgMethod · 0.95
NewClientFunction · 0.92
WithTransportCredentialsFunction · 0.92
NewCredentialsFunction · 0.92
CodeMethod · 0.80
FatalMethod · 0.65
FatalfMethod · 0.65
CloseMethod · 0.65
NewStreamMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected