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

Function DoPingPong

interop/test_utils.go:179–220  ·  view source on GitHub ↗

DoPingPong performs ping-pong style bi-directional streaming RPC.

(ctx context.Context, tc testgrpc.TestServiceClient, args ...grpc.CallOption)

Source from the content-addressed store, hash-verified

177
178// DoPingPong performs ping-pong style bi-directional streaming RPC.
179func DoPingPong(ctx context.Context, tc testgrpc.TestServiceClient, args ...grpc.CallOption) {
180 stream, err := tc.FullDuplexCall(ctx, args...)
181 if err != nil {
182 logger.Fatalf("%v.FullDuplexCall(_) = _, %v", tc, err)
183 }
184 var index int
185 for index < len(reqSizes) {
186 respParam := []*testpb.ResponseParameters{
187 {
188 Size: int32(respSizes[index]),
189 },
190 }
191 pl := ClientNewPayload(testpb.PayloadType_COMPRESSABLE, reqSizes[index])
192 req := &testpb.StreamingOutputCallRequest{
193 ResponseType: testpb.PayloadType_COMPRESSABLE,
194 ResponseParameters: respParam,
195 Payload: pl,
196 }
197 if err := stream.Send(req); err != nil {
198 logger.Fatalf("%v has error %v while sending %v", stream, err, req)
199 }
200 reply, err := stream.Recv()
201 if err != nil {
202 logger.Fatalf("%v.Recv() = %v", stream, err)
203 }
204 t := reply.GetPayload().GetType()
205 if t != testpb.PayloadType_COMPRESSABLE {
206 logger.Fatalf("Got the reply of type %d, want %d", t, testpb.PayloadType_COMPRESSABLE)
207 }
208 size := len(reply.GetPayload().GetBody())
209 if size != respSizes[index] {
210 logger.Fatalf("Got reply body of length %d, want %d", size, respSizes[index])
211 }
212 index++
213 }
214 if err := stream.CloseSend(); err != nil {
215 logger.Fatalf("%v.CloseSend() got %v, want %v", stream, err, nil)
216 }
217 if _, err := stream.Recv(); err != io.EOF {
218 logger.Fatalf("%v failed to complele the ping pong test: %v", stream, err)
219 }
220}
221
222// DoEmptyStream sets up a bi-directional streaming with zero message.
223func DoEmptyStream(ctx context.Context, tc testgrpc.TestServiceClient, args ...grpc.CallOption) {

Callers 3

mainFunction · 0.92
mainFunction · 0.92
performRPCsFunction · 0.92

Calls 9

ClientNewPayloadFunction · 0.85
FullDuplexCallMethod · 0.65
FatalfMethod · 0.65
SendMethod · 0.65
RecvMethod · 0.65
CloseSendMethod · 0.65
GetTypeMethod · 0.45
GetPayloadMethod · 0.45
GetBodyMethod · 0.45

Tested by

no test coverage detected