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

Method TestRetryStreaming

test/retry_test.go:181–498  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

179}
180
181func (s) TestRetryStreaming(t *testing.T) {
182 req := func(b byte) *testpb.StreamingOutputCallRequest {
183 return &testpb.StreamingOutputCallRequest{Payload: &testpb.Payload{Body: []byte{b}}}
184 }
185 res := func(b byte) *testpb.StreamingOutputCallResponse {
186 return &testpb.StreamingOutputCallResponse{Payload: &testpb.Payload{Body: []byte{b}}}
187 }
188
189 largePayload, _ := newPayload(testpb.PayloadType_COMPRESSABLE, 500)
190
191 type serverOp func(stream testgrpc.TestService_FullDuplexCallServer) error
192 type clientOp func(stream testgrpc.TestService_FullDuplexCallClient) error
193
194 // Server Operations
195 sAttempts := func(n int) serverOp {
196 return func(stream testgrpc.TestService_FullDuplexCallServer) error {
197 const key = "grpc-previous-rpc-attempts"
198 md, ok := metadata.FromIncomingContext(stream.Context())
199 if !ok {
200 return status.Errorf(codes.Internal, "server: no header metadata received")
201 }
202 if got := md[key]; len(got) != 1 || got[0] != strconv.Itoa(n) {
203 return status.Errorf(codes.Internal, "server: metadata = %v; want <contains %q: %q>", md, key, n)
204 }
205 return nil
206 }
207 }
208 sReq := func(b byte) serverOp {
209 return func(stream testgrpc.TestService_FullDuplexCallServer) error {
210 want := req(b)
211 if got, err := stream.Recv(); err != nil || !proto.Equal(got, want) {
212 return status.Errorf(codes.Internal, "server: Recv() = %v, %v; want %v, <nil>", got, err, want)
213 }
214 return nil
215 }
216 }
217 sReqPayload := func(p *testpb.Payload) serverOp {
218 return func(stream testgrpc.TestService_FullDuplexCallServer) error {
219 want := &testpb.StreamingOutputCallRequest{Payload: p}
220 if got, err := stream.Recv(); err != nil || !proto.Equal(got, want) {
221 return status.Errorf(codes.Internal, "server: Recv() = %v, %v; want %v, <nil>", got, err, want)
222 }
223 return nil
224 }
225 }
226 sHdr := func() serverOp {
227 return func(stream testgrpc.TestService_FullDuplexCallServer) error {
228 return stream.SendHeader(metadata.Pairs("test_header", "test_value"))
229 }
230 }
231 sRes := func(b byte) serverOp {
232 return func(stream testgrpc.TestService_FullDuplexCallServer) error {
233 msg := res(b)
234 if err := stream.Send(msg); err != nil {
235 return status.Errorf(codes.Internal, "server: Send(%v) = %v; want <nil>", msg, err)
236 }
237 return nil
238 }

Callers

nothing calls this directly

Calls 15

StartMethod · 0.95
StopMethod · 0.95
FromIncomingContextFunction · 0.92
ErrorfFunction · 0.92
PairsFunction · 0.92
NewFunction · 0.92
CodeFunction · 0.92
WithDefaultCallOptionsFunction · 0.92
MaxRetryRPCBufferSizeFunction · 0.92
WithDefaultServiceConfigFunction · 0.92
newPayloadFunction · 0.85
ErrMethod · 0.80

Tested by

no test coverage detected