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

Method TestNoRetry

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

Source from the content-addressed store, hash-verified

851}
852
853func (s) TestNoRetry(t *testing.T) {
854 scJSON := `{
855 "methodConfig": [{
856 "name": [{"service": "grpc.testing.TestService"}],
857 "retryPolicy": {
858 "MaxAttempts": 4,
859 "InitialBackoff": ".01s",
860 "MaxBackoff": ".01s",
861 "BackoffMultiplier": 1.0,
862 "RetryableStatusCodes": [ "UNAVAILABLE" ]
863 }
864 }]}`
865 tests := []struct {
866 name string
867 dialOpts []grpc.DialOption
868 }{
869 {
870 name: "disabled",
871 dialOpts: []grpc.DialOption{
872 grpc.WithDefaultServiceConfig(scJSON),
873 grpc.WithDisableRetry(),
874 },
875 },
876 {
877 name: "not_configured",
878 dialOpts: []grpc.DialOption{},
879 },
880 }
881
882 for _, tc := range tests {
883 t.Run(tc.name, func(t *testing.T) {
884 ss := &stubserver.StubServer{
885 FullDuplexCallF: func(testgrpc.TestService_FullDuplexCallServer) error {
886 return status.New(codes.Unavailable, "retryable error").Err()
887 },
888 EmptyCallF: func(context.Context, *testpb.Empty) (r *testpb.Empty, err error) {
889 return nil, status.New(codes.Unavailable, "retryable error").Err()
890 },
891 }
892 if err := ss.Start([]grpc.ServerOption{}, tc.dialOpts...); err != nil {
893 t.Fatalf("Error starting endpoint server: %v", err)
894 }
895 defer ss.Stop()
896
897 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
898 defer cancel()
899
900 // Test streaming RPC
901 stream, err := ss.Client.FullDuplexCall(ctx)
902 if err != nil {
903 t.Fatalf("Error while creating stream: %v", err)
904 }
905 _, err = stream.Recv()
906 if err == nil {
907 t.Fatal("stream.Recv() succeeded when expected to fail")
908 }
909 if status.Code(err) != codes.Unavailable {
910 t.Fatalf("client: Recv() = _, %v; want _, Unavailable", err)

Callers

nothing calls this directly

Calls 13

StartMethod · 0.95
StopMethod · 0.95
WithDefaultServiceConfigFunction · 0.92
WithDisableRetryFunction · 0.92
NewFunction · 0.92
CodeFunction · 0.92
ErrMethod · 0.80
FatalfMethod · 0.65
FullDuplexCallMethod · 0.65
RecvMethod · 0.65
FatalMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected