DoPingPong performs ping-pong style bi-directional streaming RPC.
(ctx context.Context, tc testgrpc.TestServiceClient, args ...grpc.CallOption)
| 177 | |
| 178 | // DoPingPong performs ping-pong style bi-directional streaming RPC. |
| 179 | func 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. |
| 223 | func DoEmptyStream(ctx context.Context, tc testgrpc.TestServiceClient, args ...grpc.CallOption) { |
no test coverage detected