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

Method TestStreamingRPCWithTimeoutInServiceConfigRecv

test/end2end_test.go:1643–1709  ·  view source on GitHub ↗

Reading from a streaming RPC may fail with context canceled if timeout was set by service config (https://github.com/grpc/grpc-go/issues/1818). This test makes sure read from streaming RPC doesn't fail in this case.

(t *testing.T)

Source from the content-addressed store, hash-verified

1641// set by service config (https://github.com/grpc/grpc-go/issues/1818). This
1642// test makes sure read from streaming RPC doesn't fail in this case.
1643func (s) TestStreamingRPCWithTimeoutInServiceConfigRecv(t *testing.T) {
1644 te := testServiceConfigSetup(t, tcpClearRREnv)
1645 te.startServer(&testServer{security: tcpClearRREnv.security})
1646 defer te.tearDown()
1647 r := manual.NewBuilderWithScheme("whatever")
1648
1649 te.resolverScheme = r.Scheme()
1650 cc := te.clientConn(grpc.WithResolvers(r))
1651 tc := testgrpc.NewTestServiceClient(cc)
1652
1653 r.UpdateState(resolver.State{
1654 Addresses: []resolver.Address{{Addr: te.srvAddr}},
1655 ServiceConfig: parseServiceConfig(t, r, `{
1656 "methodConfig": [
1657 {
1658 "name": [
1659 {
1660 "service": "grpc.testing.TestService",
1661 "method": "FullDuplexCall"
1662 }
1663 ],
1664 "waitForReady": true,
1665 "timeout": "10s"
1666 }
1667 ]
1668 }`)})
1669 // Make sure service config has been processed by grpc.
1670 for {
1671 if cc.GetMethodConfig("/grpc.testing.TestService/FullDuplexCall").Timeout != nil {
1672 break
1673 }
1674 time.Sleep(time.Millisecond)
1675 }
1676
1677 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
1678 defer cancel()
1679 stream, err := tc.FullDuplexCall(ctx, grpc.WaitForReady(true))
1680 if err != nil {
1681 t.Fatalf("TestService/FullDuplexCall(_) = _, %v, want <nil>", err)
1682 }
1683
1684 payload, err := newPayload(testpb.PayloadType_COMPRESSABLE, 0)
1685 if err != nil {
1686 t.Fatalf("failed to newPayload: %v", err)
1687 }
1688 req := &testpb.StreamingOutputCallRequest{
1689 ResponseType: testpb.PayloadType_COMPRESSABLE,
1690 ResponseParameters: []*testpb.ResponseParameters{{Size: 0}},
1691 Payload: payload,
1692 }
1693 if err := stream.Send(req); err != nil {
1694 t.Fatalf("stream.Send(%v) = %v, want <nil>", req, err)
1695 }
1696 stream.CloseSend()
1697 time.Sleep(time.Second)
1698 // Sleep 1 second before recv to make sure the final status is received
1699 // before the recv.
1700 if _, err := stream.Recv(); err != nil {

Callers

nothing calls this directly

Calls 15

FullDuplexCallMethod · 0.95
NewBuilderWithSchemeFunction · 0.92
WithResolversFunction · 0.92
WaitForReadyFunction · 0.92
testServiceConfigSetupFunction · 0.85
newPayloadFunction · 0.85
GetMethodConfigMethod · 0.80
parseServiceConfigFunction · 0.70
SchemeMethod · 0.65
UpdateStateMethod · 0.65
FatalfMethod · 0.65
SendMethod · 0.65

Tested by

no test coverage detected