xref: /aosp_15_r20/external/grpc-grpc/test/core/end2end/tests/retry_disabled.cc (revision cc02d7e222339f7a4f6ba5f422e6413f4bd931f2)
1 //
2 //
3 // Copyright 2017 gRPC authors.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 //
18 
19 #include <memory>
20 
21 #include "absl/types/optional.h"
22 #include "gtest/gtest.h"
23 
24 #include <grpc/impl/channel_arg_names.h>
25 #include <grpc/status.h>
26 
27 #include "src/core/lib/channel/channel_args.h"
28 #include "src/core/lib/gprpp/time.h"
29 #include "test/core/end2end/end2end_tests.h"
30 
31 namespace grpc_core {
32 namespace {
33 
34 // Tests that we don't retry when retries are disabled via the
35 // GRPC_ARG_ENABLE_RETRIES channel arg, even when there is retry
36 // configuration in the service config.
37 // - 1 retry allowed for ABORTED status
38 // - first attempt returns ABORTED but does not retry
CORE_END2END_TEST(RetryTest,RetryDisabled)39 CORE_END2END_TEST(RetryTest, RetryDisabled) {
40   InitServer(ChannelArgs());
41   InitClient(
42       ChannelArgs()
43           .Set(GRPC_ARG_ENABLE_RETRIES, false)
44           .Set(GRPC_ARG_SERVICE_CONFIG,
45                "{\n"
46                "  \"methodConfig\": [ {\n"
47                "    \"name\": [\n"
48                "      { \"service\": \"service\", \"method\": \"method\" }\n"
49                "    ],\n"
50                "    \"retryPolicy\": {\n"
51                "      \"maxAttempts\": 2,\n"
52                "      \"initialBackoff\": \"1s\",\n"
53                "      \"maxBackoff\": \"120s\",\n"
54                "      \"backoffMultiplier\": 1.6,\n"
55                "      \"retryableStatusCodes\": [ \"ABORTED\" ]\n"
56                "    }\n"
57                "  } ]\n"
58                "}"));
59   auto c =
60       NewClientCall("/service/method").Timeout(Duration::Seconds(5)).Create();
61   EXPECT_NE(c.GetPeer(), absl::nullopt);
62   IncomingMetadata server_initial_metadata;
63   IncomingMessage server_message;
64   IncomingStatusOnClient server_status;
65   c.NewBatch(1)
66       .SendInitialMetadata({})
67       .SendMessage("foo")
68       .RecvMessage(server_message)
69       .SendCloseFromClient()
70       .RecvInitialMetadata(server_initial_metadata)
71       .RecvStatusOnClient(server_status);
72   auto s = RequestCall(101);
73   Expect(101, true);
74   Step();
75   EXPECT_NE(s.GetPeer(), absl::nullopt);
76   EXPECT_NE(c.GetPeer(), absl::nullopt);
77   IncomingCloseOnServer client_close;
78   s.NewBatch(102)
79       .SendInitialMetadata({})
80       .SendStatusFromServer(GRPC_STATUS_ABORTED, "xyz", {})
81       .RecvCloseOnServer(client_close);
82   Expect(102, true);
83   Expect(1, true);
84   Step();
85   EXPECT_EQ(server_status.status(), GRPC_STATUS_ABORTED);
86   EXPECT_EQ(server_status.message(), "xyz");
87   EXPECT_EQ(s.method(), "/service/method");
88   EXPECT_FALSE(client_close.was_cancelled());
89 }
90 
91 }  // namespace
92 }  // namespace grpc_core
93