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 <grpc/impl/channel_arg_names.h>
20 #include <grpc/status.h>
21
22 #include <memory>
23
24 #include "absl/types/optional.h"
25 #include "gtest/gtest.h"
26 #include "src/core/lib/channel/channel_args.h"
27 #include "src/core/util/time.h"
28 #include "test/core/end2end/end2end_tests.h"
29
30 namespace grpc_core {
31 namespace {
32
33 // Tests that we don't retry when retries are disabled via the
34 // GRPC_ARG_ENABLE_RETRIES channel arg, even when there is retry
35 // configuration in the service config.
36 // - 1 retry allowed for ABORTED status
37 // - first attempt returns ABORTED but does not retry
CORE_END2END_TEST(RetryTest,RetryDisabled)38 CORE_END2END_TEST(RetryTest, RetryDisabled) {
39 InitServer(ChannelArgs());
40 InitClient(
41 ChannelArgs()
42 .Set(GRPC_ARG_ENABLE_RETRIES, false)
43 .Set(GRPC_ARG_SERVICE_CONFIG,
44 "{\n"
45 " \"methodConfig\": [ {\n"
46 " \"name\": [\n"
47 " { \"service\": \"service\", \"method\": \"method\" }\n"
48 " ],\n"
49 " \"retryPolicy\": {\n"
50 " \"maxAttempts\": 2,\n"
51 " \"initialBackoff\": \"1s\",\n"
52 " \"maxBackoff\": \"120s\",\n"
53 " \"backoffMultiplier\": 1.6,\n"
54 " \"retryableStatusCodes\": [ \"ABORTED\" ]\n"
55 " }\n"
56 " } ]\n"
57 "}"));
58 auto c =
59 NewClientCall("/service/method").Timeout(Duration::Seconds(5)).Create();
60 EXPECT_NE(c.GetPeer(), absl::nullopt);
61 IncomingMetadata server_initial_metadata;
62 IncomingMessage server_message;
63 IncomingStatusOnClient server_status;
64 c.NewBatch(1)
65 .SendInitialMetadata({})
66 .SendMessage("foo")
67 .RecvMessage(server_message)
68 .SendCloseFromClient()
69 .RecvInitialMetadata(server_initial_metadata)
70 .RecvStatusOnClient(server_status);
71 auto s = RequestCall(101);
72 Expect(101, true);
73 Step();
74 EXPECT_NE(s.GetPeer(), absl::nullopt);
75 EXPECT_NE(c.GetPeer(), absl::nullopt);
76 IncomingCloseOnServer client_close;
77 s.NewBatch(102)
78 .SendInitialMetadata({})
79 .SendStatusFromServer(GRPC_STATUS_ABORTED, "xyz", {})
80 .RecvCloseOnServer(client_close);
81 Expect(102, true);
82 Expect(1, true);
83 Step();
84 EXPECT_EQ(server_status.status(), GRPC_STATUS_ABORTED);
85 EXPECT_EQ(server_status.message(), "xyz");
86 EXPECT_EQ(s.method(), "/service/method");
87 EXPECT_FALSE(client_close.was_cancelled());
88 }
89
90 } // namespace
91 } // namespace grpc_core
92