blob: e0649bd694864c1d850bd3f5ebd55a4f7968534e [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
210 void UpdatePlugins(
211 std::map<grpc::string, std::unique_ptr<ServerBuilderPlugin>>* plugins)
212 GRPC_OVERRIDE {
213 auto plugin = plugins->begin();
214 while (plugin != plugins->end()) {
215 if ((*plugin).second->has_sync_methods()) {
216 plugins->erase(plugin++);
217 } else {
218 plugin++;
219 }
220 }
221 }
222};
223
Vijay Paidf8b62c2016-05-02 14:34:24 -0700224class TestScenario {
225 public:
Vijay Paid7b1e702016-05-02 15:10:21 -0700226 TestScenario(bool non_block, const grpc::string& creds_type,
227 const grpc::string& content)
228 : disable_blocking(non_block),
229 credentials_type(creds_type),
230 message_content(content) {}
231 void Log() const {
232 gpr_log(GPR_INFO,
233 "Scenario: disable_blocking %d, credentials %s, message size %d",
234 disable_blocking, credentials_type.c_str(), message_content.size());
235 }
Vijay Paidf8b62c2016-05-02 14:34:24 -0700236 bool disable_blocking;
237 const grpc::string credentials_type;
Vijay Paid7b1e702016-05-02 15:10:21 -0700238 const grpc::string message_content;
Vijay Paidf8b62c2016-05-02 14:34:24 -0700239};
240
241class AsyncEnd2endTest : public ::testing::TestWithParam<TestScenario> {
Craig Tiller0220cf12015-02-12 17:39:26 -0800242 protected:
Vijay Paid7b1e702016-05-02 15:10:21 -0700243 AsyncEnd2endTest() { GetParam().Log(); }
Craig Tiller0220cf12015-02-12 17:39:26 -0800244
Craig Tillercf133f42015-02-26 14:05:56 -0800245 void SetUp() GRPC_OVERRIDE {
Vijay Paidf8b62c2016-05-02 14:34:24 -0700246 poll_overrider_.reset(new PollingOverrider(!GetParam().disable_blocking));
Vijay Pai018879a2016-02-16 09:20:50 -0800247
Craig Tiller0220cf12015-02-12 17:39:26 -0800248 int port = grpc_pick_unused_port_or_die();
249 server_address_ << "localhost:" << port;
vjpai017ed622015-12-09 10:42:54 -0800250
Craig Tiller0220cf12015-02-12 17:39:26 -0800251 // Setup server
252 ServerBuilder builder;
Vijay Paidf8b62c2016-05-02 14:34:24 -0700253 auto server_creds = GetServerCredentials(GetParam().credentials_type);
254 builder.AddListeningPort(server_address_.str(), server_creds);
Craig Tiller15f383c2016-01-07 12:45:32 -0800255 builder.RegisterService(&service_);
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700256 cq_ = builder.AddCompletionQueue();
Yuchen Zenga42ec212016-04-29 13:03:06 -0700257
258 // TODO(zyc): make a test option to choose wheather sync plugins should be
259 // deleted
260 std::unique_ptr<ServerBuilderOption> sync_plugin_disabler(
261 new ServerBuilderSyncPluginDisabler());
262 builder.SetOption(move(sync_plugin_disabler));
Craig Tiller0220cf12015-02-12 17:39:26 -0800263 server_ = builder.BuildAndStart();
Vijay Paib65eda42016-02-16 13:48:05 -0800264
265 gpr_tls_set(&g_is_async_end2end_test, 1);
Craig Tiller0220cf12015-02-12 17:39:26 -0800266 }
267
Craig Tillercf133f42015-02-26 14:05:56 -0800268 void TearDown() GRPC_OVERRIDE {
Craig Tiller492968f2015-02-18 13:14:03 -0800269 server_->Shutdown();
270 void* ignored_tag;
271 bool ignored_ok;
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700272 cq_->Shutdown();
273 while (cq_->Next(&ignored_tag, &ignored_ok))
Craig Tiller492968f2015-02-18 13:14:03 -0800274 ;
Vijay Pai018879a2016-02-16 09:20:50 -0800275 poll_overrider_.reset();
Vijay Paib65eda42016-02-16 13:48:05 -0800276 gpr_tls_set(&g_is_async_end2end_test, 0);
Craig Tiller492968f2015-02-18 13:14:03 -0800277 }
Craig Tiller0220cf12015-02-12 17:39:26 -0800278
279 void ResetStub() {
Vijay Paidf8b62c2016-05-02 14:34:24 -0700280 ChannelArguments args;
281 auto channel_creds =
282 GetChannelCredentials(GetParam().credentials_type, &args);
yang-g730055d2015-08-27 12:29:45 -0700283 std::shared_ptr<Channel> channel =
Vijay Paidf8b62c2016-05-02 14:34:24 -0700284 CreateCustomChannel(server_address_.str(), channel_creds, args);
Sree Kuchibhotla5a05f512016-01-13 22:43:20 -0800285 stub_ = grpc::testing::EchoTestService::NewStub(channel);
Craig Tiller0220cf12015-02-12 17:39:26 -0800286 }
287
Yang Gao406b32f2015-02-13 16:25:33 -0800288 void SendRpc(int num_rpcs) {
289 for (int i = 0; i < num_rpcs; i++) {
290 EchoRequest send_request;
291 EchoRequest recv_request;
292 EchoResponse send_response;
293 EchoResponse recv_response;
294 Status recv_status;
295
296 ClientContext cli_ctx;
297 ServerContext srv_ctx;
298 grpc::ServerAsyncResponseWriter<EchoResponse> response_writer(&srv_ctx);
299
Vijay Paid7b1e702016-05-02 15:10:21 -0700300 send_request.set_message(GetParam().message_content);
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800301 std::unique_ptr<ClientAsyncResponseReader<EchoResponse>> response_reader(
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700302 stub_->AsyncEcho(&cli_ctx, send_request, cq_.get()));
Yang Gao406b32f2015-02-13 16:25:33 -0800303
Craig Tillerd6c98df2015-08-18 09:33:44 -0700304 service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, cq_.get(),
305 cq_.get(), tag(2));
Yang Gao406b32f2015-02-13 16:25:33 -0800306
Vijay Paidf8b62c2016-05-02 14:34:24 -0700307 Verifier(GetParam().disable_blocking).Expect(2, true).Verify(cq_.get());
Yang Gao406b32f2015-02-13 16:25:33 -0800308 EXPECT_EQ(send_request.message(), recv_request.message());
309
310 send_response.set_message(recv_request.message());
311 response_writer.Finish(send_response, Status::OK, tag(3));
Yang Gao3a5e5492015-02-18 14:32:38 -0800312 response_reader->Finish(&recv_response, &recv_status, tag(4));
Craig Tillere4d27482016-05-03 12:19:33 -0700313 Verifier(GetParam().disable_blocking)
314 .Expect(3, true)
315 .Expect(4, true)
316 .Verify(cq_.get());
Yang Gao406b32f2015-02-13 16:25:33 -0800317
318 EXPECT_EQ(send_response.message(), recv_response.message());
Yang Gaoc1a2c312015-06-16 10:59:46 -0700319 EXPECT_TRUE(recv_status.ok());
Yang Gao406b32f2015-02-13 16:25:33 -0800320 }
321 }
322
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700323 std::unique_ptr<ServerCompletionQueue> cq_;
Sree Kuchibhotla5a05f512016-01-13 22:43:20 -0800324 std::unique_ptr<grpc::testing::EchoTestService::Stub> stub_;
Craig Tiller0220cf12015-02-12 17:39:26 -0800325 std::unique_ptr<Server> server_;
Sree Kuchibhotla5a05f512016-01-13 22:43:20 -0800326 grpc::testing::EchoTestService::AsyncService service_;
Craig Tiller0220cf12015-02-12 17:39:26 -0800327 std::ostringstream server_address_;
vjpaicf4daeb2016-02-15 02:33:54 -0800328
Vijay Pai018879a2016-02-16 09:20:50 -0800329 std::unique_ptr<PollingOverrider> poll_overrider_;
Craig Tiller0220cf12015-02-12 17:39:26 -0800330};
331
Craig Tiller69f90e62015-08-06 08:32:35 -0700332TEST_P(AsyncEnd2endTest, SimpleRpc) {
Craig Tiller0220cf12015-02-12 17:39:26 -0800333 ResetStub();
Yang Gao406b32f2015-02-13 16:25:33 -0800334 SendRpc(1);
335}
Yang Gaobb84a302015-02-12 23:30:12 -0800336
Craig Tiller69f90e62015-08-06 08:32:35 -0700337TEST_P(AsyncEnd2endTest, SequentialRpcs) {
Yang Gao406b32f2015-02-13 16:25:33 -0800338 ResetStub();
339 SendRpc(10);
Craig Tiller0220cf12015-02-12 17:39:26 -0800340}
341
vjpai7aadf462015-03-16 23:58:44 -0700342// Test a simple RPC using the async version of Next
Craig Tiller69f90e62015-08-06 08:32:35 -0700343TEST_P(AsyncEnd2endTest, AsyncNextRpc) {
vjpai7aadf462015-03-16 23:58:44 -0700344 ResetStub();
345
346 EchoRequest send_request;
347 EchoRequest recv_request;
348 EchoResponse send_response;
349 EchoResponse recv_response;
350 Status recv_status;
351
352 ClientContext cli_ctx;
353 ServerContext srv_ctx;
354 grpc::ServerAsyncResponseWriter<EchoResponse> response_writer(&srv_ctx);
355
Vijay Paid7b1e702016-05-02 15:10:21 -0700356 send_request.set_message(GetParam().message_content);
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800357 std::unique_ptr<ClientAsyncResponseReader<EchoResponse>> response_reader(
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700358 stub_->AsyncEcho(&cli_ctx, send_request, cq_.get()));
vjpai7aadf462015-03-16 23:58:44 -0700359
Yang Gao757afae2015-03-17 15:49:26 -0700360 std::chrono::system_clock::time_point time_now(
Craig Tillerf51199f2015-05-08 09:32:53 -0700361 std::chrono::system_clock::now());
362 std::chrono::system_clock::time_point time_limit(
363 std::chrono::system_clock::now() + std::chrono::seconds(10));
Vijay Paidf8b62c2016-05-02 14:34:24 -0700364 Verifier(GetParam().disable_blocking).Verify(cq_.get(), time_now);
365 Verifier(GetParam().disable_blocking).Verify(cq_.get(), time_now);
vjpai7aadf462015-03-16 23:58:44 -0700366
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700367 service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, cq_.get(),
368 cq_.get(), tag(2));
vjpai7aadf462015-03-16 23:58:44 -0700369
Vijay Paidf8b62c2016-05-02 14:34:24 -0700370 Verifier(GetParam().disable_blocking)
371 .Expect(2, true)
372 .Verify(cq_.get(), time_limit);
vjpai7aadf462015-03-16 23:58:44 -0700373 EXPECT_EQ(send_request.message(), recv_request.message());
vjpai7aadf462015-03-16 23:58:44 -0700374
375 send_response.set_message(recv_request.message());
376 response_writer.Finish(send_response, Status::OK, tag(3));
vjpai7aadf462015-03-16 23:58:44 -0700377 response_reader->Finish(&recv_response, &recv_status, tag(4));
Vijay Paidf8b62c2016-05-02 14:34:24 -0700378 Verifier(GetParam().disable_blocking)
Craig Tillere4d27482016-05-03 12:19:33 -0700379 .Expect(3, true)
Craig Tiller4c06b822015-08-06 08:41:31 -0700380 .Expect(4, true)
381 .Verify(cq_.get(), std::chrono::system_clock::time_point::max());
vjpai7aadf462015-03-16 23:58:44 -0700382
383 EXPECT_EQ(send_response.message(), recv_response.message());
Yang Gaoc1a2c312015-06-16 10:59:46 -0700384 EXPECT_TRUE(recv_status.ok());
vjpai7aadf462015-03-16 23:58:44 -0700385}
Yang Gao757afae2015-03-17 15:49:26 -0700386
Yang Gao0e0d8e12015-02-13 14:40:41 -0800387// Two pings and a final pong.
Craig Tiller69f90e62015-08-06 08:32:35 -0700388TEST_P(AsyncEnd2endTest, SimpleClientStreaming) {
Yang Gao005f18a2015-02-13 10:22:33 -0800389 ResetStub();
390
391 EchoRequest send_request;
392 EchoRequest recv_request;
393 EchoResponse send_response;
394 EchoResponse recv_response;
395 Status recv_status;
396 ClientContext cli_ctx;
397 ServerContext srv_ctx;
398 ServerAsyncReader<EchoResponse, EchoRequest> srv_stream(&srv_ctx);
399
Vijay Paid7b1e702016-05-02 15:10:21 -0700400 send_request.set_message(GetParam().message_content);
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800401 std::unique_ptr<ClientAsyncWriter<EchoRequest>> cli_stream(
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700402 stub_->AsyncRequestStream(&cli_ctx, &recv_response, cq_.get(), tag(1)));
Yang Gao005f18a2015-02-13 10:22:33 -0800403
Craig Tillerd6c98df2015-08-18 09:33:44 -0700404 service_.RequestRequestStream(&srv_ctx, &srv_stream, cq_.get(), cq_.get(),
405 tag(2));
Yang Gao005f18a2015-02-13 10:22:33 -0800406
Vijay Paidf8b62c2016-05-02 14:34:24 -0700407 Verifier(GetParam().disable_blocking)
408 .Expect(2, true)
409 .Expect(1, true)
410 .Verify(cq_.get());
Yang Gao005f18a2015-02-13 10:22:33 -0800411
412 cli_stream->Write(send_request, tag(3));
Yang Gao005f18a2015-02-13 10:22:33 -0800413 srv_stream.Read(&recv_request, tag(4));
Craig Tillere4d27482016-05-03 12:19:33 -0700414 Verifier(GetParam().disable_blocking)
415 .Expect(3, true)
416 .Expect(4, true)
417 .Verify(cq_.get());
Yang Gao005f18a2015-02-13 10:22:33 -0800418 EXPECT_EQ(send_request.message(), recv_request.message());
419
420 cli_stream->Write(send_request, tag(5));
Yang Gao005f18a2015-02-13 10:22:33 -0800421 srv_stream.Read(&recv_request, tag(6));
Craig Tillere4d27482016-05-03 12:19:33 -0700422 Verifier(GetParam().disable_blocking)
423 .Expect(5, true)
424 .Expect(6, true)
425 .Verify(cq_.get());
Yang Gao005f18a2015-02-13 10:22:33 -0800426
427 EXPECT_EQ(send_request.message(), recv_request.message());
428 cli_stream->WritesDone(tag(7));
Yang Gao005f18a2015-02-13 10:22:33 -0800429 srv_stream.Read(&recv_request, tag(8));
Craig Tillere4d27482016-05-03 12:19:33 -0700430 Verifier(GetParam().disable_blocking)
431 .Expect(7, true)
432 .Expect(8, false)
433 .Verify(cq_.get());
Yang Gao005f18a2015-02-13 10:22:33 -0800434
435 send_response.set_message(recv_request.message());
436 srv_stream.Finish(send_response, Status::OK, tag(9));
Yang Gao005f18a2015-02-13 10:22:33 -0800437 cli_stream->Finish(&recv_status, tag(10));
Craig Tillere4d27482016-05-03 12:19:33 -0700438 Verifier(GetParam().disable_blocking)
439 .Expect(9, true)
440 .Expect(10, true)
441 .Verify(cq_.get());
Yang Gao005f18a2015-02-13 10:22:33 -0800442
443 EXPECT_EQ(send_response.message(), recv_response.message());
Yang Gaoc1a2c312015-06-16 10:59:46 -0700444 EXPECT_TRUE(recv_status.ok());
Yang Gao005f18a2015-02-13 10:22:33 -0800445}
446
Yang Gao0e0d8e12015-02-13 14:40:41 -0800447// One ping, two pongs.
Craig Tiller69f90e62015-08-06 08:32:35 -0700448TEST_P(AsyncEnd2endTest, SimpleServerStreaming) {
Yang Gao0e0d8e12015-02-13 14:40:41 -0800449 ResetStub();
450
451 EchoRequest send_request;
452 EchoRequest recv_request;
453 EchoResponse send_response;
454 EchoResponse recv_response;
455 Status recv_status;
456 ClientContext cli_ctx;
457 ServerContext srv_ctx;
458 ServerAsyncWriter<EchoResponse> srv_stream(&srv_ctx);
459
Vijay Paid7b1e702016-05-02 15:10:21 -0700460 send_request.set_message(GetParam().message_content);
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800461 std::unique_ptr<ClientAsyncReader<EchoResponse>> cli_stream(
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700462 stub_->AsyncResponseStream(&cli_ctx, send_request, cq_.get(), tag(1)));
Yang Gao0e0d8e12015-02-13 14:40:41 -0800463
Craig Tillerf9e6adf2015-05-06 11:45:59 -0700464 service_.RequestResponseStream(&srv_ctx, &recv_request, &srv_stream,
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700465 cq_.get(), cq_.get(), tag(2));
Yang Gao0e0d8e12015-02-13 14:40:41 -0800466
Vijay Paidf8b62c2016-05-02 14:34:24 -0700467 Verifier(GetParam().disable_blocking)
468 .Expect(1, true)
469 .Expect(2, true)
470 .Verify(cq_.get());
Yang Gao0e0d8e12015-02-13 14:40:41 -0800471 EXPECT_EQ(send_request.message(), recv_request.message());
472
473 send_response.set_message(recv_request.message());
474 srv_stream.Write(send_response, tag(3));
Yang Gao0e0d8e12015-02-13 14:40:41 -0800475 cli_stream->Read(&recv_response, tag(4));
Craig Tillere4d27482016-05-03 12:19:33 -0700476 Verifier(GetParam().disable_blocking)
477 .Expect(3, true)
478 .Expect(4, true)
479 .Verify(cq_.get());
Yang Gao0e0d8e12015-02-13 14:40:41 -0800480 EXPECT_EQ(send_response.message(), recv_response.message());
481
482 srv_stream.Write(send_response, tag(5));
Yang Gao0e0d8e12015-02-13 14:40:41 -0800483 cli_stream->Read(&recv_response, tag(6));
Craig Tillere4d27482016-05-03 12:19:33 -0700484 Verifier(GetParam().disable_blocking)
485 .Expect(5, true)
486 .Expect(6, true)
487 .Verify(cq_.get());
Yang Gao0e0d8e12015-02-13 14:40:41 -0800488 EXPECT_EQ(send_response.message(), recv_response.message());
489
490 srv_stream.Finish(Status::OK, tag(7));
Yang Gao0e0d8e12015-02-13 14:40:41 -0800491 cli_stream->Read(&recv_response, tag(8));
Craig Tillere4d27482016-05-03 12:19:33 -0700492 Verifier(GetParam().disable_blocking)
493 .Expect(7, true)
494 .Expect(8, false)
495 .Verify(cq_.get());
Yang Gao0e0d8e12015-02-13 14:40:41 -0800496
497 cli_stream->Finish(&recv_status, tag(9));
Vijay Paidf8b62c2016-05-02 14:34:24 -0700498 Verifier(GetParam().disable_blocking).Expect(9, true).Verify(cq_.get());
Yang Gao0e0d8e12015-02-13 14:40:41 -0800499
Yang Gaoc1a2c312015-06-16 10:59:46 -0700500 EXPECT_TRUE(recv_status.ok());
Yang Gao0e0d8e12015-02-13 14:40:41 -0800501}
502
503// One ping, one pong.
Craig Tiller69f90e62015-08-06 08:32:35 -0700504TEST_P(AsyncEnd2endTest, SimpleBidiStreaming) {
Yang Gaoc05b6cb2015-02-13 00:34:10 -0800505 ResetStub();
506
507 EchoRequest send_request;
508 EchoRequest recv_request;
509 EchoResponse send_response;
510 EchoResponse recv_response;
511 Status recv_status;
512 ClientContext cli_ctx;
513 ServerContext srv_ctx;
514 ServerAsyncReaderWriter<EchoResponse, EchoRequest> srv_stream(&srv_ctx);
515
Vijay Paid7b1e702016-05-02 15:10:21 -0700516 send_request.set_message(GetParam().message_content);
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800517 std::unique_ptr<ClientAsyncReaderWriter<EchoRequest, EchoResponse>>
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700518 cli_stream(stub_->AsyncBidiStream(&cli_ctx, cq_.get(), tag(1)));
Yang Gaoc05b6cb2015-02-13 00:34:10 -0800519
Craig Tillerd6c98df2015-08-18 09:33:44 -0700520 service_.RequestBidiStream(&srv_ctx, &srv_stream, cq_.get(), cq_.get(),
521 tag(2));
Yang Gaoc05b6cb2015-02-13 00:34:10 -0800522
Vijay Paidf8b62c2016-05-02 14:34:24 -0700523 Verifier(GetParam().disable_blocking)
524 .Expect(1, true)
525 .Expect(2, true)
526 .Verify(cq_.get());
Yang Gaoc05b6cb2015-02-13 00:34:10 -0800527
528 cli_stream->Write(send_request, tag(3));
Yang Gaoc05b6cb2015-02-13 00:34:10 -0800529 srv_stream.Read(&recv_request, tag(4));
Craig Tillere4d27482016-05-03 12:19:33 -0700530 Verifier(GetParam().disable_blocking)
531 .Expect(3, true)
532 .Expect(4, true)
533 .Verify(cq_.get());
Yang Gaoc05b6cb2015-02-13 00:34:10 -0800534 EXPECT_EQ(send_request.message(), recv_request.message());
535
536 send_response.set_message(recv_request.message());
537 srv_stream.Write(send_response, tag(5));
Yang Gaoc05b6cb2015-02-13 00:34:10 -0800538 cli_stream->Read(&recv_response, tag(6));
Craig Tillere4d27482016-05-03 12:19:33 -0700539 Verifier(GetParam().disable_blocking)
540 .Expect(5, true)
541 .Expect(6, true)
542 .Verify(cq_.get());
Yang Gaoc05b6cb2015-02-13 00:34:10 -0800543 EXPECT_EQ(send_response.message(), recv_response.message());
544
545 cli_stream->WritesDone(tag(7));
Yang Gaoc05b6cb2015-02-13 00:34:10 -0800546 srv_stream.Read(&recv_request, tag(8));
Craig Tillere4d27482016-05-03 12:19:33 -0700547 Verifier(GetParam().disable_blocking)
548 .Expect(7, true)
549 .Expect(8, false)
550 .Verify(cq_.get());
Yang Gaoc05b6cb2015-02-13 00:34:10 -0800551
552 srv_stream.Finish(Status::OK, tag(9));
Yang Gaoc05b6cb2015-02-13 00:34:10 -0800553 cli_stream->Finish(&recv_status, tag(10));
Craig Tillere4d27482016-05-03 12:19:33 -0700554 Verifier(GetParam().disable_blocking)
555 .Expect(9, true)
556 .Expect(10, true)
557 .Verify(cq_.get());
Yang Gaoc05b6cb2015-02-13 00:34:10 -0800558
Yang Gaoc1a2c312015-06-16 10:59:46 -0700559 EXPECT_TRUE(recv_status.ok());
Yang Gaoc05b6cb2015-02-13 00:34:10 -0800560}
561
Yang Gao406b32f2015-02-13 16:25:33 -0800562// Metadata tests
Craig Tiller69f90e62015-08-06 08:32:35 -0700563TEST_P(AsyncEnd2endTest, ClientInitialMetadataRpc) {
Yang Gao406b32f2015-02-13 16:25:33 -0800564 ResetStub();
565
566 EchoRequest send_request;
567 EchoRequest recv_request;
568 EchoResponse send_response;
569 EchoResponse recv_response;
570 Status recv_status;
571
572 ClientContext cli_ctx;
573 ServerContext srv_ctx;
574 grpc::ServerAsyncResponseWriter<EchoResponse> response_writer(&srv_ctx);
575
Vijay Paid7b1e702016-05-02 15:10:21 -0700576 send_request.set_message(GetParam().message_content);
Yang Gao406b32f2015-02-13 16:25:33 -0800577 std::pair<grpc::string, grpc::string> meta1("key1", "val1");
578 std::pair<grpc::string, grpc::string> meta2("key2", "val2");
Craig Tiller6f871642016-02-03 16:15:31 -0800579 std::pair<grpc::string, grpc::string> meta3("g.r.d-bin", "xyz");
Yang Gao406b32f2015-02-13 16:25:33 -0800580 cli_ctx.AddMetadata(meta1.first, meta1.second);
581 cli_ctx.AddMetadata(meta2.first, meta2.second);
Craig Tiller6f871642016-02-03 16:15:31 -0800582 cli_ctx.AddMetadata(meta3.first, meta3.second);
Yang Gao406b32f2015-02-13 16:25:33 -0800583
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800584 std::unique_ptr<ClientAsyncResponseReader<EchoResponse>> response_reader(
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700585 stub_->AsyncEcho(&cli_ctx, send_request, cq_.get()));
Yang Gao406b32f2015-02-13 16:25:33 -0800586
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700587 service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, cq_.get(),
588 cq_.get(), tag(2));
Vijay Paidf8b62c2016-05-02 14:34:24 -0700589 Verifier(GetParam().disable_blocking).Expect(2, true).Verify(cq_.get());
Yang Gao406b32f2015-02-13 16:25:33 -0800590 EXPECT_EQ(send_request.message(), recv_request.message());
591 auto client_initial_metadata = srv_ctx.client_metadata();
yang-ge21908f2015-08-25 13:47:51 -0700592 EXPECT_EQ(meta1.second,
593 ToString(client_initial_metadata.find(meta1.first)->second));
594 EXPECT_EQ(meta2.second,
595 ToString(client_initial_metadata.find(meta2.first)->second));
Craig Tiller6f871642016-02-03 16:15:31 -0800596 EXPECT_EQ(meta3.second,
597 ToString(client_initial_metadata.find(meta3.first)->second));
Craig Tiller8bf2dca2015-07-10 13:08:41 -0700598 EXPECT_GE(client_initial_metadata.size(), static_cast<size_t>(2));
Yang Gao406b32f2015-02-13 16:25:33 -0800599
600 send_response.set_message(recv_request.message());
601 response_writer.Finish(send_response, Status::OK, tag(3));
Yang Gao3a5e5492015-02-18 14:32:38 -0800602 response_reader->Finish(&recv_response, &recv_status, tag(4));
Craig Tillere4d27482016-05-03 12:19:33 -0700603 Verifier(GetParam().disable_blocking)
604 .Expect(3, true)
605 .Expect(4, true)
606 .Verify(cq_.get());
Yang Gao406b32f2015-02-13 16:25:33 -0800607
608 EXPECT_EQ(send_response.message(), recv_response.message());
Yang Gaoc1a2c312015-06-16 10:59:46 -0700609 EXPECT_TRUE(recv_status.ok());
Yang Gao406b32f2015-02-13 16:25:33 -0800610}
611
Craig Tiller69f90e62015-08-06 08:32:35 -0700612TEST_P(AsyncEnd2endTest, ServerInitialMetadataRpc) {
Yang Gao2b7f5372015-02-18 00:45:53 -0800613 ResetStub();
614
615 EchoRequest send_request;
616 EchoRequest recv_request;
617 EchoResponse send_response;
618 EchoResponse recv_response;
619 Status recv_status;
620
621 ClientContext cli_ctx;
622 ServerContext srv_ctx;
623 grpc::ServerAsyncResponseWriter<EchoResponse> response_writer(&srv_ctx);
624
Vijay Paid7b1e702016-05-02 15:10:21 -0700625 send_request.set_message(GetParam().message_content);
Yang Gao2b7f5372015-02-18 00:45:53 -0800626 std::pair<grpc::string, grpc::string> meta1("key1", "val1");
627 std::pair<grpc::string, grpc::string> meta2("key2", "val2");
628
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800629 std::unique_ptr<ClientAsyncResponseReader<EchoResponse>> response_reader(
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700630 stub_->AsyncEcho(&cli_ctx, send_request, cq_.get()));
Yang Gao2b7f5372015-02-18 00:45:53 -0800631
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700632 service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, cq_.get(),
633 cq_.get(), tag(2));
Vijay Paidf8b62c2016-05-02 14:34:24 -0700634 Verifier(GetParam().disable_blocking).Expect(2, true).Verify(cq_.get());
Yang Gao2b7f5372015-02-18 00:45:53 -0800635 EXPECT_EQ(send_request.message(), recv_request.message());
636 srv_ctx.AddInitialMetadata(meta1.first, meta1.second);
637 srv_ctx.AddInitialMetadata(meta2.first, meta2.second);
638 response_writer.SendInitialMetadata(tag(3));
Vijay Paidf8b62c2016-05-02 14:34:24 -0700639 Verifier(GetParam().disable_blocking).Expect(3, true).Verify(cq_.get());
Yang Gao2b7f5372015-02-18 00:45:53 -0800640
Yang Gao3a5e5492015-02-18 14:32:38 -0800641 response_reader->ReadInitialMetadata(tag(4));
Vijay Paidf8b62c2016-05-02 14:34:24 -0700642 Verifier(GetParam().disable_blocking).Expect(4, true).Verify(cq_.get());
Yang Gao2b7f5372015-02-18 00:45:53 -0800643 auto server_initial_metadata = cli_ctx.GetServerInitialMetadata();
yang-ge21908f2015-08-25 13:47:51 -0700644 EXPECT_EQ(meta1.second,
645 ToString(server_initial_metadata.find(meta1.first)->second));
646 EXPECT_EQ(meta2.second,
647 ToString(server_initial_metadata.find(meta2.first)->second));
vjpaid5577aa2015-02-18 22:26:48 -0800648 EXPECT_EQ(static_cast<size_t>(2), server_initial_metadata.size());
Yang Gao3a5e5492015-02-18 14:32:38 -0800649
650 send_response.set_message(recv_request.message());
651 response_writer.Finish(send_response, Status::OK, tag(5));
Yang Gao3a5e5492015-02-18 14:32:38 -0800652 response_reader->Finish(&recv_response, &recv_status, tag(6));
Craig Tillere4d27482016-05-03 12:19:33 -0700653 Verifier(GetParam().disable_blocking)
654 .Expect(5, true)
655 .Expect(6, true)
656 .Verify(cq_.get());
Yang Gao3a5e5492015-02-18 14:32:38 -0800657
658 EXPECT_EQ(send_response.message(), recv_response.message());
Yang Gaoc1a2c312015-06-16 10:59:46 -0700659 EXPECT_TRUE(recv_status.ok());
Yang Gao2b7f5372015-02-18 00:45:53 -0800660}
661
Craig Tiller69f90e62015-08-06 08:32:35 -0700662TEST_P(AsyncEnd2endTest, ServerTrailingMetadataRpc) {
Yang Gao2b7f5372015-02-18 00:45:53 -0800663 ResetStub();
664
665 EchoRequest send_request;
666 EchoRequest recv_request;
667 EchoResponse send_response;
668 EchoResponse recv_response;
669 Status recv_status;
670
671 ClientContext cli_ctx;
672 ServerContext srv_ctx;
673 grpc::ServerAsyncResponseWriter<EchoResponse> response_writer(&srv_ctx);
674
Vijay Paid7b1e702016-05-02 15:10:21 -0700675 send_request.set_message(GetParam().message_content);
Yang Gao2b7f5372015-02-18 00:45:53 -0800676 std::pair<grpc::string, grpc::string> meta1("key1", "val1");
677 std::pair<grpc::string, grpc::string> meta2("key2", "val2");
678
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800679 std::unique_ptr<ClientAsyncResponseReader<EchoResponse>> response_reader(
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700680 stub_->AsyncEcho(&cli_ctx, send_request, cq_.get()));
Yang Gao2b7f5372015-02-18 00:45:53 -0800681
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700682 service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, cq_.get(),
683 cq_.get(), tag(2));
Vijay Paidf8b62c2016-05-02 14:34:24 -0700684 Verifier(GetParam().disable_blocking).Expect(2, true).Verify(cq_.get());
Yang Gao2b7f5372015-02-18 00:45:53 -0800685 EXPECT_EQ(send_request.message(), recv_request.message());
686 response_writer.SendInitialMetadata(tag(3));
Vijay Paidf8b62c2016-05-02 14:34:24 -0700687 Verifier(GetParam().disable_blocking).Expect(3, true).Verify(cq_.get());
Yang Gao2b7f5372015-02-18 00:45:53 -0800688
689 send_response.set_message(recv_request.message());
690 srv_ctx.AddTrailingMetadata(meta1.first, meta1.second);
691 srv_ctx.AddTrailingMetadata(meta2.first, meta2.second);
692 response_writer.Finish(send_response, Status::OK, tag(4));
Yang Gao3a5e5492015-02-18 14:32:38 -0800693 response_reader->Finish(&recv_response, &recv_status, tag(5));
Craig Tillere4d27482016-05-03 12:19:33 -0700694
695 Verifier(GetParam().disable_blocking)
696 .Expect(4, true)
697 .Expect(5, true)
698 .Verify(cq_.get());
699
Yang Gao2b7f5372015-02-18 00:45:53 -0800700 EXPECT_EQ(send_response.message(), recv_response.message());
Yang Gaoc1a2c312015-06-16 10:59:46 -0700701 EXPECT_TRUE(recv_status.ok());
Yang Gao2b7f5372015-02-18 00:45:53 -0800702 auto server_trailing_metadata = cli_ctx.GetServerTrailingMetadata();
yang-ge21908f2015-08-25 13:47:51 -0700703 EXPECT_EQ(meta1.second,
704 ToString(server_trailing_metadata.find(meta1.first)->second));
705 EXPECT_EQ(meta2.second,
706 ToString(server_trailing_metadata.find(meta2.first)->second));
vjpaid5577aa2015-02-18 22:26:48 -0800707 EXPECT_EQ(static_cast<size_t>(2), server_trailing_metadata.size());
Yang Gao2b7f5372015-02-18 00:45:53 -0800708}
709
Craig Tiller69f90e62015-08-06 08:32:35 -0700710TEST_P(AsyncEnd2endTest, MetadataRpc) {
Yang Gao2b7f5372015-02-18 00:45:53 -0800711 ResetStub();
712
713 EchoRequest send_request;
714 EchoRequest recv_request;
715 EchoResponse send_response;
716 EchoResponse recv_response;
717 Status recv_status;
718
719 ClientContext cli_ctx;
720 ServerContext srv_ctx;
721 grpc::ServerAsyncResponseWriter<EchoResponse> response_writer(&srv_ctx);
722
Vijay Paid7b1e702016-05-02 15:10:21 -0700723 send_request.set_message(GetParam().message_content);
Yang Gao2b7f5372015-02-18 00:45:53 -0800724 std::pair<grpc::string, grpc::string> meta1("key1", "val1");
Yang Gao3a5e5492015-02-18 14:32:38 -0800725 std::pair<grpc::string, grpc::string> meta2(
Vijay Pai92a928f2015-03-26 16:30:22 -0400726 "key2-bin",
Craig Tillerd6c98df2015-08-18 09:33:44 -0700727 grpc::string("\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc", 13));
Yang Gao2b7f5372015-02-18 00:45:53 -0800728 std::pair<grpc::string, grpc::string> meta3("key3", "val3");
Craig Tiller47c83fd2015-02-21 22:45:35 -0800729 std::pair<grpc::string, grpc::string> meta6(
730 "key4-bin",
Vijay Pai92a928f2015-03-26 16:30:22 -0400731 grpc::string("\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d",
Craig Tillerd6c98df2015-08-18 09:33:44 -0700732 14));
Yang Gao2b7f5372015-02-18 00:45:53 -0800733 std::pair<grpc::string, grpc::string> meta5("key5", "val5");
Craig Tiller47c83fd2015-02-21 22:45:35 -0800734 std::pair<grpc::string, grpc::string> meta4(
735 "key6-bin",
Craig Tillerd6c98df2015-08-18 09:33:44 -0700736 grpc::string(
737 "\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee", 15));
Yang Gao2b7f5372015-02-18 00:45:53 -0800738
739 cli_ctx.AddMetadata(meta1.first, meta1.second);
740 cli_ctx.AddMetadata(meta2.first, meta2.second);
741
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800742 std::unique_ptr<ClientAsyncResponseReader<EchoResponse>> response_reader(
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700743 stub_->AsyncEcho(&cli_ctx, send_request, cq_.get()));
Yang Gao2b7f5372015-02-18 00:45:53 -0800744
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700745 service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, cq_.get(),
746 cq_.get(), tag(2));
Vijay Paidf8b62c2016-05-02 14:34:24 -0700747 Verifier(GetParam().disable_blocking).Expect(2, true).Verify(cq_.get());
Yang Gao2b7f5372015-02-18 00:45:53 -0800748 EXPECT_EQ(send_request.message(), recv_request.message());
749 auto client_initial_metadata = srv_ctx.client_metadata();
yang-ge21908f2015-08-25 13:47:51 -0700750 EXPECT_EQ(meta1.second,
751 ToString(client_initial_metadata.find(meta1.first)->second));
752 EXPECT_EQ(meta2.second,
753 ToString(client_initial_metadata.find(meta2.first)->second));
Craig Tiller8bf2dca2015-07-10 13:08:41 -0700754 EXPECT_GE(client_initial_metadata.size(), static_cast<size_t>(2));
Yang Gao2b7f5372015-02-18 00:45:53 -0800755
756 srv_ctx.AddInitialMetadata(meta3.first, meta3.second);
757 srv_ctx.AddInitialMetadata(meta4.first, meta4.second);
758 response_writer.SendInitialMetadata(tag(3));
Vijay Paidf8b62c2016-05-02 14:34:24 -0700759 Verifier(GetParam().disable_blocking).Expect(3, true).Verify(cq_.get());
Yang Gao3a5e5492015-02-18 14:32:38 -0800760 response_reader->ReadInitialMetadata(tag(4));
Vijay Paidf8b62c2016-05-02 14:34:24 -0700761 Verifier(GetParam().disable_blocking).Expect(4, true).Verify(cq_.get());
Yang Gao2b7f5372015-02-18 00:45:53 -0800762 auto server_initial_metadata = cli_ctx.GetServerInitialMetadata();
yang-ge21908f2015-08-25 13:47:51 -0700763 EXPECT_EQ(meta3.second,
764 ToString(server_initial_metadata.find(meta3.first)->second));
765 EXPECT_EQ(meta4.second,
766 ToString(server_initial_metadata.find(meta4.first)->second));
Craig Tiller8bf2dca2015-07-10 13:08:41 -0700767 EXPECT_GE(server_initial_metadata.size(), static_cast<size_t>(2));
Yang Gao3a5e5492015-02-18 14:32:38 -0800768
769 send_response.set_message(recv_request.message());
770 srv_ctx.AddTrailingMetadata(meta5.first, meta5.second);
771 srv_ctx.AddTrailingMetadata(meta6.first, meta6.second);
772 response_writer.Finish(send_response, Status::OK, tag(5));
Yang Gao3a5e5492015-02-18 14:32:38 -0800773 response_reader->Finish(&recv_response, &recv_status, tag(6));
Craig Tillere4d27482016-05-03 12:19:33 -0700774
775 Verifier(GetParam().disable_blocking)
776 .Expect(5, true)
777 .Expect(6, true)
778 .Verify(cq_.get());
779
Yang Gao3a5e5492015-02-18 14:32:38 -0800780 EXPECT_EQ(send_response.message(), recv_response.message());
Yang Gaoc1a2c312015-06-16 10:59:46 -0700781 EXPECT_TRUE(recv_status.ok());
Yang Gao2b7f5372015-02-18 00:45:53 -0800782 auto server_trailing_metadata = cli_ctx.GetServerTrailingMetadata();
yang-ge21908f2015-08-25 13:47:51 -0700783 EXPECT_EQ(meta5.second,
784 ToString(server_trailing_metadata.find(meta5.first)->second));
785 EXPECT_EQ(meta6.second,
786 ToString(server_trailing_metadata.find(meta6.first)->second));
Craig Tiller8bf2dca2015-07-10 13:08:41 -0700787 EXPECT_GE(server_trailing_metadata.size(), static_cast<size_t>(2));
Yang Gao2b7f5372015-02-18 00:45:53 -0800788}
yang-gb3352562015-08-04 14:42:06 -0700789
790// Server uses AsyncNotifyWhenDone API to check for cancellation
Craig Tiller69f90e62015-08-06 08:32:35 -0700791TEST_P(AsyncEnd2endTest, ServerCheckCancellation) {
yang-gb3352562015-08-04 14:42:06 -0700792 ResetStub();
793
794 EchoRequest send_request;
795 EchoRequest recv_request;
796 EchoResponse send_response;
797 EchoResponse recv_response;
798 Status recv_status;
799
800 ClientContext cli_ctx;
801 ServerContext srv_ctx;
802 grpc::ServerAsyncResponseWriter<EchoResponse> response_writer(&srv_ctx);
803
Vijay Paid7b1e702016-05-02 15:10:21 -0700804 send_request.set_message(GetParam().message_content);
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800805 std::unique_ptr<ClientAsyncResponseReader<EchoResponse>> response_reader(
yang-gb3352562015-08-04 14:42:06 -0700806 stub_->AsyncEcho(&cli_ctx, send_request, cq_.get()));
807
808 srv_ctx.AsyncNotifyWhenDone(tag(5));
809 service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, cq_.get(),
810 cq_.get(), tag(2));
811
Vijay Paidf8b62c2016-05-02 14:34:24 -0700812 Verifier(GetParam().disable_blocking).Expect(2, true).Verify(cq_.get());
yang-gb3352562015-08-04 14:42:06 -0700813 EXPECT_EQ(send_request.message(), recv_request.message());
814
815 cli_ctx.TryCancel();
Vijay Paidf8b62c2016-05-02 14:34:24 -0700816 Verifier(GetParam().disable_blocking).Expect(5, true).Verify(cq_.get());
yang-gb3352562015-08-04 14:42:06 -0700817 EXPECT_TRUE(srv_ctx.IsCancelled());
818
819 response_reader->Finish(&recv_response, &recv_status, tag(4));
Vijay Paidf8b62c2016-05-02 14:34:24 -0700820 Verifier(GetParam().disable_blocking).Expect(4, false).Verify(cq_.get());
yang-gb3352562015-08-04 14:42:06 -0700821
822 EXPECT_EQ(StatusCode::CANCELLED, recv_status.error_code());
823}
824
825// Server uses AsyncNotifyWhenDone API to check for normal finish
Craig Tiller69f90e62015-08-06 08:32:35 -0700826TEST_P(AsyncEnd2endTest, ServerCheckDone) {
yang-gb3352562015-08-04 14:42:06 -0700827 ResetStub();
828
829 EchoRequest send_request;
830 EchoRequest recv_request;
831 EchoResponse send_response;
832 EchoResponse recv_response;
833 Status recv_status;
834
835 ClientContext cli_ctx;
836 ServerContext srv_ctx;
837 grpc::ServerAsyncResponseWriter<EchoResponse> response_writer(&srv_ctx);
838
Vijay Paid7b1e702016-05-02 15:10:21 -0700839 send_request.set_message(GetParam().message_content);
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800840 std::unique_ptr<ClientAsyncResponseReader<EchoResponse>> response_reader(
yang-gb3352562015-08-04 14:42:06 -0700841 stub_->AsyncEcho(&cli_ctx, send_request, cq_.get()));
842
843 srv_ctx.AsyncNotifyWhenDone(tag(5));
844 service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, cq_.get(),
845 cq_.get(), tag(2));
846
Vijay Paidf8b62c2016-05-02 14:34:24 -0700847 Verifier(GetParam().disable_blocking).Expect(2, true).Verify(cq_.get());
yang-gb3352562015-08-04 14:42:06 -0700848 EXPECT_EQ(send_request.message(), recv_request.message());
849
850 send_response.set_message(recv_request.message());
851 response_writer.Finish(send_response, Status::OK, tag(3));
yang-gb3352562015-08-04 14:42:06 -0700852 response_reader->Finish(&recv_response, &recv_status, tag(4));
Craig Tillere4d27482016-05-03 12:19:33 -0700853 Verifier(GetParam().disable_blocking)
854 .Expect(3, true)
855 .Expect(4, true)
856 .Expect(5, true)
857 .Verify(cq_.get());
858 EXPECT_FALSE(srv_ctx.IsCancelled());
yang-gb3352562015-08-04 14:42:06 -0700859
860 EXPECT_EQ(send_response.message(), recv_response.message());
861 EXPECT_TRUE(recv_status.ok());
862}
863
Craig Tiller8f7bff72015-08-17 13:23:14 -0700864TEST_P(AsyncEnd2endTest, UnimplementedRpc) {
Vijay Paidf8b62c2016-05-02 14:34:24 -0700865 ChannelArguments args;
866 auto channel_creds =
867 GetChannelCredentials(GetParam().credentials_type, &args);
yang-g730055d2015-08-27 12:29:45 -0700868 std::shared_ptr<Channel> channel =
Vijay Paidf8b62c2016-05-02 14:34:24 -0700869 CreateCustomChannel(server_address_.str(), channel_creds, args);
Craig Tiller1b4e3302015-12-17 16:35:00 -0800870 std::unique_ptr<grpc::testing::UnimplementedService::Stub> stub;
871 stub = grpc::testing::UnimplementedService::NewStub(channel);
yang-g9b7757d2015-08-13 11:15:53 -0700872 EchoRequest send_request;
873 EchoResponse recv_response;
874 Status recv_status;
875
876 ClientContext cli_ctx;
Vijay Paid7b1e702016-05-02 15:10:21 -0700877 send_request.set_message(GetParam().message_content);
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800878 std::unique_ptr<ClientAsyncResponseReader<EchoResponse>> response_reader(
yang-g9b7757d2015-08-13 11:15:53 -0700879 stub->AsyncUnimplemented(&cli_ctx, send_request, cq_.get()));
880
881 response_reader->Finish(&recv_response, &recv_status, tag(4));
Vijay Paidf8b62c2016-05-02 14:34:24 -0700882 Verifier(GetParam().disable_blocking).Expect(4, false).Verify(cq_.get());
yang-g9b7757d2015-08-13 11:15:53 -0700883
884 EXPECT_EQ(StatusCode::UNIMPLEMENTED, recv_status.error_code());
885 EXPECT_EQ("", recv_status.error_message());
886}
887
Sree Kuchibhotla0f242ac2016-01-29 18:12:19 -0800888// This class is for testing scenarios where RPCs are cancelled on the server
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -0800889// by calling ServerContext::TryCancel(). Server uses AsyncNotifyWhenDone
890// API to check for cancellation
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800891class AsyncEnd2endServerTryCancelTest : public AsyncEnd2endTest {
892 protected:
893 typedef enum {
894 DO_NOT_CANCEL = 0,
895 CANCEL_BEFORE_PROCESSING,
896 CANCEL_DURING_PROCESSING,
897 CANCEL_AFTER_PROCESSING
898 } ServerTryCancelRequestPhase;
899
Sree Kuchibhotla0f242ac2016-01-29 18:12:19 -0800900 // Helper for testing client-streaming RPCs which are cancelled on the server.
901 // Depending on the value of server_try_cancel parameter, this will test one
902 // of the following three scenarios:
903 // CANCEL_BEFORE_PROCESSING: Rpc is cancelled by the server before reading
904 // any messages from the client
905 //
906 // CANCEL_DURING_PROCESSING: Rpc is cancelled by the server while reading
907 // messages from the client
908 //
909 // CANCEL_AFTER PROCESSING: Rpc is cancelled by server after reading all
910 // messages from the client (but before sending any status back to the
911 // client)
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800912 void TestClientStreamingServerCancel(
913 ServerTryCancelRequestPhase server_try_cancel) {
914 ResetStub();
915
916 EchoRequest send_request;
917 EchoRequest recv_request;
918 EchoResponse send_response;
919 EchoResponse recv_response;
920 Status recv_status;
921
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800922 ClientContext cli_ctx;
923 ServerContext srv_ctx;
924 ServerAsyncReader<EchoResponse, EchoRequest> srv_stream(&srv_ctx);
925
926 // Initiate the 'RequestStream' call on client
927 std::unique_ptr<ClientAsyncWriter<EchoRequest>> cli_stream(
Sree Kuchibhotla4fb59082016-01-29 11:16:24 -0800928 stub_->AsyncRequestStream(&cli_ctx, &recv_response, cq_.get(), tag(1)));
Vijay Paidf8b62c2016-05-02 14:34:24 -0700929 Verifier(GetParam().disable_blocking).Expect(1, true).Verify(cq_.get());
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800930
931 // On the server, request to be notified of 'RequestStream' calls
932 // and receive the 'RequestStream' call just made by the client
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -0800933 srv_ctx.AsyncNotifyWhenDone(tag(11));
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800934 service_.RequestRequestStream(&srv_ctx, &srv_stream, cq_.get(), cq_.get(),
935 tag(2));
Vijay Paidf8b62c2016-05-02 14:34:24 -0700936 Verifier(GetParam().disable_blocking).Expect(2, true).Verify(cq_.get());
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800937
938 // Client sends 3 messages (tags 3, 4 and 5)
939 for (int tag_idx = 3; tag_idx <= 5; tag_idx++) {
940 send_request.set_message("Ping " + std::to_string(tag_idx));
941 cli_stream->Write(send_request, tag(tag_idx));
Vijay Paidf8b62c2016-05-02 14:34:24 -0700942 Verifier(GetParam().disable_blocking)
943 .Expect(tag_idx, true)
944 .Verify(cq_.get());
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800945 }
946 cli_stream->WritesDone(tag(6));
Vijay Paidf8b62c2016-05-02 14:34:24 -0700947 Verifier(GetParam().disable_blocking).Expect(6, true).Verify(cq_.get());
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800948
949 bool expected_server_cq_result = true;
950 bool ignore_cq_result = false;
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -0800951 bool want_done_tag = false;
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800952
953 if (server_try_cancel == CANCEL_BEFORE_PROCESSING) {
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -0800954 srv_ctx.TryCancel();
Vijay Paidf8b62c2016-05-02 14:34:24 -0700955 Verifier(GetParam().disable_blocking).Expect(11, true).Verify(cq_.get());
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -0800956 EXPECT_TRUE(srv_ctx.IsCancelled());
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800957
958 // Since cancellation is done before server reads any results, we know
959 // for sure that all cq results will return false from this point forward
960 expected_server_cq_result = false;
961 }
962
963 std::thread* server_try_cancel_thd = NULL;
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -0800964
Vijay Paidf8b62c2016-05-02 14:34:24 -0700965 auto verif = Verifier(GetParam().disable_blocking);
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -0800966
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800967 if (server_try_cancel == CANCEL_DURING_PROCESSING) {
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -0800968 server_try_cancel_thd =
969 new std::thread(&ServerContext::TryCancel, &srv_ctx);
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800970 // Server will cancel the RPC in a parallel thread while reading the
971 // requests from the client. Since the cancellation can happen at anytime,
972 // some of the cq results (i.e those until cancellation) might be true but
973 // its non deterministic. So better to ignore the cq results
974 ignore_cq_result = true;
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -0800975 // Expect that we might possibly see the done tag that
976 // indicates cancellation completion in this case
977 want_done_tag = true;
978 verif.Expect(11, true);
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800979 }
980
981 // Server reads 3 messages (tags 6, 7 and 8)
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -0800982 // But if want_done_tag is true, we might also see tag 11
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800983 for (int tag_idx = 6; tag_idx <= 8; tag_idx++) {
984 srv_stream.Read(&recv_request, tag(tag_idx));
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -0800985 // Note that we'll add something to the verifier and verify that
986 // something was seen, but it might be tag 11 and not what we
987 // just added
988 int got_tag = verif.Expect(tag_idx, expected_server_cq_result)
989 .Next(cq_.get(), ignore_cq_result);
990 GPR_ASSERT((got_tag == tag_idx) || (got_tag == 11 && want_done_tag));
991 if (got_tag == 11) {
992 EXPECT_TRUE(srv_ctx.IsCancelled());
993 want_done_tag = false;
994 // Now get the other entry that we were waiting on
995 EXPECT_EQ(verif.Next(cq_.get(), ignore_cq_result), tag_idx);
996 }
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800997 }
998
999 if (server_try_cancel_thd != NULL) {
1000 server_try_cancel_thd->join();
1001 delete server_try_cancel_thd;
1002 }
1003
1004 if (server_try_cancel == CANCEL_AFTER_PROCESSING) {
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001005 srv_ctx.TryCancel();
1006 want_done_tag = true;
1007 verif.Expect(11, true);
1008 }
1009
1010 if (want_done_tag) {
1011 verif.Verify(cq_.get());
1012 EXPECT_TRUE(srv_ctx.IsCancelled());
1013 want_done_tag = false;
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001014 }
1015
Sree Kuchibhotla0f242ac2016-01-29 18:12:19 -08001016 // The RPC has been cancelled at this point for sure (i.e irrespective of
1017 // the value of `server_try_cancel` is). So, from this point forward, we
1018 // know that cq results are supposed to return false on server.
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001019
Sree Kuchibhotla0f242ac2016-01-29 18:12:19 -08001020 // Server sends the final message and cancelled status (but the RPC is
1021 // already cancelled at this point. So we expect the operation to fail)
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001022 srv_stream.Finish(send_response, Status::CANCELLED, tag(9));
Vijay Paidf8b62c2016-05-02 14:34:24 -07001023 Verifier(GetParam().disable_blocking).Expect(9, false).Verify(cq_.get());
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001024
Sree Kuchibhotla0f242ac2016-01-29 18:12:19 -08001025 // Client will see the cancellation
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001026 cli_stream->Finish(&recv_status, tag(10));
Sree Kuchibhotla369a04a2016-02-01 10:53:13 -08001027 // TODO(sreek): The expectation here should be true. This is a bug (github
Sree Kuchibhotla0f242ac2016-01-29 18:12:19 -08001028 // issue #4972)
Vijay Paidf8b62c2016-05-02 14:34:24 -07001029 Verifier(GetParam().disable_blocking).Expect(10, false).Verify(cq_.get());
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001030 EXPECT_FALSE(recv_status.ok());
1031 EXPECT_EQ(::grpc::StatusCode::CANCELLED, recv_status.error_code());
1032 }
1033
Sree Kuchibhotla0f242ac2016-01-29 18:12:19 -08001034 // Helper for testing server-streaming RPCs which are cancelled on the server.
1035 // Depending on the value of server_try_cancel parameter, this will test one
1036 // of the following three scenarios:
1037 // CANCEL_BEFORE_PROCESSING: Rpc is cancelled by the server before sending
1038 // any messages to the client
1039 //
1040 // CANCEL_DURING_PROCESSING: Rpc is cancelled by the server while sending
1041 // messages to the client
1042 //
1043 // CANCEL_AFTER PROCESSING: Rpc is cancelled by server after sending all
1044 // messages to the client (but before sending any status back to the
1045 // client)
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001046 void TestServerStreamingServerCancel(
1047 ServerTryCancelRequestPhase server_try_cancel) {
1048 ResetStub();
1049
1050 EchoRequest send_request;
1051 EchoRequest recv_request;
1052 EchoResponse send_response;
1053 EchoResponse recv_response;
1054 Status recv_status;
1055 ClientContext cli_ctx;
1056 ServerContext srv_ctx;
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001057 ServerAsyncWriter<EchoResponse> srv_stream(&srv_ctx);
1058
1059 send_request.set_message("Ping");
1060 // Initiate the 'ResponseStream' call on the client
1061 std::unique_ptr<ClientAsyncReader<EchoResponse>> cli_stream(
Sree Kuchibhotla4fb59082016-01-29 11:16:24 -08001062 stub_->AsyncResponseStream(&cli_ctx, send_request, cq_.get(), tag(1)));
Vijay Paidf8b62c2016-05-02 14:34:24 -07001063 Verifier(GetParam().disable_blocking).Expect(1, true).Verify(cq_.get());
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001064 // On the server, request to be notified of 'ResponseStream' calls and
1065 // receive the call just made by the client
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001066 srv_ctx.AsyncNotifyWhenDone(tag(11));
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001067 service_.RequestResponseStream(&srv_ctx, &recv_request, &srv_stream,
1068 cq_.get(), cq_.get(), tag(2));
Vijay Paidf8b62c2016-05-02 14:34:24 -07001069 Verifier(GetParam().disable_blocking).Expect(2, true).Verify(cq_.get());
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001070 EXPECT_EQ(send_request.message(), recv_request.message());
1071
1072 bool expected_cq_result = true;
1073 bool ignore_cq_result = false;
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001074 bool want_done_tag = false;
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001075
1076 if (server_try_cancel == CANCEL_BEFORE_PROCESSING) {
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001077 srv_ctx.TryCancel();
Vijay Paidf8b62c2016-05-02 14:34:24 -07001078 Verifier(GetParam().disable_blocking).Expect(11, true).Verify(cq_.get());
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001079 EXPECT_TRUE(srv_ctx.IsCancelled());
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001080
1081 // We know for sure that all cq results will be false from this point
1082 // since the server cancelled the RPC
1083 expected_cq_result = false;
1084 }
1085
1086 std::thread* server_try_cancel_thd = NULL;
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001087
Vijay Paidf8b62c2016-05-02 14:34:24 -07001088 auto verif = Verifier(GetParam().disable_blocking);
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001089
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001090 if (server_try_cancel == CANCEL_DURING_PROCESSING) {
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001091 server_try_cancel_thd =
1092 new std::thread(&ServerContext::TryCancel, &srv_ctx);
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001093
1094 // Server will cancel the RPC in a parallel thread while writing responses
1095 // to the client. Since the cancellation can happen at anytime, some of
Sree Kuchibhotla0f242ac2016-01-29 18:12:19 -08001096 // the cq results (i.e those until cancellation) might be true but it is
1097 // non deterministic. So better to ignore the cq results
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001098 ignore_cq_result = true;
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001099 // Expect that we might possibly see the done tag that
1100 // indicates cancellation completion in this case
1101 want_done_tag = true;
1102 verif.Expect(11, true);
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001103 }
1104
1105 // Server sends three messages (tags 3, 4 and 5)
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001106 // But if want_done tag is true, we might also see tag 11
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001107 for (int tag_idx = 3; tag_idx <= 5; tag_idx++) {
1108 send_response.set_message("Pong " + std::to_string(tag_idx));
1109 srv_stream.Write(send_response, tag(tag_idx));
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001110 // Note that we'll add something to the verifier and verify that
1111 // something was seen, but it might be tag 11 and not what we
1112 // just added
1113 int got_tag = verif.Expect(tag_idx, expected_cq_result)
1114 .Next(cq_.get(), ignore_cq_result);
1115 GPR_ASSERT((got_tag == tag_idx) || (got_tag == 11 && want_done_tag));
1116 if (got_tag == 11) {
1117 EXPECT_TRUE(srv_ctx.IsCancelled());
1118 want_done_tag = false;
1119 // Now get the other entry that we were waiting on
1120 EXPECT_EQ(verif.Next(cq_.get(), ignore_cq_result), tag_idx);
1121 }
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001122 }
1123
Sree Kuchibhotla0f242ac2016-01-29 18:12:19 -08001124 if (server_try_cancel_thd != NULL) {
1125 server_try_cancel_thd->join();
1126 delete server_try_cancel_thd;
1127 }
1128
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001129 if (server_try_cancel == CANCEL_AFTER_PROCESSING) {
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001130 srv_ctx.TryCancel();
1131 want_done_tag = true;
1132 verif.Expect(11, true);
yang-gad0df7b2016-02-22 10:00:20 -08001133
1134 // Client reads may fail bacause it is notified that the stream is
1135 // cancelled.
1136 ignore_cq_result = true;
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001137 }
1138
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001139 if (want_done_tag) {
1140 verif.Verify(cq_.get());
1141 EXPECT_TRUE(srv_ctx.IsCancelled());
1142 want_done_tag = false;
1143 }
1144
Sree Kuchibhotla0f242ac2016-01-29 18:12:19 -08001145 // Client attemts to read the three messages from the server
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001146 for (int tag_idx = 6; tag_idx <= 8; tag_idx++) {
1147 cli_stream->Read(&recv_response, tag(tag_idx));
Vijay Paidf8b62c2016-05-02 14:34:24 -07001148 Verifier(GetParam().disable_blocking)
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001149 .Expect(tag_idx, expected_cq_result)
Sree Kuchibhotla4fb59082016-01-29 11:16:24 -08001150 .Verify(cq_.get(), ignore_cq_result);
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001151 }
1152
Sree Kuchibhotla0f242ac2016-01-29 18:12:19 -08001153 // The RPC has been cancelled at this point for sure (i.e irrespective of
1154 // the value of `server_try_cancel` is). So, from this point forward, we
1155 // know that cq results are supposed to return false on server.
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001156
Sree Kuchibhotla0f242ac2016-01-29 18:12:19 -08001157 // Server finishes the stream (but the RPC is already cancelled)
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001158 srv_stream.Finish(Status::CANCELLED, tag(9));
Vijay Paidf8b62c2016-05-02 14:34:24 -07001159 Verifier(GetParam().disable_blocking).Expect(9, false).Verify(cq_.get());
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001160
Sree Kuchibhotla0f242ac2016-01-29 18:12:19 -08001161 // Client will see the cancellation
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001162 cli_stream->Finish(&recv_status, tag(10));
Vijay Paidf8b62c2016-05-02 14:34:24 -07001163 Verifier(GetParam().disable_blocking).Expect(10, true).Verify(cq_.get());
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001164 EXPECT_FALSE(recv_status.ok());
1165 EXPECT_EQ(::grpc::StatusCode::CANCELLED, recv_status.error_code());
1166 }
1167
Sree Kuchibhotla0f242ac2016-01-29 18:12:19 -08001168 // Helper for testing bidirectinal-streaming RPCs which are cancelled on the
1169 // server.
1170 //
1171 // Depending on the value of server_try_cancel parameter, this will
1172 // test one of the following three scenarios:
1173 // CANCEL_BEFORE_PROCESSING: Rpc is cancelled by the server before reading/
1174 // writing any messages from/to the client
1175 //
1176 // CANCEL_DURING_PROCESSING: Rpc is cancelled by the server while reading
1177 // messages from the client
1178 //
1179 // CANCEL_AFTER PROCESSING: Rpc is cancelled by server after reading all
1180 // messages from the client (but before sending any status back to the
1181 // client)
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001182 void TestBidiStreamingServerCancel(
1183 ServerTryCancelRequestPhase server_try_cancel) {
1184 ResetStub();
1185
1186 EchoRequest send_request;
1187 EchoRequest recv_request;
1188 EchoResponse send_response;
1189 EchoResponse recv_response;
1190 Status recv_status;
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001191 ClientContext cli_ctx;
1192 ServerContext srv_ctx;
1193 ServerAsyncReaderWriter<EchoResponse, EchoRequest> srv_stream(&srv_ctx);
1194
1195 // Initiate the call from the client side
1196 std::unique_ptr<ClientAsyncReaderWriter<EchoRequest, EchoResponse>>
Sree Kuchibhotla4fb59082016-01-29 11:16:24 -08001197 cli_stream(stub_->AsyncBidiStream(&cli_ctx, cq_.get(), tag(1)));
Vijay Paidf8b62c2016-05-02 14:34:24 -07001198 Verifier(GetParam().disable_blocking).Expect(1, true).Verify(cq_.get());
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001199
1200 // On the server, request to be notified of the 'BidiStream' call and
1201 // receive the call just made by the client
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001202 srv_ctx.AsyncNotifyWhenDone(tag(11));
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001203 service_.RequestBidiStream(&srv_ctx, &srv_stream, cq_.get(), cq_.get(),
1204 tag(2));
Vijay Paidf8b62c2016-05-02 14:34:24 -07001205 Verifier(GetParam().disable_blocking).Expect(2, true).Verify(cq_.get());
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001206
Sree Kuchibhotla0f242ac2016-01-29 18:12:19 -08001207 // Client sends the first and the only message
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001208 send_request.set_message("Ping");
1209 cli_stream->Write(send_request, tag(3));
Vijay Paidf8b62c2016-05-02 14:34:24 -07001210 Verifier(GetParam().disable_blocking).Expect(3, true).Verify(cq_.get());
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001211
1212 bool expected_cq_result = true;
1213 bool ignore_cq_result = false;
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001214 bool want_done_tag = false;
Sree Kuchibhotla0f242ac2016-01-29 18:12:19 -08001215
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001216 if (server_try_cancel == CANCEL_BEFORE_PROCESSING) {
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001217 srv_ctx.TryCancel();
Vijay Paidf8b62c2016-05-02 14:34:24 -07001218 Verifier(GetParam().disable_blocking).Expect(11, true).Verify(cq_.get());
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001219 EXPECT_TRUE(srv_ctx.IsCancelled());
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001220
1221 // We know for sure that all cq results will be false from this point
1222 // since the server cancelled the RPC
1223 expected_cq_result = false;
1224 }
1225
1226 std::thread* server_try_cancel_thd = NULL;
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001227
Vijay Paidf8b62c2016-05-02 14:34:24 -07001228 auto verif = Verifier(GetParam().disable_blocking);
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001229
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001230 if (server_try_cancel == CANCEL_DURING_PROCESSING) {
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001231 server_try_cancel_thd =
1232 new std::thread(&ServerContext::TryCancel, &srv_ctx);
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001233
1234 // Since server is going to cancel the RPC in a parallel thread, some of
1235 // the cq results (i.e those until the cancellation) might be true. Since
1236 // that number is non-deterministic, it is better to ignore the cq results
1237 ignore_cq_result = true;
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001238 // Expect that we might possibly see the done tag that
1239 // indicates cancellation completion in this case
1240 want_done_tag = true;
1241 verif.Expect(11, true);
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001242 }
1243
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001244 int got_tag;
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001245 srv_stream.Read(&recv_request, tag(4));
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001246 verif.Expect(4, expected_cq_result);
1247 got_tag = verif.Next(cq_.get(), ignore_cq_result);
1248 GPR_ASSERT((got_tag == 4) || (got_tag == 11 && want_done_tag));
1249 if (got_tag == 11) {
1250 EXPECT_TRUE(srv_ctx.IsCancelled());
1251 want_done_tag = false;
1252 // Now get the other entry that we were waiting on
1253 EXPECT_EQ(verif.Next(cq_.get(), ignore_cq_result), 4);
1254 }
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001255
1256 send_response.set_message("Pong");
1257 srv_stream.Write(send_response, tag(5));
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001258 verif.Expect(5, expected_cq_result);
1259 got_tag = verif.Next(cq_.get(), ignore_cq_result);
1260 GPR_ASSERT((got_tag == 5) || (got_tag == 11 && want_done_tag));
1261 if (got_tag == 11) {
1262 EXPECT_TRUE(srv_ctx.IsCancelled());
1263 want_done_tag = false;
1264 // Now get the other entry that we were waiting on
1265 EXPECT_EQ(verif.Next(cq_.get(), ignore_cq_result), 5);
1266 }
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001267
1268 cli_stream->Read(&recv_response, tag(6));
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001269 verif.Expect(6, expected_cq_result);
1270 got_tag = verif.Next(cq_.get(), ignore_cq_result);
1271 GPR_ASSERT((got_tag == 6) || (got_tag == 11 && want_done_tag));
1272 if (got_tag == 11) {
1273 EXPECT_TRUE(srv_ctx.IsCancelled());
1274 want_done_tag = false;
1275 // Now get the other entry that we were waiting on
1276 EXPECT_EQ(verif.Next(cq_.get(), ignore_cq_result), 6);
1277 }
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001278
1279 // This is expected to succeed in all cases
1280 cli_stream->WritesDone(tag(7));
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001281 verif.Expect(7, true);
1282 got_tag = verif.Next(cq_.get(), ignore_cq_result);
1283 GPR_ASSERT((got_tag == 7) || (got_tag == 11 && want_done_tag));
1284 if (got_tag == 11) {
1285 EXPECT_TRUE(srv_ctx.IsCancelled());
1286 want_done_tag = false;
1287 // Now get the other entry that we were waiting on
1288 EXPECT_EQ(verif.Next(cq_.get(), ignore_cq_result), 7);
1289 }
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001290
Sree Kuchibhotla0f242ac2016-01-29 18:12:19 -08001291 // This is expected to fail in all cases i.e for all values of
Vijay Pai018879a2016-02-16 09:20:50 -08001292 // server_try_cancel. This is because at this point, either there are no
Sree Kuchibhotla0f242ac2016-01-29 18:12:19 -08001293 // more msgs from the client (because client called WritesDone) or the RPC
1294 // is cancelled on the server
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001295 srv_stream.Read(&recv_request, tag(8));
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001296 verif.Expect(8, false);
1297 got_tag = verif.Next(cq_.get(), ignore_cq_result);
1298 GPR_ASSERT((got_tag == 8) || (got_tag == 11 && want_done_tag));
1299 if (got_tag == 11) {
1300 EXPECT_TRUE(srv_ctx.IsCancelled());
1301 want_done_tag = false;
1302 // Now get the other entry that we were waiting on
1303 EXPECT_EQ(verif.Next(cq_.get(), ignore_cq_result), 8);
1304 }
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001305
1306 if (server_try_cancel_thd != NULL) {
1307 server_try_cancel_thd->join();
1308 delete server_try_cancel_thd;
1309 }
1310
1311 if (server_try_cancel == CANCEL_AFTER_PROCESSING) {
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001312 srv_ctx.TryCancel();
1313 want_done_tag = true;
1314 verif.Expect(11, true);
1315 }
1316
1317 if (want_done_tag) {
1318 verif.Verify(cq_.get());
1319 EXPECT_TRUE(srv_ctx.IsCancelled());
1320 want_done_tag = false;
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001321 }
1322
Sree Kuchibhotla0f242ac2016-01-29 18:12:19 -08001323 // The RPC has been cancelled at this point for sure (i.e irrespective of
1324 // the value of `server_try_cancel` is). So, from this point forward, we
1325 // know that cq results are supposed to return false on server.
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001326
1327 srv_stream.Finish(Status::CANCELLED, tag(9));
Vijay Paidf8b62c2016-05-02 14:34:24 -07001328 Verifier(GetParam().disable_blocking).Expect(9, false).Verify(cq_.get());
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001329
1330 cli_stream->Finish(&recv_status, tag(10));
Vijay Paidf8b62c2016-05-02 14:34:24 -07001331 Verifier(GetParam().disable_blocking).Expect(10, true).Verify(cq_.get());
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001332 EXPECT_FALSE(recv_status.ok());
1333 EXPECT_EQ(grpc::StatusCode::CANCELLED, recv_status.error_code());
1334 }
1335};
1336
1337TEST_P(AsyncEnd2endServerTryCancelTest, ClientStreamingServerTryCancelBefore) {
1338 TestClientStreamingServerCancel(CANCEL_BEFORE_PROCESSING);
1339}
1340
1341TEST_P(AsyncEnd2endServerTryCancelTest, ClientStreamingServerTryCancelDuring) {
1342 TestClientStreamingServerCancel(CANCEL_DURING_PROCESSING);
1343}
1344
1345TEST_P(AsyncEnd2endServerTryCancelTest, ClientStreamingServerTryCancelAfter) {
1346 TestClientStreamingServerCancel(CANCEL_AFTER_PROCESSING);
1347}
1348
1349TEST_P(AsyncEnd2endServerTryCancelTest, ServerStreamingServerTryCancelBefore) {
1350 TestServerStreamingServerCancel(CANCEL_BEFORE_PROCESSING);
1351}
1352
1353TEST_P(AsyncEnd2endServerTryCancelTest, ServerStreamingServerTryCancelDuring) {
1354 TestServerStreamingServerCancel(CANCEL_DURING_PROCESSING);
1355}
1356
1357TEST_P(AsyncEnd2endServerTryCancelTest, ServerStreamingServerTryCancelAfter) {
1358 TestServerStreamingServerCancel(CANCEL_AFTER_PROCESSING);
1359}
1360
1361TEST_P(AsyncEnd2endServerTryCancelTest, ServerBidiStreamingTryCancelBefore) {
1362 TestBidiStreamingServerCancel(CANCEL_BEFORE_PROCESSING);
1363}
1364
1365TEST_P(AsyncEnd2endServerTryCancelTest, ServerBidiStreamingTryCancelDuring) {
1366 TestBidiStreamingServerCancel(CANCEL_DURING_PROCESSING);
1367}
1368
1369TEST_P(AsyncEnd2endServerTryCancelTest, ServerBidiStreamingTryCancelAfter) {
1370 TestBidiStreamingServerCancel(CANCEL_AFTER_PROCESSING);
1371}
1372
Vijay Paidf8b62c2016-05-02 14:34:24 -07001373std::vector<TestScenario> CreateTestScenarios(bool test_disable_blocking,
Vijay Paid7b1e702016-05-02 15:10:21 -07001374 bool test_secure,
1375 int test_big_limit) {
Vijay Paidf8b62c2016-05-02 14:34:24 -07001376 std::vector<TestScenario> scenarios;
1377 std::vector<grpc::string> credentials_types;
Vijay Paid7b1e702016-05-02 15:10:21 -07001378 std::vector<grpc::string> messages;
1379
Vijay Paidf8b62c2016-05-02 14:34:24 -07001380 credentials_types.push_back(kInsecureCredentialsType);
Vijay Paid7b1e702016-05-02 15:10:21 -07001381 auto sec_list = GetSecureCredentialsTypeList();
1382 for (auto sec = sec_list.begin(); sec != sec_list.end(); sec++) {
1383 credentials_types.push_back(*sec);
1384 }
1385
1386 messages.push_back("Hello");
1387 for (int sz = 1; sz < test_big_limit; sz *= 2) {
1388 grpc::string big_msg;
1389 for (int i = 0; i < sz * 1024; i++) {
1390 char c = 'a' + (i % 26);
1391 big_msg += c;
1392 }
1393 messages.push_back(big_msg);
1394 }
1395
1396 for (auto cred = credentials_types.begin(); cred != credentials_types.end();
1397 ++cred) {
1398 for (auto msg = messages.begin(); msg != messages.end(); msg++) {
1399 scenarios.push_back(TestScenario(false, *cred, *msg));
1400 if (test_disable_blocking) {
1401 scenarios.push_back(TestScenario(true, *cred, *msg));
1402 }
Vijay Paidf8b62c2016-05-02 14:34:24 -07001403 }
1404 }
1405 return scenarios;
1406}
1407
Craig Tiller4c06b822015-08-06 08:41:31 -07001408INSTANTIATE_TEST_CASE_P(AsyncEnd2end, AsyncEnd2endTest,
Vijay Paid7b1e702016-05-02 15:10:21 -07001409 ::testing::ValuesIn(CreateTestScenarios(true, true,
1410 1024)));
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001411INSTANTIATE_TEST_CASE_P(AsyncEnd2endServerTryCancel,
1412 AsyncEnd2endServerTryCancelTest,
Vijay Paid7b1e702016-05-02 15:10:21 -07001413 ::testing::ValuesIn(CreateTestScenarios(false, false,
1414 0)));
Craig Tiller69f90e62015-08-06 08:32:35 -07001415
Craig Tiller0220cf12015-02-12 17:39:26 -08001416} // namespace
1417} // namespace testing
1418} // namespace grpc
1419
1420int main(int argc, char** argv) {
1421 grpc_test_init(argc, argv);
Vijay Paib65eda42016-02-16 13:48:05 -08001422 gpr_tls_init(&g_is_async_end2end_test);
Craig Tiller0220cf12015-02-12 17:39:26 -08001423 ::testing::InitGoogleTest(&argc, argv);
Vijay Paib65eda42016-02-16 13:48:05 -08001424 int ret = RUN_ALL_TESTS();
1425 gpr_tls_destroy(&g_is_async_end2end_test);
1426 return ret;
Craig Tiller0220cf12015-02-12 17:39:26 -08001427}