1 //
2 // Copyright 2017 gRPC authors.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 #include <memory>
18
19 #include "gtest/gtest.h"
20
21 #include <grpc/impl/channel_arg_names.h>
22 #include <grpc/status.h>
23
24 #include "src/core/lib/channel/channel_args.h"
25 #include "src/core/lib/gprpp/time.h"
26 #include "test/core/end2end/end2end_tests.h"
27
28 namespace grpc_core {
29 namespace {
30
31 // Tests a scenario where there is a batch containing both a send op and
32 // a recv op, where the send op completes but the recv op does not, and
33 // then a subsequent recv op is started. This ensures that we do not
34 // incorrectly attempt to replay the send op.
CORE_END2END_TEST(RetryTest,RetrySendRecvBatch)35 CORE_END2END_TEST(RetryTest, RetrySendRecvBatch) {
36 InitServer(ChannelArgs());
37 InitClient(ChannelArgs().Set(
38 GRPC_ARG_SERVICE_CONFIG,
39 "{\n"
40 " \"methodConfig\": [ {\n"
41 " \"name\": [\n"
42 " { \"service\": \"service\", \"method\": \"method\" }\n"
43 " ],\n"
44 " \"retryPolicy\": {\n"
45 " \"maxAttempts\": 3,\n"
46 " \"initialBackoff\": \"1s\",\n"
47 " \"maxBackoff\": \"120s\",\n"
48 " \"backoffMultiplier\": 1.6,\n"
49 " \"retryableStatusCodes\": [ \"ABORTED\" ]\n"
50 " }\n"
51 " } ]\n"
52 "}"));
53 auto c =
54 NewClientCall("/service/method").Timeout(Duration::Minutes(1)).Create();
55 // Client starts batch with send_initial_metadata and recv_initial_metadata.
56 IncomingMetadata server_initial_metadata;
57 c.NewBatch(1).SendInitialMetadata({}).RecvInitialMetadata(
58 server_initial_metadata);
59 // Client starts a batch with send_message and recv_trailing_metadata.
60 IncomingStatusOnClient server_status;
61 c.NewBatch(2).SendMessage("hello").RecvStatusOnClient(server_status);
62 // Server gets a call.
63 auto s = RequestCall(101);
64 Expect(101, true);
65 Step();
66 // Client starts a batch containing recv_message.
67 IncomingMessage server_message;
68 c.NewBatch(3).RecvMessage(server_message);
69 // Server fails the call with a non-retriable status.
70 IncomingCloseOnServer client_close;
71 s.NewBatch(102)
72 .SendInitialMetadata({})
73 .SendStatusFromServer(GRPC_STATUS_PERMISSION_DENIED, "xyz", {})
74 .RecvCloseOnServer(client_close);
75 Expect(102, true);
76 Expect(1, true);
77 Expect(2, true);
78 Expect(3, true);
79 Step();
80 EXPECT_EQ(server_status.status(), GRPC_STATUS_PERMISSION_DENIED);
81 EXPECT_EQ(server_status.message(), "xyz");
82 EXPECT_EQ(s.method(), "/service/method");
83 EXPECT_FALSE(client_close.was_cancelled());
84 }
85
86 } // namespace
87 } // namespace grpc_core
88