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

Function DoCancelAfterFirstResponse

interop/test_utils.go:462–489  ·  view source on GitHub ↗

DoCancelAfterFirstResponse cancels the RPC after receiving the first message from the server.

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

Source from the content-addressed store, hash-verified

460
461// DoCancelAfterFirstResponse cancels the RPC after receiving the first message from the server.
462func DoCancelAfterFirstResponse(ctx context.Context, tc testgrpc.TestServiceClient, args ...grpc.CallOption) {
463 ctx, cancel := context.WithCancel(ctx)
464 stream, err := tc.FullDuplexCall(ctx, args...)
465 if err != nil {
466 logger.Fatalf("%v.FullDuplexCall(_) = _, %v", tc, err)
467 }
468 respParam := []*testpb.ResponseParameters{
469 {
470 Size: 31415,
471 },
472 }
473 pl := ClientNewPayload(testpb.PayloadType_COMPRESSABLE, 27182)
474 req := &testpb.StreamingOutputCallRequest{
475 ResponseType: testpb.PayloadType_COMPRESSABLE,
476 ResponseParameters: respParam,
477 Payload: pl,
478 }
479 if err := stream.Send(req); err != nil {
480 logger.Fatalf("%v has error %v while sending %v", stream, err, req)
481 }
482 if _, err := stream.Recv(); err != nil {
483 logger.Fatalf("%v.Recv() = %v", stream, err)
484 }
485 cancel()
486 if _, err := stream.Recv(); status.Code(err) != codes.Canceled {
487 logger.Fatalf("%v compleled with error code %d, want %d", stream, status.Code(err), codes.Canceled)
488 }
489}
490
491var (
492 initialMetadataValue = "test_initial_metadata_value"

Callers 2

mainFunction · 0.92
performRPCsFunction · 0.92

Calls 6

CodeFunction · 0.92
ClientNewPayloadFunction · 0.85
FullDuplexCallMethod · 0.65
FatalfMethod · 0.65
SendMethod · 0.65
RecvMethod · 0.65

Tested by

no test coverage detected