blob: 029bdc8bce162b515d21fd90fd1ce31153186ebb [file] [log] [blame]
Craig Tiller0220cf12015-02-12 17:39:26 -08001/*
2 *
Craig Tiller6169d5f2016-03-31 07:46:18 -07003 * Copyright 2015, Google Inc.
Craig Tiller0220cf12015-02-12 17:39:26 -08004 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following disclaimer
14 * in the documentation and/or other materials provided with the
15 * distribution.
16 * * Neither the name of Google Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
33
Yang Gaoda699b82015-02-18 01:10:22 -080034#include <memory>
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -080035#include <thread>
Craig Tiller0220cf12015-02-12 17:39:26 -080036
yang-g8c2be9f2015-08-19 16:28:09 -070037#include <grpc++/channel.h>
Craig Tiller0220cf12015-02-12 17:39:26 -080038#include <grpc++/client_context.h>
39#include <grpc++/create_channel.h>
Craig Tiller0220cf12015-02-12 17:39:26 -080040#include <grpc++/server.h>
41#include <grpc++/server_builder.h>
42#include <grpc++/server_context.h>
Sree Kuchibhotlab0d0c8e2016-01-13 22:52:17 -080043#include <grpc/grpc.h>
44#include <grpc/support/thd.h>
45#include <grpc/support/time.h>
Vijay Paib65eda42016-02-16 13:48:05 -080046#include <grpc/support/tls.h>
Craig Tiller0220cf12015-02-12 17:39:26 -080047#include <gtest/gtest.h>
48
Craig Tiller1b4e3302015-12-17 16:35:00 -080049#include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h"
50#include "src/proto/grpc/testing/echo.grpc.pb.h"
Sree Kuchibhotlab0d0c8e2016-01-13 22:52:17 -080051#include "test/core/util/port.h"
52#include "test/core/util/test_config.h"
yang-ge21908f2015-08-25 13:47:51 -070053#include "test/cpp/util/string_ref_helper.h"
Vijay Paidf8b62c2016-05-02 14:34:24 -070054#include "test/cpp/util/test_credentials_provider.h"
Craig Tiller0220cf12015-02-12 17:39:26 -080055
Craig Tiller69f90e62015-08-06 08:32:35 -070056#ifdef GPR_POSIX_SOCKET
Craig Tillerf45496f2016-03-30 07:41:19 -070057#include "src/core/lib/iomgr/ev_posix.h"
Craig Tiller69f90e62015-08-06 08:32:35 -070058#endif
59
Craig Tiller1b4e3302015-12-17 16:35:00 -080060using grpc::testing::EchoRequest;
61using grpc::testing::EchoResponse;
Vijay Paidf8b62c2016-05-02 14:34:24 -070062using grpc::testing::kTlsCredentialsType;
Craig Tiller0220cf12015-02-12 17:39:26 -080063using std::chrono::system_clock;
64
Vijay Paib65eda42016-02-16 13:48:05 -080065GPR_TLS_DECL(g_is_async_end2end_test);
66
Craig Tiller0220cf12015-02-12 17:39:26 -080067namespace grpc {
68namespace testing {
69
70namespace {
71
Craig Tiller7536af02015-12-22 13:49:30 -080072void* tag(int i) { return (void*)(intptr_t)i; }
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -080073int detag(void* p) { return static_cast<int>(reinterpret_cast<intptr_t>(p)); }
Yang Gaoc05b6cb2015-02-13 00:34:10 -080074
Craig Tiller69f90e62015-08-06 08:32:35 -070075#ifdef GPR_POSIX_SOCKET
Vijay Paib65eda42016-02-16 13:48:05 -080076static int maybe_assert_non_blocking_poll(struct pollfd* pfds, nfds_t nfds,
77 int timeout) {
78 if (gpr_tls_get(&g_is_async_end2end_test)) {
79 GPR_ASSERT(timeout == 0);
80 }
81 return poll(pfds, nfds, timeout);
Craig Tiller69f90e62015-08-06 08:32:35 -070082}
83
84class PollOverride {
Craig Tiller06cf3cc2015-05-13 13:11:01 -070085 public:
Craig Tiller69f90e62015-08-06 08:32:35 -070086 PollOverride(grpc_poll_function_type f) {
87 prev_ = grpc_poll_function;
88 grpc_poll_function = f;
89 }
90
Craig Tiller4c06b822015-08-06 08:41:31 -070091 ~PollOverride() { grpc_poll_function = prev_; }
Craig Tiller69f90e62015-08-06 08:32:35 -070092
93 private:
94 grpc_poll_function_type prev_;
95};
96
vjpaicf4daeb2016-02-15 02:33:54 -080097class PollingOverrider : public PollOverride {
Craig Tiller69f90e62015-08-06 08:32:35 -070098 public:
vjpaicf4daeb2016-02-15 02:33:54 -080099 explicit PollingOverrider(bool allow_blocking)
Vijay Paib65eda42016-02-16 13:48:05 -0800100 : PollOverride(allow_blocking ? poll : maybe_assert_non_blocking_poll) {}
Craig Tiller69f90e62015-08-06 08:32:35 -0700101};
102#else
vjpaicf4daeb2016-02-15 02:33:54 -0800103class PollingOverrider {
Craig Tiller69f90e62015-08-06 08:32:35 -0700104 public:
vjpaicf4daeb2016-02-15 02:33:54 -0800105 explicit PollingOverrider(bool allow_blocking) {}
Craig Tiller69f90e62015-08-06 08:32:35 -0700106};
107#endif
108
vjpaicf4daeb2016-02-15 02:33:54 -0800109class Verifier {
Craig Tiller69f90e62015-08-06 08:32:35 -0700110 public:
vjpaicf4daeb2016-02-15 02:33:54 -0800111 explicit Verifier(bool spin) : spin_(spin) {}
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -0800112 // Expect sets the expected ok value for a specific tag
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700113 Verifier& Expect(int i, bool expect_ok) {
114 expectations_[tag(i)] = expect_ok;
115 return *this;
vjpai7aadf462015-03-16 23:58:44 -0700116 }
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800117
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -0800118 // Next waits for 1 async tag to complete, checks its
119 // expectations, and returns the tag
120 int Next(CompletionQueue* cq, bool ignore_ok) {
121 bool ok;
122 void* got_tag;
123 if (spin_) {
124 for (;;) {
125 auto r = cq->AsyncNext(&got_tag, &ok, gpr_time_0(GPR_CLOCK_REALTIME));
126 if (r == CompletionQueue::TIMEOUT) continue;
127 if (r == CompletionQueue::GOT_EVENT) break;
128 gpr_log(GPR_ERROR, "unexpected result from AsyncNext");
129 abort();
130 }
131 } else {
132 EXPECT_TRUE(cq->Next(&got_tag, &ok));
133 }
134 auto it = expectations_.find(got_tag);
135 EXPECT_TRUE(it != expectations_.end());
136 if (!ignore_ok) {
137 EXPECT_EQ(it->second, ok);
138 }
139 expectations_.erase(it);
140 return detag(got_tag);
141 }
142
143 // Verify keeps calling Next until all currently set
144 // expected tags are complete
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800145 void Verify(CompletionQueue* cq) { Verify(cq, false); }
146
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -0800147 // This version of Verify allows optionally ignoring the
148 // outcome of the expectation
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800149 void Verify(CompletionQueue* cq, bool ignore_ok) {
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700150 GPR_ASSERT(!expectations_.empty());
151 while (!expectations_.empty()) {
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -0800152 Next(cq, ignore_ok);
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700153 }
154 }
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -0800155 // This version of Verify stops after a certain deadline
Craig Tillerd6c98df2015-08-18 09:33:44 -0700156 void Verify(CompletionQueue* cq,
157 std::chrono::system_clock::time_point deadline) {
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700158 if (expectations_.empty()) {
159 bool ok;
Craig Tillerd6c98df2015-08-18 09:33:44 -0700160 void* got_tag;
Craig Tiller69f90e62015-08-06 08:32:35 -0700161 if (spin_) {
162 while (std::chrono::system_clock::now() < deadline) {
Craig Tiller4c06b822015-08-06 08:41:31 -0700163 EXPECT_EQ(
164 cq->AsyncNext(&got_tag, &ok, gpr_time_0(GPR_CLOCK_REALTIME)),
165 CompletionQueue::TIMEOUT);
Craig Tiller69f90e62015-08-06 08:32:35 -0700166 }
167 } else {
Craig Tiller4c06b822015-08-06 08:41:31 -0700168 EXPECT_EQ(cq->AsyncNext(&got_tag, &ok, deadline),
169 CompletionQueue::TIMEOUT);
Craig Tiller69f90e62015-08-06 08:32:35 -0700170 }
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700171 } else {
172 while (!expectations_.empty()) {
173 bool ok;
Craig Tillerd6c98df2015-08-18 09:33:44 -0700174 void* got_tag;
Craig Tiller69f90e62015-08-06 08:32:35 -0700175 if (spin_) {
176 for (;;) {
177 GPR_ASSERT(std::chrono::system_clock::now() < deadline);
Craig Tiller4c06b822015-08-06 08:41:31 -0700178 auto r =
179 cq->AsyncNext(&got_tag, &ok, gpr_time_0(GPR_CLOCK_REALTIME));
Craig Tiller69f90e62015-08-06 08:32:35 -0700180 if (r == CompletionQueue::TIMEOUT) continue;
181 if (r == CompletionQueue::GOT_EVENT) break;
182 gpr_log(GPR_ERROR, "unexpected result from AsyncNext");
183 abort();
Craig Tiller4c06b822015-08-06 08:41:31 -0700184 }
Craig Tiller69f90e62015-08-06 08:32:35 -0700185 } else {
Craig Tiller4c06b822015-08-06 08:41:31 -0700186 EXPECT_EQ(cq->AsyncNext(&got_tag, &ok, deadline),
187 CompletionQueue::GOT_EVENT);
Craig Tiller69f90e62015-08-06 08:32:35 -0700188 }
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700189 auto it = expectations_.find(got_tag);
190 EXPECT_TRUE(it != expectations_.end());
191 EXPECT_EQ(it->second, ok);
192 expectations_.erase(it);
193 }
194 }
195 }
196
197 private:
198 std::map<void*, bool> expectations_;
Craig Tiller69f90e62015-08-06 08:32:35 -0700199 bool spin_;
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700200};
vjpai7aadf462015-03-16 23:58:44 -0700201
Yuchen Zenga42ec212016-04-29 13:03:06 -0700202// This class disables the server builder plugins that may add sync services to
203// the server. If there are sync services, UnimplementedRpc test will triger
204// the sync unkown rpc routine on the server side, rather than the async one
205// that needs to be tested here.
206class ServerBuilderSyncPluginDisabler : public ::grpc::ServerBuilderOption {
207 public:
208 void UpdateArguments(ChannelArguments* arg) GRPC_OVERRIDE {}
209
vjpai97da6472016-06-13 09:56:26 -0700210 void UpdatePlugins(std::vector<std::unique_ptr<ServerBuilderPlugin>>* plugins)
Yuchen Zenga42ec212016-04-29 13:03:06 -0700211 GRPC_OVERRIDE {
212 auto plugin = plugins->begin();
213 while (plugin != plugins->end()) {
Vijay Pai15855f32016-06-10 12:25:32 -0700214 if ((*plugin)->has_sync_methods()) {
Yuchen Zenga42ec212016-04-29 13:03:06 -0700215 plugins->erase(plugin++);
216 } else {
217 plugin++;
218 }
219 }
220 }
221};
222
Vijay Paidf8b62c2016-05-02 14:34:24 -0700223class TestScenario {
224 public:
Vijay Paid7b1e702016-05-02 15:10:21 -0700225 TestScenario(bool non_block, const grpc::string& creds_type,
226 const grpc::string& content)
227 : disable_blocking(non_block),
228 credentials_type(creds_type),
229 message_content(content) {}
230 void Log() const {
231 gpr_log(GPR_INFO,
232 "Scenario: disable_blocking %d, credentials %s, message size %d",
233 disable_blocking, credentials_type.c_str(), message_content.size());
234 }
Vijay Paidf8b62c2016-05-02 14:34:24 -0700235 bool disable_blocking;
Vijay Pai679c75f2016-06-15 13:08:00 -0700236 // Although the below grpc::string's are logically const, we can't declare
237 // them const because of a limitation in the way old compilers (e.g., gcc-4.4)
238 // manage vector insertion using a copy constructor
239 grpc::string credentials_type;
240 grpc::string message_content;
Vijay Paidf8b62c2016-05-02 14:34:24 -0700241};
242
243class AsyncEnd2endTest : public ::testing::TestWithParam<TestScenario> {
Craig Tiller0220cf12015-02-12 17:39:26 -0800244 protected:
Vijay Paid7b1e702016-05-02 15:10:21 -0700245 AsyncEnd2endTest() { GetParam().Log(); }
Craig Tiller0220cf12015-02-12 17:39:26 -0800246
Craig Tillercf133f42015-02-26 14:05:56 -0800247 void SetUp() GRPC_OVERRIDE {
Vijay Paidf8b62c2016-05-02 14:34:24 -0700248 poll_overrider_.reset(new PollingOverrider(!GetParam().disable_blocking));
Vijay Pai018879a2016-02-16 09:20:50 -0800249
David Klempner6fb122d2016-05-13 15:24:17 -0700250 port_ = grpc_pick_unused_port_or_die();
251 server_address_ << "localhost:" << port_;
vjpai017ed622015-12-09 10:42:54 -0800252
Craig Tiller0220cf12015-02-12 17:39:26 -0800253 // Setup server
254 ServerBuilder builder;
Vijay Paidf8b62c2016-05-02 14:34:24 -0700255 auto server_creds = GetServerCredentials(GetParam().credentials_type);
256 builder.AddListeningPort(server_address_.str(), server_creds);
Craig Tiller15f383c2016-01-07 12:45:32 -0800257 builder.RegisterService(&service_);
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700258 cq_ = builder.AddCompletionQueue();
Yuchen Zenga42ec212016-04-29 13:03:06 -0700259
260 // TODO(zyc): make a test option to choose wheather sync plugins should be
261 // deleted
262 std::unique_ptr<ServerBuilderOption> sync_plugin_disabler(
263 new ServerBuilderSyncPluginDisabler());
264 builder.SetOption(move(sync_plugin_disabler));
Craig Tiller0220cf12015-02-12 17:39:26 -0800265 server_ = builder.BuildAndStart();
Vijay Paib65eda42016-02-16 13:48:05 -0800266
267 gpr_tls_set(&g_is_async_end2end_test, 1);
Craig Tiller0220cf12015-02-12 17:39:26 -0800268 }
269
Craig Tillercf133f42015-02-26 14:05:56 -0800270 void TearDown() GRPC_OVERRIDE {
Craig Tiller492968f2015-02-18 13:14:03 -0800271 server_->Shutdown();
272 void* ignored_tag;
273 bool ignored_ok;
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700274 cq_->Shutdown();
275 while (cq_->Next(&ignored_tag, &ignored_ok))
Craig Tiller492968f2015-02-18 13:14:03 -0800276 ;
Vijay Pai018879a2016-02-16 09:20:50 -0800277 poll_overrider_.reset();
Vijay Paib65eda42016-02-16 13:48:05 -0800278 gpr_tls_set(&g_is_async_end2end_test, 0);
David Klempner6fb122d2016-05-13 15:24:17 -0700279 grpc_recycle_unused_port(port_);
Craig Tiller492968f2015-02-18 13:14:03 -0800280 }
Craig Tiller0220cf12015-02-12 17:39:26 -0800281
282 void ResetStub() {
Vijay Paidf8b62c2016-05-02 14:34:24 -0700283 ChannelArguments args;
284 auto channel_creds =
285 GetChannelCredentials(GetParam().credentials_type, &args);
yang-g730055d2015-08-27 12:29:45 -0700286 std::shared_ptr<Channel> channel =
Vijay Paidf8b62c2016-05-02 14:34:24 -0700287 CreateCustomChannel(server_address_.str(), channel_creds, args);
Sree Kuchibhotla5a05f512016-01-13 22:43:20 -0800288 stub_ = grpc::testing::EchoTestService::NewStub(channel);
Craig Tiller0220cf12015-02-12 17:39:26 -0800289 }
290
Yang Gao406b32f2015-02-13 16:25:33 -0800291 void SendRpc(int num_rpcs) {
292 for (int i = 0; i < num_rpcs; i++) {
293 EchoRequest send_request;
294 EchoRequest recv_request;
295 EchoResponse send_response;
296 EchoResponse recv_response;
297 Status recv_status;
298
299 ClientContext cli_ctx;
300 ServerContext srv_ctx;
301 grpc::ServerAsyncResponseWriter<EchoResponse> response_writer(&srv_ctx);
302
Vijay Paid7b1e702016-05-02 15:10:21 -0700303 send_request.set_message(GetParam().message_content);
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800304 std::unique_ptr<ClientAsyncResponseReader<EchoResponse>> response_reader(
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700305 stub_->AsyncEcho(&cli_ctx, send_request, cq_.get()));
Yang Gao406b32f2015-02-13 16:25:33 -0800306
Craig Tillerd6c98df2015-08-18 09:33:44 -0700307 service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, cq_.get(),
308 cq_.get(), tag(2));
Yang Gao406b32f2015-02-13 16:25:33 -0800309
Vijay Paidf8b62c2016-05-02 14:34:24 -0700310 Verifier(GetParam().disable_blocking).Expect(2, true).Verify(cq_.get());
Yang Gao406b32f2015-02-13 16:25:33 -0800311 EXPECT_EQ(send_request.message(), recv_request.message());
312
313 send_response.set_message(recv_request.message());
314 response_writer.Finish(send_response, Status::OK, tag(3));
Yang Gao3a5e5492015-02-18 14:32:38 -0800315 response_reader->Finish(&recv_response, &recv_status, tag(4));
Craig Tillere4d27482016-05-03 12:19:33 -0700316 Verifier(GetParam().disable_blocking)
317 .Expect(3, true)
318 .Expect(4, true)
319 .Verify(cq_.get());
Yang Gao406b32f2015-02-13 16:25:33 -0800320
321 EXPECT_EQ(send_response.message(), recv_response.message());
Yang Gaoc1a2c312015-06-16 10:59:46 -0700322 EXPECT_TRUE(recv_status.ok());
Yang Gao406b32f2015-02-13 16:25:33 -0800323 }
324 }
325
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700326 std::unique_ptr<ServerCompletionQueue> cq_;
Sree Kuchibhotla5a05f512016-01-13 22:43:20 -0800327 std::unique_ptr<grpc::testing::EchoTestService::Stub> stub_;
Craig Tiller0220cf12015-02-12 17:39:26 -0800328 std::unique_ptr<Server> server_;
Sree Kuchibhotla5a05f512016-01-13 22:43:20 -0800329 grpc::testing::EchoTestService::AsyncService service_;
Craig Tiller0220cf12015-02-12 17:39:26 -0800330 std::ostringstream server_address_;
David Klempner6fb122d2016-05-13 15:24:17 -0700331 int port_;
vjpaicf4daeb2016-02-15 02:33:54 -0800332
Vijay Pai018879a2016-02-16 09:20:50 -0800333 std::unique_ptr<PollingOverrider> poll_overrider_;
Craig Tiller0220cf12015-02-12 17:39:26 -0800334};
335
Craig Tiller69f90e62015-08-06 08:32:35 -0700336TEST_P(AsyncEnd2endTest, SimpleRpc) {
Craig Tiller0220cf12015-02-12 17:39:26 -0800337 ResetStub();
Yang Gao406b32f2015-02-13 16:25:33 -0800338 SendRpc(1);
339}
Yang Gaobb84a302015-02-12 23:30:12 -0800340
Craig Tiller69f90e62015-08-06 08:32:35 -0700341TEST_P(AsyncEnd2endTest, SequentialRpcs) {
Yang Gao406b32f2015-02-13 16:25:33 -0800342 ResetStub();
343 SendRpc(10);
Craig Tiller0220cf12015-02-12 17:39:26 -0800344}
345
vjpai7aadf462015-03-16 23:58:44 -0700346// Test a simple RPC using the async version of Next
Craig Tiller69f90e62015-08-06 08:32:35 -0700347TEST_P(AsyncEnd2endTest, AsyncNextRpc) {
vjpai7aadf462015-03-16 23:58:44 -0700348 ResetStub();
349
350 EchoRequest send_request;
351 EchoRequest recv_request;
352 EchoResponse send_response;
353 EchoResponse recv_response;
354 Status recv_status;
355
356 ClientContext cli_ctx;
357 ServerContext srv_ctx;
358 grpc::ServerAsyncResponseWriter<EchoResponse> response_writer(&srv_ctx);
359
Vijay Paid7b1e702016-05-02 15:10:21 -0700360 send_request.set_message(GetParam().message_content);
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800361 std::unique_ptr<ClientAsyncResponseReader<EchoResponse>> response_reader(
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700362 stub_->AsyncEcho(&cli_ctx, send_request, cq_.get()));
vjpai7aadf462015-03-16 23:58:44 -0700363
Yang Gao757afae2015-03-17 15:49:26 -0700364 std::chrono::system_clock::time_point time_now(
Craig Tillerf51199f2015-05-08 09:32:53 -0700365 std::chrono::system_clock::now());
366 std::chrono::system_clock::time_point time_limit(
367 std::chrono::system_clock::now() + std::chrono::seconds(10));
Vijay Paidf8b62c2016-05-02 14:34:24 -0700368 Verifier(GetParam().disable_blocking).Verify(cq_.get(), time_now);
369 Verifier(GetParam().disable_blocking).Verify(cq_.get(), time_now);
vjpai7aadf462015-03-16 23:58:44 -0700370
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700371 service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, cq_.get(),
372 cq_.get(), tag(2));
vjpai7aadf462015-03-16 23:58:44 -0700373
Vijay Paidf8b62c2016-05-02 14:34:24 -0700374 Verifier(GetParam().disable_blocking)
375 .Expect(2, true)
376 .Verify(cq_.get(), time_limit);
vjpai7aadf462015-03-16 23:58:44 -0700377 EXPECT_EQ(send_request.message(), recv_request.message());
vjpai7aadf462015-03-16 23:58:44 -0700378
379 send_response.set_message(recv_request.message());
380 response_writer.Finish(send_response, Status::OK, tag(3));
vjpai7aadf462015-03-16 23:58:44 -0700381 response_reader->Finish(&recv_response, &recv_status, tag(4));
Vijay Paidf8b62c2016-05-02 14:34:24 -0700382 Verifier(GetParam().disable_blocking)
Craig Tillere4d27482016-05-03 12:19:33 -0700383 .Expect(3, true)
Craig Tiller4c06b822015-08-06 08:41:31 -0700384 .Expect(4, true)
385 .Verify(cq_.get(), std::chrono::system_clock::time_point::max());
vjpai7aadf462015-03-16 23:58:44 -0700386
387 EXPECT_EQ(send_response.message(), recv_response.message());
Yang Gaoc1a2c312015-06-16 10:59:46 -0700388 EXPECT_TRUE(recv_status.ok());
vjpai7aadf462015-03-16 23:58:44 -0700389}
Yang Gao757afae2015-03-17 15:49:26 -0700390
Yang Gao0e0d8e12015-02-13 14:40:41 -0800391// Two pings and a final pong.
Craig Tiller69f90e62015-08-06 08:32:35 -0700392TEST_P(AsyncEnd2endTest, SimpleClientStreaming) {
Yang Gao005f18a2015-02-13 10:22:33 -0800393 ResetStub();
394
395 EchoRequest send_request;
396 EchoRequest recv_request;
397 EchoResponse send_response;
398 EchoResponse recv_response;
399 Status recv_status;
400 ClientContext cli_ctx;
401 ServerContext srv_ctx;
402 ServerAsyncReader<EchoResponse, EchoRequest> srv_stream(&srv_ctx);
403
Vijay Paid7b1e702016-05-02 15:10:21 -0700404 send_request.set_message(GetParam().message_content);
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800405 std::unique_ptr<ClientAsyncWriter<EchoRequest>> cli_stream(
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700406 stub_->AsyncRequestStream(&cli_ctx, &recv_response, cq_.get(), tag(1)));
Yang Gao005f18a2015-02-13 10:22:33 -0800407
Craig Tillerd6c98df2015-08-18 09:33:44 -0700408 service_.RequestRequestStream(&srv_ctx, &srv_stream, cq_.get(), cq_.get(),
409 tag(2));
Yang Gao005f18a2015-02-13 10:22:33 -0800410
Vijay Paidf8b62c2016-05-02 14:34:24 -0700411 Verifier(GetParam().disable_blocking)
412 .Expect(2, true)
413 .Expect(1, true)
414 .Verify(cq_.get());
Yang Gao005f18a2015-02-13 10:22:33 -0800415
416 cli_stream->Write(send_request, tag(3));
Yang Gao005f18a2015-02-13 10:22:33 -0800417 srv_stream.Read(&recv_request, tag(4));
Craig Tillere4d27482016-05-03 12:19:33 -0700418 Verifier(GetParam().disable_blocking)
419 .Expect(3, true)
420 .Expect(4, true)
421 .Verify(cq_.get());
Yang Gao005f18a2015-02-13 10:22:33 -0800422 EXPECT_EQ(send_request.message(), recv_request.message());
423
424 cli_stream->Write(send_request, tag(5));
Yang Gao005f18a2015-02-13 10:22:33 -0800425 srv_stream.Read(&recv_request, tag(6));
Craig Tillere4d27482016-05-03 12:19:33 -0700426 Verifier(GetParam().disable_blocking)
427 .Expect(5, true)
428 .Expect(6, true)
429 .Verify(cq_.get());
Yang Gao005f18a2015-02-13 10:22:33 -0800430
431 EXPECT_EQ(send_request.message(), recv_request.message());
432 cli_stream->WritesDone(tag(7));
Yang Gao005f18a2015-02-13 10:22:33 -0800433 srv_stream.Read(&recv_request, tag(8));
Craig Tillere4d27482016-05-03 12:19:33 -0700434 Verifier(GetParam().disable_blocking)
435 .Expect(7, true)
436 .Expect(8, false)
437 .Verify(cq_.get());
Yang Gao005f18a2015-02-13 10:22:33 -0800438
439 send_response.set_message(recv_request.message());
440 srv_stream.Finish(send_response, Status::OK, tag(9));
Yang Gao005f18a2015-02-13 10:22:33 -0800441 cli_stream->Finish(&recv_status, tag(10));
Craig Tillere4d27482016-05-03 12:19:33 -0700442 Verifier(GetParam().disable_blocking)
443 .Expect(9, true)
444 .Expect(10, true)
445 .Verify(cq_.get());
Yang Gao005f18a2015-02-13 10:22:33 -0800446
447 EXPECT_EQ(send_response.message(), recv_response.message());
Yang Gaoc1a2c312015-06-16 10:59:46 -0700448 EXPECT_TRUE(recv_status.ok());
Yang Gao005f18a2015-02-13 10:22:33 -0800449}
450
Yang Gao0e0d8e12015-02-13 14:40:41 -0800451// One ping, two pongs.
Craig Tiller69f90e62015-08-06 08:32:35 -0700452TEST_P(AsyncEnd2endTest, SimpleServerStreaming) {
Yang Gao0e0d8e12015-02-13 14:40:41 -0800453 ResetStub();
454
455 EchoRequest send_request;
456 EchoRequest recv_request;
457 EchoResponse send_response;
458 EchoResponse recv_response;
459 Status recv_status;
460 ClientContext cli_ctx;
461 ServerContext srv_ctx;
462 ServerAsyncWriter<EchoResponse> srv_stream(&srv_ctx);
463
Vijay Paid7b1e702016-05-02 15:10:21 -0700464 send_request.set_message(GetParam().message_content);
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800465 std::unique_ptr<ClientAsyncReader<EchoResponse>> cli_stream(
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700466 stub_->AsyncResponseStream(&cli_ctx, send_request, cq_.get(), tag(1)));
Yang Gao0e0d8e12015-02-13 14:40:41 -0800467
Craig Tillerf9e6adf2015-05-06 11:45:59 -0700468 service_.RequestResponseStream(&srv_ctx, &recv_request, &srv_stream,
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700469 cq_.get(), cq_.get(), tag(2));
Yang Gao0e0d8e12015-02-13 14:40:41 -0800470
Vijay Paidf8b62c2016-05-02 14:34:24 -0700471 Verifier(GetParam().disable_blocking)
472 .Expect(1, true)
473 .Expect(2, true)
474 .Verify(cq_.get());
Yang Gao0e0d8e12015-02-13 14:40:41 -0800475 EXPECT_EQ(send_request.message(), recv_request.message());
476
477 send_response.set_message(recv_request.message());
478 srv_stream.Write(send_response, tag(3));
Yang Gao0e0d8e12015-02-13 14:40:41 -0800479 cli_stream->Read(&recv_response, tag(4));
Craig Tillere4d27482016-05-03 12:19:33 -0700480 Verifier(GetParam().disable_blocking)
481 .Expect(3, true)
482 .Expect(4, true)
483 .Verify(cq_.get());
Yang Gao0e0d8e12015-02-13 14:40:41 -0800484 EXPECT_EQ(send_response.message(), recv_response.message());
485
486 srv_stream.Write(send_response, tag(5));
Yang Gao0e0d8e12015-02-13 14:40:41 -0800487 cli_stream->Read(&recv_response, tag(6));
Craig Tillere4d27482016-05-03 12:19:33 -0700488 Verifier(GetParam().disable_blocking)
489 .Expect(5, true)
490 .Expect(6, true)
491 .Verify(cq_.get());
Yang Gao0e0d8e12015-02-13 14:40:41 -0800492 EXPECT_EQ(send_response.message(), recv_response.message());
493
494 srv_stream.Finish(Status::OK, tag(7));
Yang Gao0e0d8e12015-02-13 14:40:41 -0800495 cli_stream->Read(&recv_response, tag(8));
Craig Tillere4d27482016-05-03 12:19:33 -0700496 Verifier(GetParam().disable_blocking)
497 .Expect(7, true)
498 .Expect(8, false)
499 .Verify(cq_.get());
Yang Gao0e0d8e12015-02-13 14:40:41 -0800500
501 cli_stream->Finish(&recv_status, tag(9));
Vijay Paidf8b62c2016-05-02 14:34:24 -0700502 Verifier(GetParam().disable_blocking).Expect(9, true).Verify(cq_.get());
Yang Gao0e0d8e12015-02-13 14:40:41 -0800503
Yang Gaoc1a2c312015-06-16 10:59:46 -0700504 EXPECT_TRUE(recv_status.ok());
Yang Gao0e0d8e12015-02-13 14:40:41 -0800505}
506
507// One ping, one pong.
Craig Tiller69f90e62015-08-06 08:32:35 -0700508TEST_P(AsyncEnd2endTest, SimpleBidiStreaming) {
Yang Gaoc05b6cb2015-02-13 00:34:10 -0800509 ResetStub();
510
511 EchoRequest send_request;
512 EchoRequest recv_request;
513 EchoResponse send_response;
514 EchoResponse recv_response;
515 Status recv_status;
516 ClientContext cli_ctx;
517 ServerContext srv_ctx;
518 ServerAsyncReaderWriter<EchoResponse, EchoRequest> srv_stream(&srv_ctx);
519
Vijay Paid7b1e702016-05-02 15:10:21 -0700520 send_request.set_message(GetParam().message_content);
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800521 std::unique_ptr<ClientAsyncReaderWriter<EchoRequest, EchoResponse>>
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700522 cli_stream(stub_->AsyncBidiStream(&cli_ctx, cq_.get(), tag(1)));
Yang Gaoc05b6cb2015-02-13 00:34:10 -0800523
Craig Tillerd6c98df2015-08-18 09:33:44 -0700524 service_.RequestBidiStream(&srv_ctx, &srv_stream, cq_.get(), cq_.get(),
525 tag(2));
Yang Gaoc05b6cb2015-02-13 00:34:10 -0800526
Vijay Paidf8b62c2016-05-02 14:34:24 -0700527 Verifier(GetParam().disable_blocking)
528 .Expect(1, true)
529 .Expect(2, true)
530 .Verify(cq_.get());
Yang Gaoc05b6cb2015-02-13 00:34:10 -0800531
532 cli_stream->Write(send_request, tag(3));
Yang Gaoc05b6cb2015-02-13 00:34:10 -0800533 srv_stream.Read(&recv_request, tag(4));
Craig Tillere4d27482016-05-03 12:19:33 -0700534 Verifier(GetParam().disable_blocking)
535 .Expect(3, true)
536 .Expect(4, true)
537 .Verify(cq_.get());
Yang Gaoc05b6cb2015-02-13 00:34:10 -0800538 EXPECT_EQ(send_request.message(), recv_request.message());
539
540 send_response.set_message(recv_request.message());
541 srv_stream.Write(send_response, tag(5));
Yang Gaoc05b6cb2015-02-13 00:34:10 -0800542 cli_stream->Read(&recv_response, tag(6));
Craig Tillere4d27482016-05-03 12:19:33 -0700543 Verifier(GetParam().disable_blocking)
544 .Expect(5, true)
545 .Expect(6, true)
546 .Verify(cq_.get());
Yang Gaoc05b6cb2015-02-13 00:34:10 -0800547 EXPECT_EQ(send_response.message(), recv_response.message());
548
549 cli_stream->WritesDone(tag(7));
Yang Gaoc05b6cb2015-02-13 00:34:10 -0800550 srv_stream.Read(&recv_request, tag(8));
Craig Tillere4d27482016-05-03 12:19:33 -0700551 Verifier(GetParam().disable_blocking)
552 .Expect(7, true)
553 .Expect(8, false)
554 .Verify(cq_.get());
Yang Gaoc05b6cb2015-02-13 00:34:10 -0800555
556 srv_stream.Finish(Status::OK, tag(9));
Yang Gaoc05b6cb2015-02-13 00:34:10 -0800557 cli_stream->Finish(&recv_status, tag(10));
Craig Tillere4d27482016-05-03 12:19:33 -0700558 Verifier(GetParam().disable_blocking)
559 .Expect(9, true)
560 .Expect(10, true)
561 .Verify(cq_.get());
Yang Gaoc05b6cb2015-02-13 00:34:10 -0800562
Yang Gaoc1a2c312015-06-16 10:59:46 -0700563 EXPECT_TRUE(recv_status.ok());
Yang Gaoc05b6cb2015-02-13 00:34:10 -0800564}
565
Yang Gao406b32f2015-02-13 16:25:33 -0800566// Metadata tests
Craig Tiller69f90e62015-08-06 08:32:35 -0700567TEST_P(AsyncEnd2endTest, ClientInitialMetadataRpc) {
Yang Gao406b32f2015-02-13 16:25:33 -0800568 ResetStub();
569
570 EchoRequest send_request;
571 EchoRequest recv_request;
572 EchoResponse send_response;
573 EchoResponse recv_response;
574 Status recv_status;
575
576 ClientContext cli_ctx;
577 ServerContext srv_ctx;
578 grpc::ServerAsyncResponseWriter<EchoResponse> response_writer(&srv_ctx);
579
Vijay Paid7b1e702016-05-02 15:10:21 -0700580 send_request.set_message(GetParam().message_content);
Yang Gao406b32f2015-02-13 16:25:33 -0800581 std::pair<grpc::string, grpc::string> meta1("key1", "val1");
582 std::pair<grpc::string, grpc::string> meta2("key2", "val2");
Craig Tiller6f871642016-02-03 16:15:31 -0800583 std::pair<grpc::string, grpc::string> meta3("g.r.d-bin", "xyz");
Yang Gao406b32f2015-02-13 16:25:33 -0800584 cli_ctx.AddMetadata(meta1.first, meta1.second);
585 cli_ctx.AddMetadata(meta2.first, meta2.second);
Craig Tiller6f871642016-02-03 16:15:31 -0800586 cli_ctx.AddMetadata(meta3.first, meta3.second);
Yang Gao406b32f2015-02-13 16:25:33 -0800587
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800588 std::unique_ptr<ClientAsyncResponseReader<EchoResponse>> response_reader(
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700589 stub_->AsyncEcho(&cli_ctx, send_request, cq_.get()));
Yang Gao406b32f2015-02-13 16:25:33 -0800590
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700591 service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, cq_.get(),
592 cq_.get(), tag(2));
Vijay Paidf8b62c2016-05-02 14:34:24 -0700593 Verifier(GetParam().disable_blocking).Expect(2, true).Verify(cq_.get());
Yang Gao406b32f2015-02-13 16:25:33 -0800594 EXPECT_EQ(send_request.message(), recv_request.message());
595 auto client_initial_metadata = srv_ctx.client_metadata();
yang-ge21908f2015-08-25 13:47:51 -0700596 EXPECT_EQ(meta1.second,
597 ToString(client_initial_metadata.find(meta1.first)->second));
598 EXPECT_EQ(meta2.second,
599 ToString(client_initial_metadata.find(meta2.first)->second));
Craig Tiller6f871642016-02-03 16:15:31 -0800600 EXPECT_EQ(meta3.second,
601 ToString(client_initial_metadata.find(meta3.first)->second));
Craig Tiller8bf2dca2015-07-10 13:08:41 -0700602 EXPECT_GE(client_initial_metadata.size(), static_cast<size_t>(2));
Yang Gao406b32f2015-02-13 16:25:33 -0800603
604 send_response.set_message(recv_request.message());
605 response_writer.Finish(send_response, Status::OK, tag(3));
Yang Gao3a5e5492015-02-18 14:32:38 -0800606 response_reader->Finish(&recv_response, &recv_status, tag(4));
Craig Tillere4d27482016-05-03 12:19:33 -0700607 Verifier(GetParam().disable_blocking)
608 .Expect(3, true)
609 .Expect(4, true)
610 .Verify(cq_.get());
Yang Gao406b32f2015-02-13 16:25:33 -0800611
612 EXPECT_EQ(send_response.message(), recv_response.message());
Yang Gaoc1a2c312015-06-16 10:59:46 -0700613 EXPECT_TRUE(recv_status.ok());
Yang Gao406b32f2015-02-13 16:25:33 -0800614}
615
Craig Tiller69f90e62015-08-06 08:32:35 -0700616TEST_P(AsyncEnd2endTest, ServerInitialMetadataRpc) {
Yang Gao2b7f5372015-02-18 00:45:53 -0800617 ResetStub();
618
619 EchoRequest send_request;
620 EchoRequest recv_request;
621 EchoResponse send_response;
622 EchoResponse recv_response;
623 Status recv_status;
624
625 ClientContext cli_ctx;
626 ServerContext srv_ctx;
627 grpc::ServerAsyncResponseWriter<EchoResponse> response_writer(&srv_ctx);
628
Vijay Paid7b1e702016-05-02 15:10:21 -0700629 send_request.set_message(GetParam().message_content);
Yang Gao2b7f5372015-02-18 00:45:53 -0800630 std::pair<grpc::string, grpc::string> meta1("key1", "val1");
631 std::pair<grpc::string, grpc::string> meta2("key2", "val2");
632
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800633 std::unique_ptr<ClientAsyncResponseReader<EchoResponse>> response_reader(
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700634 stub_->AsyncEcho(&cli_ctx, send_request, cq_.get()));
Yang Gao2b7f5372015-02-18 00:45:53 -0800635
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700636 service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, cq_.get(),
637 cq_.get(), tag(2));
Vijay Paidf8b62c2016-05-02 14:34:24 -0700638 Verifier(GetParam().disable_blocking).Expect(2, true).Verify(cq_.get());
Yang Gao2b7f5372015-02-18 00:45:53 -0800639 EXPECT_EQ(send_request.message(), recv_request.message());
640 srv_ctx.AddInitialMetadata(meta1.first, meta1.second);
641 srv_ctx.AddInitialMetadata(meta2.first, meta2.second);
642 response_writer.SendInitialMetadata(tag(3));
Vijay Paidf8b62c2016-05-02 14:34:24 -0700643 Verifier(GetParam().disable_blocking).Expect(3, true).Verify(cq_.get());
Yang Gao2b7f5372015-02-18 00:45:53 -0800644
Yang Gao3a5e5492015-02-18 14:32:38 -0800645 response_reader->ReadInitialMetadata(tag(4));
Vijay Paidf8b62c2016-05-02 14:34:24 -0700646 Verifier(GetParam().disable_blocking).Expect(4, true).Verify(cq_.get());
Yang Gao2b7f5372015-02-18 00:45:53 -0800647 auto server_initial_metadata = cli_ctx.GetServerInitialMetadata();
yang-ge21908f2015-08-25 13:47:51 -0700648 EXPECT_EQ(meta1.second,
649 ToString(server_initial_metadata.find(meta1.first)->second));
650 EXPECT_EQ(meta2.second,
651 ToString(server_initial_metadata.find(meta2.first)->second));
vjpaid5577aa2015-02-18 22:26:48 -0800652 EXPECT_EQ(static_cast<size_t>(2), server_initial_metadata.size());
Yang Gao3a5e5492015-02-18 14:32:38 -0800653
654 send_response.set_message(recv_request.message());
655 response_writer.Finish(send_response, Status::OK, tag(5));
Yang Gao3a5e5492015-02-18 14:32:38 -0800656 response_reader->Finish(&recv_response, &recv_status, tag(6));
Craig Tillere4d27482016-05-03 12:19:33 -0700657 Verifier(GetParam().disable_blocking)
658 .Expect(5, true)
659 .Expect(6, true)
660 .Verify(cq_.get());
Yang Gao3a5e5492015-02-18 14:32:38 -0800661
662 EXPECT_EQ(send_response.message(), recv_response.message());
Yang Gaoc1a2c312015-06-16 10:59:46 -0700663 EXPECT_TRUE(recv_status.ok());
Yang Gao2b7f5372015-02-18 00:45:53 -0800664}
665
Craig Tiller69f90e62015-08-06 08:32:35 -0700666TEST_P(AsyncEnd2endTest, ServerTrailingMetadataRpc) {
Yang Gao2b7f5372015-02-18 00:45:53 -0800667 ResetStub();
668
669 EchoRequest send_request;
670 EchoRequest recv_request;
671 EchoResponse send_response;
672 EchoResponse recv_response;
673 Status recv_status;
674
675 ClientContext cli_ctx;
676 ServerContext srv_ctx;
677 grpc::ServerAsyncResponseWriter<EchoResponse> response_writer(&srv_ctx);
678
Vijay Paid7b1e702016-05-02 15:10:21 -0700679 send_request.set_message(GetParam().message_content);
Yang Gao2b7f5372015-02-18 00:45:53 -0800680 std::pair<grpc::string, grpc::string> meta1("key1", "val1");
681 std::pair<grpc::string, grpc::string> meta2("key2", "val2");
682
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800683 std::unique_ptr<ClientAsyncResponseReader<EchoResponse>> response_reader(
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700684 stub_->AsyncEcho(&cli_ctx, send_request, cq_.get()));
Yang Gao2b7f5372015-02-18 00:45:53 -0800685
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700686 service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, cq_.get(),
687 cq_.get(), tag(2));
Vijay Paidf8b62c2016-05-02 14:34:24 -0700688 Verifier(GetParam().disable_blocking).Expect(2, true).Verify(cq_.get());
Yang Gao2b7f5372015-02-18 00:45:53 -0800689 EXPECT_EQ(send_request.message(), recv_request.message());
690 response_writer.SendInitialMetadata(tag(3));
Vijay Paidf8b62c2016-05-02 14:34:24 -0700691 Verifier(GetParam().disable_blocking).Expect(3, true).Verify(cq_.get());
Yang Gao2b7f5372015-02-18 00:45:53 -0800692
693 send_response.set_message(recv_request.message());
694 srv_ctx.AddTrailingMetadata(meta1.first, meta1.second);
695 srv_ctx.AddTrailingMetadata(meta2.first, meta2.second);
696 response_writer.Finish(send_response, Status::OK, tag(4));
Yang Gao3a5e5492015-02-18 14:32:38 -0800697 response_reader->Finish(&recv_response, &recv_status, tag(5));
Craig Tillere4d27482016-05-03 12:19:33 -0700698
699 Verifier(GetParam().disable_blocking)
700 .Expect(4, true)
701 .Expect(5, true)
702 .Verify(cq_.get());
703
Yang Gao2b7f5372015-02-18 00:45:53 -0800704 EXPECT_EQ(send_response.message(), recv_response.message());
Yang Gaoc1a2c312015-06-16 10:59:46 -0700705 EXPECT_TRUE(recv_status.ok());
Yang Gao2b7f5372015-02-18 00:45:53 -0800706 auto server_trailing_metadata = cli_ctx.GetServerTrailingMetadata();
yang-ge21908f2015-08-25 13:47:51 -0700707 EXPECT_EQ(meta1.second,
708 ToString(server_trailing_metadata.find(meta1.first)->second));
709 EXPECT_EQ(meta2.second,
710 ToString(server_trailing_metadata.find(meta2.first)->second));
vjpaid5577aa2015-02-18 22:26:48 -0800711 EXPECT_EQ(static_cast<size_t>(2), server_trailing_metadata.size());
Yang Gao2b7f5372015-02-18 00:45:53 -0800712}
713
Craig Tiller69f90e62015-08-06 08:32:35 -0700714TEST_P(AsyncEnd2endTest, MetadataRpc) {
Yang Gao2b7f5372015-02-18 00:45:53 -0800715 ResetStub();
716
717 EchoRequest send_request;
718 EchoRequest recv_request;
719 EchoResponse send_response;
720 EchoResponse recv_response;
721 Status recv_status;
722
723 ClientContext cli_ctx;
724 ServerContext srv_ctx;
725 grpc::ServerAsyncResponseWriter<EchoResponse> response_writer(&srv_ctx);
726
Vijay Paid7b1e702016-05-02 15:10:21 -0700727 send_request.set_message(GetParam().message_content);
Yang Gao2b7f5372015-02-18 00:45:53 -0800728 std::pair<grpc::string, grpc::string> meta1("key1", "val1");
Yang Gao3a5e5492015-02-18 14:32:38 -0800729 std::pair<grpc::string, grpc::string> meta2(
Vijay Pai92a928f2015-03-26 16:30:22 -0400730 "key2-bin",
Craig Tillerd6c98df2015-08-18 09:33:44 -0700731 grpc::string("\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc", 13));
Yang Gao2b7f5372015-02-18 00:45:53 -0800732 std::pair<grpc::string, grpc::string> meta3("key3", "val3");
Craig Tiller47c83fd2015-02-21 22:45:35 -0800733 std::pair<grpc::string, grpc::string> meta6(
734 "key4-bin",
Vijay Pai92a928f2015-03-26 16:30:22 -0400735 grpc::string("\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d",
Craig Tillerd6c98df2015-08-18 09:33:44 -0700736 14));
Yang Gao2b7f5372015-02-18 00:45:53 -0800737 std::pair<grpc::string, grpc::string> meta5("key5", "val5");
Craig Tiller47c83fd2015-02-21 22:45:35 -0800738 std::pair<grpc::string, grpc::string> meta4(
739 "key6-bin",
Craig Tillerd6c98df2015-08-18 09:33:44 -0700740 grpc::string(
741 "\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee", 15));
Yang Gao2b7f5372015-02-18 00:45:53 -0800742
743 cli_ctx.AddMetadata(meta1.first, meta1.second);
744 cli_ctx.AddMetadata(meta2.first, meta2.second);
745
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800746 std::unique_ptr<ClientAsyncResponseReader<EchoResponse>> response_reader(
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700747 stub_->AsyncEcho(&cli_ctx, send_request, cq_.get()));
Yang Gao2b7f5372015-02-18 00:45:53 -0800748
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700749 service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, cq_.get(),
750 cq_.get(), tag(2));
Vijay Paidf8b62c2016-05-02 14:34:24 -0700751 Verifier(GetParam().disable_blocking).Expect(2, true).Verify(cq_.get());
Yang Gao2b7f5372015-02-18 00:45:53 -0800752 EXPECT_EQ(send_request.message(), recv_request.message());
753 auto client_initial_metadata = srv_ctx.client_metadata();
yang-ge21908f2015-08-25 13:47:51 -0700754 EXPECT_EQ(meta1.second,
755 ToString(client_initial_metadata.find(meta1.first)->second));
756 EXPECT_EQ(meta2.second,
757 ToString(client_initial_metadata.find(meta2.first)->second));
Craig Tiller8bf2dca2015-07-10 13:08:41 -0700758 EXPECT_GE(client_initial_metadata.size(), static_cast<size_t>(2));
Yang Gao2b7f5372015-02-18 00:45:53 -0800759
760 srv_ctx.AddInitialMetadata(meta3.first, meta3.second);
761 srv_ctx.AddInitialMetadata(meta4.first, meta4.second);
762 response_writer.SendInitialMetadata(tag(3));
Vijay Paidf8b62c2016-05-02 14:34:24 -0700763 Verifier(GetParam().disable_blocking).Expect(3, true).Verify(cq_.get());
Yang Gao3a5e5492015-02-18 14:32:38 -0800764 response_reader->ReadInitialMetadata(tag(4));
Vijay Paidf8b62c2016-05-02 14:34:24 -0700765 Verifier(GetParam().disable_blocking).Expect(4, true).Verify(cq_.get());
Yang Gao2b7f5372015-02-18 00:45:53 -0800766 auto server_initial_metadata = cli_ctx.GetServerInitialMetadata();
yang-ge21908f2015-08-25 13:47:51 -0700767 EXPECT_EQ(meta3.second,
768 ToString(server_initial_metadata.find(meta3.first)->second));
769 EXPECT_EQ(meta4.second,
770 ToString(server_initial_metadata.find(meta4.first)->second));
Craig Tiller8bf2dca2015-07-10 13:08:41 -0700771 EXPECT_GE(server_initial_metadata.size(), static_cast<size_t>(2));
Yang Gao3a5e5492015-02-18 14:32:38 -0800772
773 send_response.set_message(recv_request.message());
774 srv_ctx.AddTrailingMetadata(meta5.first, meta5.second);
775 srv_ctx.AddTrailingMetadata(meta6.first, meta6.second);
776 response_writer.Finish(send_response, Status::OK, tag(5));
Yang Gao3a5e5492015-02-18 14:32:38 -0800777 response_reader->Finish(&recv_response, &recv_status, tag(6));
Craig Tillere4d27482016-05-03 12:19:33 -0700778
779 Verifier(GetParam().disable_blocking)
780 .Expect(5, true)
781 .Expect(6, true)
782 .Verify(cq_.get());
783
Yang Gao3a5e5492015-02-18 14:32:38 -0800784 EXPECT_EQ(send_response.message(), recv_response.message());
Yang Gaoc1a2c312015-06-16 10:59:46 -0700785 EXPECT_TRUE(recv_status.ok());
Yang Gao2b7f5372015-02-18 00:45:53 -0800786 auto server_trailing_metadata = cli_ctx.GetServerTrailingMetadata();
yang-ge21908f2015-08-25 13:47:51 -0700787 EXPECT_EQ(meta5.second,
788 ToString(server_trailing_metadata.find(meta5.first)->second));
789 EXPECT_EQ(meta6.second,
790 ToString(server_trailing_metadata.find(meta6.first)->second));
Craig Tiller8bf2dca2015-07-10 13:08:41 -0700791 EXPECT_GE(server_trailing_metadata.size(), static_cast<size_t>(2));
Yang Gao2b7f5372015-02-18 00:45:53 -0800792}
yang-gb3352562015-08-04 14:42:06 -0700793
794// Server uses AsyncNotifyWhenDone API to check for cancellation
Craig Tiller69f90e62015-08-06 08:32:35 -0700795TEST_P(AsyncEnd2endTest, ServerCheckCancellation) {
yang-gb3352562015-08-04 14:42:06 -0700796 ResetStub();
797
798 EchoRequest send_request;
799 EchoRequest recv_request;
800 EchoResponse send_response;
801 EchoResponse recv_response;
802 Status recv_status;
803
804 ClientContext cli_ctx;
805 ServerContext srv_ctx;
806 grpc::ServerAsyncResponseWriter<EchoResponse> response_writer(&srv_ctx);
807
Vijay Paid7b1e702016-05-02 15:10:21 -0700808 send_request.set_message(GetParam().message_content);
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800809 std::unique_ptr<ClientAsyncResponseReader<EchoResponse>> response_reader(
yang-gb3352562015-08-04 14:42:06 -0700810 stub_->AsyncEcho(&cli_ctx, send_request, cq_.get()));
811
812 srv_ctx.AsyncNotifyWhenDone(tag(5));
813 service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, cq_.get(),
814 cq_.get(), tag(2));
815
Vijay Paidf8b62c2016-05-02 14:34:24 -0700816 Verifier(GetParam().disable_blocking).Expect(2, true).Verify(cq_.get());
yang-gb3352562015-08-04 14:42:06 -0700817 EXPECT_EQ(send_request.message(), recv_request.message());
818
819 cli_ctx.TryCancel();
Vijay Paidf8b62c2016-05-02 14:34:24 -0700820 Verifier(GetParam().disable_blocking).Expect(5, true).Verify(cq_.get());
yang-gb3352562015-08-04 14:42:06 -0700821 EXPECT_TRUE(srv_ctx.IsCancelled());
822
823 response_reader->Finish(&recv_response, &recv_status, tag(4));
yang-g15759f62016-06-01 11:21:27 -0700824 Verifier(GetParam().disable_blocking).Expect(4, true).Verify(cq_.get());
yang-gb3352562015-08-04 14:42:06 -0700825
826 EXPECT_EQ(StatusCode::CANCELLED, recv_status.error_code());
827}
828
829// Server uses AsyncNotifyWhenDone API to check for normal finish
Craig Tiller69f90e62015-08-06 08:32:35 -0700830TEST_P(AsyncEnd2endTest, ServerCheckDone) {
yang-gb3352562015-08-04 14:42:06 -0700831 ResetStub();
832
833 EchoRequest send_request;
834 EchoRequest recv_request;
835 EchoResponse send_response;
836 EchoResponse recv_response;
837 Status recv_status;
838
839 ClientContext cli_ctx;
840 ServerContext srv_ctx;
841 grpc::ServerAsyncResponseWriter<EchoResponse> response_writer(&srv_ctx);
842
Vijay Paid7b1e702016-05-02 15:10:21 -0700843 send_request.set_message(GetParam().message_content);
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800844 std::unique_ptr<ClientAsyncResponseReader<EchoResponse>> response_reader(
yang-gb3352562015-08-04 14:42:06 -0700845 stub_->AsyncEcho(&cli_ctx, send_request, cq_.get()));
846
847 srv_ctx.AsyncNotifyWhenDone(tag(5));
848 service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, cq_.get(),
849 cq_.get(), tag(2));
850
Vijay Paidf8b62c2016-05-02 14:34:24 -0700851 Verifier(GetParam().disable_blocking).Expect(2, true).Verify(cq_.get());
yang-gb3352562015-08-04 14:42:06 -0700852 EXPECT_EQ(send_request.message(), recv_request.message());
853
854 send_response.set_message(recv_request.message());
855 response_writer.Finish(send_response, Status::OK, tag(3));
yang-gb3352562015-08-04 14:42:06 -0700856 response_reader->Finish(&recv_response, &recv_status, tag(4));
Craig Tillere4d27482016-05-03 12:19:33 -0700857 Verifier(GetParam().disable_blocking)
858 .Expect(3, true)
859 .Expect(4, true)
860 .Expect(5, true)
861 .Verify(cq_.get());
862 EXPECT_FALSE(srv_ctx.IsCancelled());
yang-gb3352562015-08-04 14:42:06 -0700863
864 EXPECT_EQ(send_response.message(), recv_response.message());
865 EXPECT_TRUE(recv_status.ok());
866}
867
Craig Tiller8f7bff72015-08-17 13:23:14 -0700868TEST_P(AsyncEnd2endTest, UnimplementedRpc) {
Vijay Paidf8b62c2016-05-02 14:34:24 -0700869 ChannelArguments args;
870 auto channel_creds =
871 GetChannelCredentials(GetParam().credentials_type, &args);
yang-g730055d2015-08-27 12:29:45 -0700872 std::shared_ptr<Channel> channel =
Vijay Paidf8b62c2016-05-02 14:34:24 -0700873 CreateCustomChannel(server_address_.str(), channel_creds, args);
Craig Tiller1b4e3302015-12-17 16:35:00 -0800874 std::unique_ptr<grpc::testing::UnimplementedService::Stub> stub;
875 stub = grpc::testing::UnimplementedService::NewStub(channel);
yang-g9b7757d2015-08-13 11:15:53 -0700876 EchoRequest send_request;
877 EchoResponse recv_response;
878 Status recv_status;
879
880 ClientContext cli_ctx;
Vijay Paid7b1e702016-05-02 15:10:21 -0700881 send_request.set_message(GetParam().message_content);
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800882 std::unique_ptr<ClientAsyncResponseReader<EchoResponse>> response_reader(
yang-g9b7757d2015-08-13 11:15:53 -0700883 stub->AsyncUnimplemented(&cli_ctx, send_request, cq_.get()));
884
885 response_reader->Finish(&recv_response, &recv_status, tag(4));
yang-g15759f62016-06-01 11:21:27 -0700886 Verifier(GetParam().disable_blocking).Expect(4, true).Verify(cq_.get());
yang-g9b7757d2015-08-13 11:15:53 -0700887
888 EXPECT_EQ(StatusCode::UNIMPLEMENTED, recv_status.error_code());
889 EXPECT_EQ("", recv_status.error_message());
890}
891
Sree Kuchibhotla0f242ac2016-01-29 18:12:19 -0800892// This class is for testing scenarios where RPCs are cancelled on the server
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -0800893// by calling ServerContext::TryCancel(). Server uses AsyncNotifyWhenDone
894// API to check for cancellation
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800895class AsyncEnd2endServerTryCancelTest : public AsyncEnd2endTest {
896 protected:
897 typedef enum {
898 DO_NOT_CANCEL = 0,
899 CANCEL_BEFORE_PROCESSING,
900 CANCEL_DURING_PROCESSING,
901 CANCEL_AFTER_PROCESSING
902 } ServerTryCancelRequestPhase;
903
Sree Kuchibhotla0f242ac2016-01-29 18:12:19 -0800904 // Helper for testing client-streaming RPCs which are cancelled on the server.
905 // Depending on the value of server_try_cancel parameter, this will test one
906 // of the following three scenarios:
907 // CANCEL_BEFORE_PROCESSING: Rpc is cancelled by the server before reading
908 // any messages from the client
909 //
910 // CANCEL_DURING_PROCESSING: Rpc is cancelled by the server while reading
911 // messages from the client
912 //
913 // CANCEL_AFTER PROCESSING: Rpc is cancelled by server after reading all
914 // messages from the client (but before sending any status back to the
915 // client)
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800916 void TestClientStreamingServerCancel(
917 ServerTryCancelRequestPhase server_try_cancel) {
918 ResetStub();
919
920 EchoRequest send_request;
921 EchoRequest recv_request;
922 EchoResponse send_response;
923 EchoResponse recv_response;
924 Status recv_status;
925
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800926 ClientContext cli_ctx;
927 ServerContext srv_ctx;
928 ServerAsyncReader<EchoResponse, EchoRequest> srv_stream(&srv_ctx);
929
930 // Initiate the 'RequestStream' call on client
931 std::unique_ptr<ClientAsyncWriter<EchoRequest>> cli_stream(
Sree Kuchibhotla4fb59082016-01-29 11:16:24 -0800932 stub_->AsyncRequestStream(&cli_ctx, &recv_response, cq_.get(), tag(1)));
Vijay Paidf8b62c2016-05-02 14:34:24 -0700933 Verifier(GetParam().disable_blocking).Expect(1, true).Verify(cq_.get());
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800934
935 // On the server, request to be notified of 'RequestStream' calls
936 // and receive the 'RequestStream' call just made by the client
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -0800937 srv_ctx.AsyncNotifyWhenDone(tag(11));
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800938 service_.RequestRequestStream(&srv_ctx, &srv_stream, cq_.get(), cq_.get(),
939 tag(2));
Vijay Paidf8b62c2016-05-02 14:34:24 -0700940 Verifier(GetParam().disable_blocking).Expect(2, true).Verify(cq_.get());
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800941
942 // Client sends 3 messages (tags 3, 4 and 5)
943 for (int tag_idx = 3; tag_idx <= 5; tag_idx++) {
Vijay Paia63271c2016-06-15 12:56:38 -0700944 send_request.set_message("Ping " + grpc::to_string(tag_idx));
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800945 cli_stream->Write(send_request, tag(tag_idx));
Vijay Paidf8b62c2016-05-02 14:34:24 -0700946 Verifier(GetParam().disable_blocking)
947 .Expect(tag_idx, true)
948 .Verify(cq_.get());
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800949 }
950 cli_stream->WritesDone(tag(6));
Vijay Paidf8b62c2016-05-02 14:34:24 -0700951 Verifier(GetParam().disable_blocking).Expect(6, true).Verify(cq_.get());
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800952
953 bool expected_server_cq_result = true;
954 bool ignore_cq_result = false;
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -0800955 bool want_done_tag = false;
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800956
957 if (server_try_cancel == CANCEL_BEFORE_PROCESSING) {
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -0800958 srv_ctx.TryCancel();
Vijay Paidf8b62c2016-05-02 14:34:24 -0700959 Verifier(GetParam().disable_blocking).Expect(11, true).Verify(cq_.get());
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -0800960 EXPECT_TRUE(srv_ctx.IsCancelled());
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800961
962 // Since cancellation is done before server reads any results, we know
963 // for sure that all cq results will return false from this point forward
964 expected_server_cq_result = false;
965 }
966
967 std::thread* server_try_cancel_thd = NULL;
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -0800968
Vijay Paidf8b62c2016-05-02 14:34:24 -0700969 auto verif = Verifier(GetParam().disable_blocking);
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -0800970
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800971 if (server_try_cancel == CANCEL_DURING_PROCESSING) {
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -0800972 server_try_cancel_thd =
973 new std::thread(&ServerContext::TryCancel, &srv_ctx);
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800974 // Server will cancel the RPC in a parallel thread while reading the
975 // requests from the client. Since the cancellation can happen at anytime,
976 // some of the cq results (i.e those until cancellation) might be true but
977 // its non deterministic. So better to ignore the cq results
978 ignore_cq_result = true;
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -0800979 // Expect that we might possibly see the done tag that
980 // indicates cancellation completion in this case
981 want_done_tag = true;
982 verif.Expect(11, true);
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800983 }
984
985 // Server reads 3 messages (tags 6, 7 and 8)
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -0800986 // But if want_done_tag is true, we might also see tag 11
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800987 for (int tag_idx = 6; tag_idx <= 8; tag_idx++) {
988 srv_stream.Read(&recv_request, tag(tag_idx));
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -0800989 // Note that we'll add something to the verifier and verify that
990 // something was seen, but it might be tag 11 and not what we
991 // just added
992 int got_tag = verif.Expect(tag_idx, expected_server_cq_result)
993 .Next(cq_.get(), ignore_cq_result);
994 GPR_ASSERT((got_tag == tag_idx) || (got_tag == 11 && want_done_tag));
995 if (got_tag == 11) {
996 EXPECT_TRUE(srv_ctx.IsCancelled());
997 want_done_tag = false;
998 // Now get the other entry that we were waiting on
999 EXPECT_EQ(verif.Next(cq_.get(), ignore_cq_result), tag_idx);
1000 }
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001001 }
1002
1003 if (server_try_cancel_thd != NULL) {
1004 server_try_cancel_thd->join();
1005 delete server_try_cancel_thd;
1006 }
1007
1008 if (server_try_cancel == CANCEL_AFTER_PROCESSING) {
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001009 srv_ctx.TryCancel();
1010 want_done_tag = true;
1011 verif.Expect(11, true);
1012 }
1013
1014 if (want_done_tag) {
1015 verif.Verify(cq_.get());
1016 EXPECT_TRUE(srv_ctx.IsCancelled());
1017 want_done_tag = false;
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001018 }
1019
Sree Kuchibhotla0f242ac2016-01-29 18:12:19 -08001020 // The RPC has been cancelled at this point for sure (i.e irrespective of
1021 // the value of `server_try_cancel` is). So, from this point forward, we
1022 // know that cq results are supposed to return false on server.
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001023
Sree Kuchibhotla0f242ac2016-01-29 18:12:19 -08001024 // Server sends the final message and cancelled status (but the RPC is
1025 // already cancelled at this point. So we expect the operation to fail)
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001026 srv_stream.Finish(send_response, Status::CANCELLED, tag(9));
Vijay Paidf8b62c2016-05-02 14:34:24 -07001027 Verifier(GetParam().disable_blocking).Expect(9, false).Verify(cq_.get());
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001028
Sree Kuchibhotla0f242ac2016-01-29 18:12:19 -08001029 // Client will see the cancellation
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001030 cli_stream->Finish(&recv_status, tag(10));
yang-g15759f62016-06-01 11:21:27 -07001031 Verifier(GetParam().disable_blocking).Expect(10, true).Verify(cq_.get());
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001032 EXPECT_FALSE(recv_status.ok());
1033 EXPECT_EQ(::grpc::StatusCode::CANCELLED, recv_status.error_code());
1034 }
1035
Sree Kuchibhotla0f242ac2016-01-29 18:12:19 -08001036 // Helper for testing server-streaming RPCs which are cancelled on the server.
1037 // Depending on the value of server_try_cancel parameter, this will test one
1038 // of the following three scenarios:
1039 // CANCEL_BEFORE_PROCESSING: Rpc is cancelled by the server before sending
1040 // any messages to the client
1041 //
1042 // CANCEL_DURING_PROCESSING: Rpc is cancelled by the server while sending
1043 // messages to the client
1044 //
1045 // CANCEL_AFTER PROCESSING: Rpc is cancelled by server after sending all
1046 // messages to the client (but before sending any status back to the
1047 // client)
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001048 void TestServerStreamingServerCancel(
1049 ServerTryCancelRequestPhase server_try_cancel) {
1050 ResetStub();
1051
1052 EchoRequest send_request;
1053 EchoRequest recv_request;
1054 EchoResponse send_response;
1055 EchoResponse recv_response;
1056 Status recv_status;
1057 ClientContext cli_ctx;
1058 ServerContext srv_ctx;
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001059 ServerAsyncWriter<EchoResponse> srv_stream(&srv_ctx);
1060
1061 send_request.set_message("Ping");
1062 // Initiate the 'ResponseStream' call on the client
1063 std::unique_ptr<ClientAsyncReader<EchoResponse>> cli_stream(
Sree Kuchibhotla4fb59082016-01-29 11:16:24 -08001064 stub_->AsyncResponseStream(&cli_ctx, send_request, cq_.get(), tag(1)));
Vijay Paidf8b62c2016-05-02 14:34:24 -07001065 Verifier(GetParam().disable_blocking).Expect(1, true).Verify(cq_.get());
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001066 // On the server, request to be notified of 'ResponseStream' calls and
1067 // receive the call just made by the client
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001068 srv_ctx.AsyncNotifyWhenDone(tag(11));
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001069 service_.RequestResponseStream(&srv_ctx, &recv_request, &srv_stream,
1070 cq_.get(), cq_.get(), tag(2));
Vijay Paidf8b62c2016-05-02 14:34:24 -07001071 Verifier(GetParam().disable_blocking).Expect(2, true).Verify(cq_.get());
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001072 EXPECT_EQ(send_request.message(), recv_request.message());
1073
1074 bool expected_cq_result = true;
1075 bool ignore_cq_result = false;
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001076 bool want_done_tag = false;
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001077
1078 if (server_try_cancel == CANCEL_BEFORE_PROCESSING) {
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001079 srv_ctx.TryCancel();
Vijay Paidf8b62c2016-05-02 14:34:24 -07001080 Verifier(GetParam().disable_blocking).Expect(11, true).Verify(cq_.get());
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001081 EXPECT_TRUE(srv_ctx.IsCancelled());
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001082
1083 // We know for sure that all cq results will be false from this point
1084 // since the server cancelled the RPC
1085 expected_cq_result = false;
1086 }
1087
1088 std::thread* server_try_cancel_thd = NULL;
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001089
Vijay Paidf8b62c2016-05-02 14:34:24 -07001090 auto verif = Verifier(GetParam().disable_blocking);
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001091
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001092 if (server_try_cancel == CANCEL_DURING_PROCESSING) {
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001093 server_try_cancel_thd =
1094 new std::thread(&ServerContext::TryCancel, &srv_ctx);
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001095
1096 // Server will cancel the RPC in a parallel thread while writing responses
1097 // to the client. Since the cancellation can happen at anytime, some of
Sree Kuchibhotla0f242ac2016-01-29 18:12:19 -08001098 // the cq results (i.e those until cancellation) might be true but it is
1099 // non deterministic. So better to ignore the cq results
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001100 ignore_cq_result = true;
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001101 // Expect that we might possibly see the done tag that
1102 // indicates cancellation completion in this case
1103 want_done_tag = true;
1104 verif.Expect(11, true);
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001105 }
1106
1107 // Server sends three messages (tags 3, 4 and 5)
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001108 // But if want_done tag is true, we might also see tag 11
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001109 for (int tag_idx = 3; tag_idx <= 5; tag_idx++) {
Vijay Paia63271c2016-06-15 12:56:38 -07001110 send_response.set_message("Pong " + grpc::to_string(tag_idx));
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001111 srv_stream.Write(send_response, tag(tag_idx));
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001112 // Note that we'll add something to the verifier and verify that
1113 // something was seen, but it might be tag 11 and not what we
1114 // just added
1115 int got_tag = verif.Expect(tag_idx, expected_cq_result)
1116 .Next(cq_.get(), ignore_cq_result);
1117 GPR_ASSERT((got_tag == tag_idx) || (got_tag == 11 && want_done_tag));
1118 if (got_tag == 11) {
1119 EXPECT_TRUE(srv_ctx.IsCancelled());
1120 want_done_tag = false;
1121 // Now get the other entry that we were waiting on
1122 EXPECT_EQ(verif.Next(cq_.get(), ignore_cq_result), tag_idx);
1123 }
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001124 }
1125
Sree Kuchibhotla0f242ac2016-01-29 18:12:19 -08001126 if (server_try_cancel_thd != NULL) {
1127 server_try_cancel_thd->join();
1128 delete server_try_cancel_thd;
1129 }
1130
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001131 if (server_try_cancel == CANCEL_AFTER_PROCESSING) {
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001132 srv_ctx.TryCancel();
1133 want_done_tag = true;
1134 verif.Expect(11, true);
yang-gad0df7b2016-02-22 10:00:20 -08001135
1136 // Client reads may fail bacause it is notified that the stream is
1137 // cancelled.
1138 ignore_cq_result = true;
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001139 }
1140
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001141 if (want_done_tag) {
1142 verif.Verify(cq_.get());
1143 EXPECT_TRUE(srv_ctx.IsCancelled());
1144 want_done_tag = false;
1145 }
1146
Sree Kuchibhotla0f242ac2016-01-29 18:12:19 -08001147 // Client attemts to read the three messages from the server
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001148 for (int tag_idx = 6; tag_idx <= 8; tag_idx++) {
1149 cli_stream->Read(&recv_response, tag(tag_idx));
Vijay Paidf8b62c2016-05-02 14:34:24 -07001150 Verifier(GetParam().disable_blocking)
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001151 .Expect(tag_idx, expected_cq_result)
Sree Kuchibhotla4fb59082016-01-29 11:16:24 -08001152 .Verify(cq_.get(), ignore_cq_result);
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001153 }
1154
Sree Kuchibhotla0f242ac2016-01-29 18:12:19 -08001155 // The RPC has been cancelled at this point for sure (i.e irrespective of
1156 // the value of `server_try_cancel` is). So, from this point forward, we
1157 // know that cq results are supposed to return false on server.
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001158
Sree Kuchibhotla0f242ac2016-01-29 18:12:19 -08001159 // Server finishes the stream (but the RPC is already cancelled)
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001160 srv_stream.Finish(Status::CANCELLED, tag(9));
Vijay Paidf8b62c2016-05-02 14:34:24 -07001161 Verifier(GetParam().disable_blocking).Expect(9, false).Verify(cq_.get());
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001162
Sree Kuchibhotla0f242ac2016-01-29 18:12:19 -08001163 // Client will see the cancellation
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001164 cli_stream->Finish(&recv_status, tag(10));
Vijay Paidf8b62c2016-05-02 14:34:24 -07001165 Verifier(GetParam().disable_blocking).Expect(10, true).Verify(cq_.get());
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001166 EXPECT_FALSE(recv_status.ok());
1167 EXPECT_EQ(::grpc::StatusCode::CANCELLED, recv_status.error_code());
1168 }
1169
Sree Kuchibhotla0f242ac2016-01-29 18:12:19 -08001170 // Helper for testing bidirectinal-streaming RPCs which are cancelled on the
1171 // server.
1172 //
1173 // Depending on the value of server_try_cancel parameter, this will
1174 // test one of the following three scenarios:
1175 // CANCEL_BEFORE_PROCESSING: Rpc is cancelled by the server before reading/
1176 // writing any messages from/to the client
1177 //
1178 // CANCEL_DURING_PROCESSING: Rpc is cancelled by the server while reading
1179 // messages from the client
1180 //
1181 // CANCEL_AFTER PROCESSING: Rpc is cancelled by server after reading all
1182 // messages from the client (but before sending any status back to the
1183 // client)
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001184 void TestBidiStreamingServerCancel(
1185 ServerTryCancelRequestPhase server_try_cancel) {
1186 ResetStub();
1187
1188 EchoRequest send_request;
1189 EchoRequest recv_request;
1190 EchoResponse send_response;
1191 EchoResponse recv_response;
1192 Status recv_status;
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001193 ClientContext cli_ctx;
1194 ServerContext srv_ctx;
1195 ServerAsyncReaderWriter<EchoResponse, EchoRequest> srv_stream(&srv_ctx);
1196
1197 // Initiate the call from the client side
1198 std::unique_ptr<ClientAsyncReaderWriter<EchoRequest, EchoResponse>>
Sree Kuchibhotla4fb59082016-01-29 11:16:24 -08001199 cli_stream(stub_->AsyncBidiStream(&cli_ctx, cq_.get(), tag(1)));
Vijay Paidf8b62c2016-05-02 14:34:24 -07001200 Verifier(GetParam().disable_blocking).Expect(1, true).Verify(cq_.get());
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001201
1202 // On the server, request to be notified of the 'BidiStream' call and
1203 // receive the call just made by the client
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001204 srv_ctx.AsyncNotifyWhenDone(tag(11));
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001205 service_.RequestBidiStream(&srv_ctx, &srv_stream, cq_.get(), cq_.get(),
1206 tag(2));
Vijay Paidf8b62c2016-05-02 14:34:24 -07001207 Verifier(GetParam().disable_blocking).Expect(2, true).Verify(cq_.get());
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001208
Sree Kuchibhotla0f242ac2016-01-29 18:12:19 -08001209 // Client sends the first and the only message
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001210 send_request.set_message("Ping");
1211 cli_stream->Write(send_request, tag(3));
Vijay Paidf8b62c2016-05-02 14:34:24 -07001212 Verifier(GetParam().disable_blocking).Expect(3, true).Verify(cq_.get());
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001213
1214 bool expected_cq_result = true;
1215 bool ignore_cq_result = false;
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001216 bool want_done_tag = false;
Sree Kuchibhotla0f242ac2016-01-29 18:12:19 -08001217
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001218 if (server_try_cancel == CANCEL_BEFORE_PROCESSING) {
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001219 srv_ctx.TryCancel();
Vijay Paidf8b62c2016-05-02 14:34:24 -07001220 Verifier(GetParam().disable_blocking).Expect(11, true).Verify(cq_.get());
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001221 EXPECT_TRUE(srv_ctx.IsCancelled());
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001222
1223 // We know for sure that all cq results will be false from this point
1224 // since the server cancelled the RPC
1225 expected_cq_result = false;
1226 }
1227
1228 std::thread* server_try_cancel_thd = NULL;
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001229
Vijay Paidf8b62c2016-05-02 14:34:24 -07001230 auto verif = Verifier(GetParam().disable_blocking);
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001231
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001232 if (server_try_cancel == CANCEL_DURING_PROCESSING) {
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001233 server_try_cancel_thd =
1234 new std::thread(&ServerContext::TryCancel, &srv_ctx);
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001235
1236 // Since server is going to cancel the RPC in a parallel thread, some of
1237 // the cq results (i.e those until the cancellation) might be true. Since
1238 // that number is non-deterministic, it is better to ignore the cq results
1239 ignore_cq_result = true;
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001240 // Expect that we might possibly see the done tag that
1241 // indicates cancellation completion in this case
1242 want_done_tag = true;
1243 verif.Expect(11, true);
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001244 }
1245
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001246 int got_tag;
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001247 srv_stream.Read(&recv_request, tag(4));
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001248 verif.Expect(4, expected_cq_result);
1249 got_tag = verif.Next(cq_.get(), ignore_cq_result);
1250 GPR_ASSERT((got_tag == 4) || (got_tag == 11 && want_done_tag));
1251 if (got_tag == 11) {
1252 EXPECT_TRUE(srv_ctx.IsCancelled());
1253 want_done_tag = false;
1254 // Now get the other entry that we were waiting on
1255 EXPECT_EQ(verif.Next(cq_.get(), ignore_cq_result), 4);
1256 }
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001257
1258 send_response.set_message("Pong");
1259 srv_stream.Write(send_response, tag(5));
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001260 verif.Expect(5, expected_cq_result);
1261 got_tag = verif.Next(cq_.get(), ignore_cq_result);
1262 GPR_ASSERT((got_tag == 5) || (got_tag == 11 && want_done_tag));
1263 if (got_tag == 11) {
1264 EXPECT_TRUE(srv_ctx.IsCancelled());
1265 want_done_tag = false;
1266 // Now get the other entry that we were waiting on
1267 EXPECT_EQ(verif.Next(cq_.get(), ignore_cq_result), 5);
1268 }
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001269
1270 cli_stream->Read(&recv_response, tag(6));
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001271 verif.Expect(6, expected_cq_result);
1272 got_tag = verif.Next(cq_.get(), ignore_cq_result);
1273 GPR_ASSERT((got_tag == 6) || (got_tag == 11 && want_done_tag));
1274 if (got_tag == 11) {
1275 EXPECT_TRUE(srv_ctx.IsCancelled());
1276 want_done_tag = false;
1277 // Now get the other entry that we were waiting on
1278 EXPECT_EQ(verif.Next(cq_.get(), ignore_cq_result), 6);
1279 }
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001280
1281 // This is expected to succeed in all cases
1282 cli_stream->WritesDone(tag(7));
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001283 verif.Expect(7, true);
1284 got_tag = verif.Next(cq_.get(), ignore_cq_result);
1285 GPR_ASSERT((got_tag == 7) || (got_tag == 11 && want_done_tag));
1286 if (got_tag == 11) {
1287 EXPECT_TRUE(srv_ctx.IsCancelled());
1288 want_done_tag = false;
1289 // Now get the other entry that we were waiting on
1290 EXPECT_EQ(verif.Next(cq_.get(), ignore_cq_result), 7);
1291 }
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001292
Sree Kuchibhotla0f242ac2016-01-29 18:12:19 -08001293 // This is expected to fail in all cases i.e for all values of
Vijay Pai018879a2016-02-16 09:20:50 -08001294 // server_try_cancel. This is because at this point, either there are no
Sree Kuchibhotla0f242ac2016-01-29 18:12:19 -08001295 // more msgs from the client (because client called WritesDone) or the RPC
1296 // is cancelled on the server
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001297 srv_stream.Read(&recv_request, tag(8));
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001298 verif.Expect(8, false);
1299 got_tag = verif.Next(cq_.get(), ignore_cq_result);
1300 GPR_ASSERT((got_tag == 8) || (got_tag == 11 && want_done_tag));
1301 if (got_tag == 11) {
1302 EXPECT_TRUE(srv_ctx.IsCancelled());
1303 want_done_tag = false;
1304 // Now get the other entry that we were waiting on
1305 EXPECT_EQ(verif.Next(cq_.get(), ignore_cq_result), 8);
1306 }
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001307
1308 if (server_try_cancel_thd != NULL) {
1309 server_try_cancel_thd->join();
1310 delete server_try_cancel_thd;
1311 }
1312
1313 if (server_try_cancel == CANCEL_AFTER_PROCESSING) {
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001314 srv_ctx.TryCancel();
1315 want_done_tag = true;
1316 verif.Expect(11, true);
1317 }
1318
1319 if (want_done_tag) {
1320 verif.Verify(cq_.get());
1321 EXPECT_TRUE(srv_ctx.IsCancelled());
1322 want_done_tag = false;
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001323 }
1324
Sree Kuchibhotla0f242ac2016-01-29 18:12:19 -08001325 // The RPC has been cancelled at this point for sure (i.e irrespective of
1326 // the value of `server_try_cancel` is). So, from this point forward, we
1327 // know that cq results are supposed to return false on server.
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001328
1329 srv_stream.Finish(Status::CANCELLED, tag(9));
Vijay Paidf8b62c2016-05-02 14:34:24 -07001330 Verifier(GetParam().disable_blocking).Expect(9, false).Verify(cq_.get());
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001331
1332 cli_stream->Finish(&recv_status, tag(10));
Vijay Paidf8b62c2016-05-02 14:34:24 -07001333 Verifier(GetParam().disable_blocking).Expect(10, true).Verify(cq_.get());
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001334 EXPECT_FALSE(recv_status.ok());
1335 EXPECT_EQ(grpc::StatusCode::CANCELLED, recv_status.error_code());
1336 }
1337};
1338
1339TEST_P(AsyncEnd2endServerTryCancelTest, ClientStreamingServerTryCancelBefore) {
1340 TestClientStreamingServerCancel(CANCEL_BEFORE_PROCESSING);
1341}
1342
1343TEST_P(AsyncEnd2endServerTryCancelTest, ClientStreamingServerTryCancelDuring) {
1344 TestClientStreamingServerCancel(CANCEL_DURING_PROCESSING);
1345}
1346
1347TEST_P(AsyncEnd2endServerTryCancelTest, ClientStreamingServerTryCancelAfter) {
1348 TestClientStreamingServerCancel(CANCEL_AFTER_PROCESSING);
1349}
1350
1351TEST_P(AsyncEnd2endServerTryCancelTest, ServerStreamingServerTryCancelBefore) {
1352 TestServerStreamingServerCancel(CANCEL_BEFORE_PROCESSING);
1353}
1354
1355TEST_P(AsyncEnd2endServerTryCancelTest, ServerStreamingServerTryCancelDuring) {
1356 TestServerStreamingServerCancel(CANCEL_DURING_PROCESSING);
1357}
1358
1359TEST_P(AsyncEnd2endServerTryCancelTest, ServerStreamingServerTryCancelAfter) {
1360 TestServerStreamingServerCancel(CANCEL_AFTER_PROCESSING);
1361}
1362
1363TEST_P(AsyncEnd2endServerTryCancelTest, ServerBidiStreamingTryCancelBefore) {
1364 TestBidiStreamingServerCancel(CANCEL_BEFORE_PROCESSING);
1365}
1366
1367TEST_P(AsyncEnd2endServerTryCancelTest, ServerBidiStreamingTryCancelDuring) {
1368 TestBidiStreamingServerCancel(CANCEL_DURING_PROCESSING);
1369}
1370
1371TEST_P(AsyncEnd2endServerTryCancelTest, ServerBidiStreamingTryCancelAfter) {
1372 TestBidiStreamingServerCancel(CANCEL_AFTER_PROCESSING);
1373}
1374
Vijay Paidf8b62c2016-05-02 14:34:24 -07001375std::vector<TestScenario> CreateTestScenarios(bool test_disable_blocking,
Vijay Paid7b1e702016-05-02 15:10:21 -07001376 bool test_secure,
1377 int test_big_limit) {
Vijay Paidf8b62c2016-05-02 14:34:24 -07001378 std::vector<TestScenario> scenarios;
1379 std::vector<grpc::string> credentials_types;
Vijay Paid7b1e702016-05-02 15:10:21 -07001380 std::vector<grpc::string> messages;
1381
Vijay Paidf8b62c2016-05-02 14:34:24 -07001382 credentials_types.push_back(kInsecureCredentialsType);
Vijay Paid7b1e702016-05-02 15:10:21 -07001383 auto sec_list = GetSecureCredentialsTypeList();
1384 for (auto sec = sec_list.begin(); sec != sec_list.end(); sec++) {
1385 credentials_types.push_back(*sec);
1386 }
1387
1388 messages.push_back("Hello");
1389 for (int sz = 1; sz < test_big_limit; sz *= 2) {
1390 grpc::string big_msg;
1391 for (int i = 0; i < sz * 1024; i++) {
1392 char c = 'a' + (i % 26);
1393 big_msg += c;
1394 }
1395 messages.push_back(big_msg);
1396 }
1397
1398 for (auto cred = credentials_types.begin(); cred != credentials_types.end();
1399 ++cred) {
1400 for (auto msg = messages.begin(); msg != messages.end(); msg++) {
Vijay Pai679c75f2016-06-15 13:08:00 -07001401 scenarios.emplace_back(false, *cred, *msg);
Vijay Paid7b1e702016-05-02 15:10:21 -07001402 if (test_disable_blocking) {
Vijay Pai679c75f2016-06-15 13:08:00 -07001403 scenarios.emplace_back(true, *cred, *msg);
Vijay Paid7b1e702016-05-02 15:10:21 -07001404 }
Vijay Paidf8b62c2016-05-02 14:34:24 -07001405 }
1406 }
1407 return scenarios;
1408}
1409
Craig Tiller4c06b822015-08-06 08:41:31 -07001410INSTANTIATE_TEST_CASE_P(AsyncEnd2end, AsyncEnd2endTest,
Vijay Paid7b1e702016-05-02 15:10:21 -07001411 ::testing::ValuesIn(CreateTestScenarios(true, true,
1412 1024)));
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001413INSTANTIATE_TEST_CASE_P(AsyncEnd2endServerTryCancel,
1414 AsyncEnd2endServerTryCancelTest,
Vijay Paid7b1e702016-05-02 15:10:21 -07001415 ::testing::ValuesIn(CreateTestScenarios(false, false,
1416 0)));
Craig Tiller69f90e62015-08-06 08:32:35 -07001417
Craig Tiller0220cf12015-02-12 17:39:26 -08001418} // namespace
1419} // namespace testing
1420} // namespace grpc
1421
1422int main(int argc, char** argv) {
1423 grpc_test_init(argc, argv);
Vijay Paib65eda42016-02-16 13:48:05 -08001424 gpr_tls_init(&g_is_async_end2end_test);
Craig Tiller0220cf12015-02-12 17:39:26 -08001425 ::testing::InitGoogleTest(&argc, argv);
Vijay Paib65eda42016-02-16 13:48:05 -08001426 int ret = RUN_ALL_TESTS();
1427 gpr_tls_destroy(&g_is_async_end2end_test);
1428 return ret;
Craig Tiller0220cf12015-02-12 17:39:26 -08001429}