DoServerStreaming performs a server streaming RPC.
(ctx context.Context, tc testgrpc.TestServiceClient, args ...grpc.CallOption)
| 133 | |
| 134 | // DoServerStreaming performs a server streaming RPC. |
| 135 | func DoServerStreaming(ctx context.Context, tc testgrpc.TestServiceClient, args ...grpc.CallOption) { |
| 136 | respParam := make([]*testpb.ResponseParameters, len(respSizes)) |
| 137 | for i, s := range respSizes { |
| 138 | respParam[i] = &testpb.ResponseParameters{ |
| 139 | Size: int32(s), |
| 140 | } |
| 141 | } |
| 142 | req := &testpb.StreamingOutputCallRequest{ |
| 143 | ResponseType: testpb.PayloadType_COMPRESSABLE, |
| 144 | ResponseParameters: respParam, |
| 145 | } |
| 146 | stream, err := tc.StreamingOutputCall(ctx, req, args...) |
| 147 | if err != nil { |
| 148 | logger.Fatalf("%v.StreamingOutputCall(_) = _, %v", tc, err) |
| 149 | } |
| 150 | var rpcStatus error |
| 151 | var respCnt int |
| 152 | var index int |
| 153 | for { |
| 154 | reply, err := stream.Recv() |
| 155 | if err != nil { |
| 156 | rpcStatus = err |
| 157 | break |
| 158 | } |
| 159 | t := reply.GetPayload().GetType() |
| 160 | if t != testpb.PayloadType_COMPRESSABLE { |
| 161 | logger.Fatalf("Got the reply of type %d, want %d", t, testpb.PayloadType_COMPRESSABLE) |
| 162 | } |
| 163 | size := len(reply.GetPayload().GetBody()) |
| 164 | if size != respSizes[index] { |
| 165 | logger.Fatalf("Got reply body of length %d, want %d", size, respSizes[index]) |
| 166 | } |
| 167 | index++ |
| 168 | respCnt++ |
| 169 | } |
| 170 | if rpcStatus != io.EOF { |
| 171 | logger.Fatalf("Failed to finish the server streaming rpc: %v", rpcStatus) |
| 172 | } |
| 173 | if respCnt != len(respSizes) { |
| 174 | logger.Fatalf("Got %d reply, want %d", len(respSizes), respCnt) |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | // DoPingPong performs ping-pong style bi-directional streaming RPC. |
| 179 | func DoPingPong(ctx context.Context, tc testgrpc.TestServiceClient, args ...grpc.CallOption) { |
no test coverage detected