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

Function testPingPong

test/end2end_test.go:3219–3270  ·  view source on GitHub ↗
(t *testing.T, e env)

Source from the content-addressed store, hash-verified

3217}
3218
3219func testPingPong(t *testing.T, e env) {
3220 te := newTest(t, e)
3221 te.startServer(&testServer{security: e.security})
3222 defer te.tearDown()
3223 tc := testgrpc.NewTestServiceClient(te.clientConn())
3224
3225 stream, err := tc.FullDuplexCall(te.ctx)
3226 if err != nil {
3227 t.Fatalf("%v.FullDuplexCall(_) = _, %v, want <nil>", tc, err)
3228 }
3229 var index int
3230 for index < len(reqSizes) {
3231 respParam := []*testpb.ResponseParameters{
3232 {
3233 Size: int32(respSizes[index]),
3234 },
3235 }
3236
3237 payload, err := newPayload(testpb.PayloadType_COMPRESSABLE, int32(reqSizes[index]))
3238 if err != nil {
3239 t.Fatal(err)
3240 }
3241
3242 req := &testpb.StreamingOutputCallRequest{
3243 ResponseType: testpb.PayloadType_COMPRESSABLE,
3244 ResponseParameters: respParam,
3245 Payload: payload,
3246 }
3247 if err := stream.Send(req); err != nil {
3248 t.Fatalf("%v.Send(%v) = %v, want <nil>", stream, req, err)
3249 }
3250 reply, err := stream.Recv()
3251 if err != nil {
3252 t.Fatalf("%v.Recv() = %v, want <nil>", stream, err)
3253 }
3254 pt := reply.GetPayload().GetType()
3255 if pt != testpb.PayloadType_COMPRESSABLE {
3256 t.Fatalf("Got the reply of type %d, want %d", pt, testpb.PayloadType_COMPRESSABLE)
3257 }
3258 size := len(reply.GetPayload().GetBody())
3259 if size != int(respSizes[index]) {
3260 t.Fatalf("Got reply body of length %d, want %d", size, respSizes[index])
3261 }
3262 index++
3263 }
3264 if err := stream.CloseSend(); err != nil {
3265 t.Fatalf("%v.CloseSend() got %v, want %v", stream, err, nil)
3266 }
3267 if _, err := stream.Recv(); err != io.EOF {
3268 t.Fatalf("%v failed to complele the ping pong test: %v", stream, err)
3269 }
3270}
3271
3272func (s) TestMetadataStreamingRPC(t *testing.T) {
3273 for _, e := range listTestEnv() {

Callers 1

TestPingPongMethod · 0.70

Calls 14

FullDuplexCallMethod · 0.95
newPayloadFunction · 0.85
newTestFunction · 0.70
FatalfMethod · 0.65
FatalMethod · 0.65
SendMethod · 0.65
RecvMethod · 0.65
CloseSendMethod · 0.65
startServerMethod · 0.45
tearDownMethod · 0.45
clientConnMethod · 0.45
GetTypeMethod · 0.45

Tested by

no test coverage detected