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 disabled by server push-back.
35 // - 2 retries allowed for ABORTED status
36 // - first attempt gets ABORTED
37 // - second attempt gets ABORTED but server push back disables retrying
CORE_END2END_TEST(RetryTest,RetryServerPushbackDisabled)38 CORE_END2END_TEST(RetryTest, RetryServerPushbackDisabled) {
39 InitServer(ChannelArgs());
40 InitClient(ChannelArgs().Set(
41 GRPC_ARG_SERVICE_CONFIG,
42 "{\n"
43 " \"methodConfig\": [ {\n"
44 " \"name\": [\n"
45 " { \"service\": \"service\", \"method\": \"method\" }\n"
46 " ],\n"
47 " \"retryPolicy\": {\n"
48 " \"maxAttempts\": 3,\n"
49 " \"initialBackoff\": \"1s\",\n"
50 " \"maxBackoff\": \"120s\",\n"
51 " \"backoffMultiplier\": 1.6,\n"
52 " \"retryableStatusCodes\": [ \"ABORTED\" ]\n"
53 " }\n"
54 " } ]\n"
55 "}"));
56 auto c =
57 NewClientCall("/service/method").Timeout(Duration::Seconds(5)).Create();
58 EXPECT_NE(c.GetPeer(), absl::nullopt);
59 IncomingMetadata server_initial_metadata;
60 IncomingMessage server_message;
61 IncomingStatusOnClient server_status;
62 c.NewBatch(1)
63 .SendInitialMetadata({})
64 .SendMessage("foo")
65 .RecvMessage(server_message)
66 .SendCloseFromClient()
67 .RecvInitialMetadata(server_initial_metadata)
68 .RecvStatusOnClient(server_status);
69 absl::optional<IncomingCall> s = RequestCall(101);
70 Expect(101, true);
71 Step();
72 EXPECT_NE(s->GetPeer(), absl::nullopt);
73 EXPECT_NE(c.GetPeer(), absl::nullopt);
74 IncomingCloseOnServer client_close;
75 s->NewBatch(102)
76 .SendInitialMetadata({})
77 .SendStatusFromServer(GRPC_STATUS_ABORTED, "xyz", {})
78 .RecvCloseOnServer(client_close);
79 Expect(102, true);
80 Step();
81 s.reset();
82 s.emplace(RequestCall(201));
83 Expect(201, true);
84 Step();
85 EXPECT_NE(s->GetPeer(), absl::nullopt);
86 EXPECT_NE(c.GetPeer(), absl::nullopt);
87 IncomingCloseOnServer client_close2;
88 s->NewBatch(202)
89 .SendInitialMetadata({})
90 .SendStatusFromServer(GRPC_STATUS_ABORTED, "xyz",
91 {{"grpc-retry-pushback-ms", "-1"}})
92 .RecvCloseOnServer(client_close2);
93 Expect(202, true);
94 Expect(1, true);
95 Step();
96 EXPECT_EQ(server_status.status(), GRPC_STATUS_ABORTED);
97 EXPECT_EQ(server_status.message(), "xyz");
98 EXPECT_EQ(s->method(), "/service/method");
99 EXPECT_FALSE(client_close2.was_cancelled());
100 }
101
102 } // namespace
103 } // namespace grpc_core
104