blob: b83980150061ef18b8275d971b36f52fad448f67 [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
David Klempner6fb122d2016-05-13 15:24:17 -0700248 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);
David Klempner6fb122d2016-05-13 15:24:17 -0700277 grpc_recycle_unused_port(port_);
Craig Tiller492968f2015-02-18 13:14:03 -0800278 }
Craig Tiller0220cf12015-02-12 17:39:26 -0800279
280 void ResetStub() {
Vijay Paidf8b62c2016-05-02 14:34:24 -0700281 ChannelArguments args;
282 auto channel_creds =
283 GetChannelCredentials(GetParam().credentials_type, &args);
yang-g730055d2015-08-27 12:29:45 -0700284 std::shared_ptr<Channel> channel =
Vijay Paidf8b62c2016-05-02 14:34:24 -0700285 CreateCustomChannel(server_address_.str(), channel_creds, args);
Sree Kuchibhotla5a05f512016-01-13 22:43:20 -0800286 stub_ = grpc::testing::EchoTestService::NewStub(channel);
Craig Tiller0220cf12015-02-12 17:39:26 -0800287 }
288
Yang Gao406b32f2015-02-13 16:25:33 -0800289 void SendRpc(int num_rpcs) {
290 for (int i = 0; i < num_rpcs; i++) {
291 EchoRequest send_request;
292 EchoRequest recv_request;
293 EchoResponse send_response;
294 EchoResponse recv_response;
295 Status recv_status;
296
297 ClientContext cli_ctx;
298 ServerContext srv_ctx;
299 grpc::ServerAsyncResponseWriter<EchoResponse> response_writer(&srv_ctx);
300
Vijay Paid7b1e702016-05-02 15:10:21 -0700301 send_request.set_message(GetParam().message_content);
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800302 std::unique_ptr<ClientAsyncResponseReader<EchoResponse>> response_reader(
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700303 stub_->AsyncEcho(&cli_ctx, send_request, cq_.get()));
Yang Gao406b32f2015-02-13 16:25:33 -0800304
Craig Tillerd6c98df2015-08-18 09:33:44 -0700305 service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, cq_.get(),
306 cq_.get(), tag(2));
Yang Gao406b32f2015-02-13 16:25:33 -0800307
Vijay Paidf8b62c2016-05-02 14:34:24 -0700308 Verifier(GetParam().disable_blocking).Expect(2, true).Verify(cq_.get());
Yang Gao406b32f2015-02-13 16:25:33 -0800309 EXPECT_EQ(send_request.message(), recv_request.message());
310
311 send_response.set_message(recv_request.message());
312 response_writer.Finish(send_response, Status::OK, tag(3));
Yang Gao3a5e5492015-02-18 14:32:38 -0800313 response_reader->Finish(&recv_response, &recv_status, tag(4));
Craig Tillere4d27482016-05-03 12:19:33 -0700314 Verifier(GetParam().disable_blocking)
315 .Expect(3, true)
316 .Expect(4, true)
317 .Verify(cq_.get());
Yang Gao406b32f2015-02-13 16:25:33 -0800318
319 EXPECT_EQ(send_response.message(), recv_response.message());
Yang Gaoc1a2c312015-06-16 10:59:46 -0700320 EXPECT_TRUE(recv_status.ok());
Yang Gao406b32f2015-02-13 16:25:33 -0800321 }
322 }
323
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700324 std::unique_ptr<ServerCompletionQueue> cq_;
Sree Kuchibhotla5a05f512016-01-13 22:43:20 -0800325 std::unique_ptr<grpc::testing::EchoTestService::Stub> stub_;
Craig Tiller0220cf12015-02-12 17:39:26 -0800326 std::unique_ptr<Server> server_;
Sree Kuchibhotla5a05f512016-01-13 22:43:20 -0800327 grpc::testing::EchoTestService::AsyncService service_;
Craig Tiller0220cf12015-02-12 17:39:26 -0800328 std::ostringstream server_address_;
David Klempner6fb122d2016-05-13 15:24:17 -0700329 int port_;
vjpaicf4daeb2016-02-15 02:33:54 -0800330
Vijay Pai018879a2016-02-16 09:20:50 -0800331 std::unique_ptr<PollingOverrider> poll_overrider_;
Craig Tiller0220cf12015-02-12 17:39:26 -0800332};
333
Craig Tiller69f90e62015-08-06 08:32:35 -0700334TEST_P(AsyncEnd2endTest, SimpleRpc) {
Craig Tiller0220cf12015-02-12 17:39:26 -0800335 ResetStub();
Yang Gao406b32f2015-02-13 16:25:33 -0800336 SendRpc(1);
337}
Yang Gaobb84a302015-02-12 23:30:12 -0800338
Craig Tiller69f90e62015-08-06 08:32:35 -0700339TEST_P(AsyncEnd2endTest, SequentialRpcs) {
Yang Gao406b32f2015-02-13 16:25:33 -0800340 ResetStub();
341 SendRpc(10);
Craig Tiller0220cf12015-02-12 17:39:26 -0800342}
343
vjpai7aadf462015-03-16 23:58:44 -0700344// Test a simple RPC using the async version of Next
Craig Tiller69f90e62015-08-06 08:32:35 -0700345TEST_P(AsyncEnd2endTest, AsyncNextRpc) {
vjpai7aadf462015-03-16 23:58:44 -0700346 ResetStub();
347
348 EchoRequest send_request;
349 EchoRequest recv_request;
350 EchoResponse send_response;
351 EchoResponse recv_response;
352 Status recv_status;
353
354 ClientContext cli_ctx;
355 ServerContext srv_ctx;
356 grpc::ServerAsyncResponseWriter<EchoResponse> response_writer(&srv_ctx);
357
Vijay Paid7b1e702016-05-02 15:10:21 -0700358 send_request.set_message(GetParam().message_content);
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800359 std::unique_ptr<ClientAsyncResponseReader<EchoResponse>> response_reader(
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700360 stub_->AsyncEcho(&cli_ctx, send_request, cq_.get()));
vjpai7aadf462015-03-16 23:58:44 -0700361
Yang Gao757afae2015-03-17 15:49:26 -0700362 std::chrono::system_clock::time_point time_now(
Craig Tillerf51199f2015-05-08 09:32:53 -0700363 std::chrono::system_clock::now());
364 std::chrono::system_clock::time_point time_limit(
365 std::chrono::system_clock::now() + std::chrono::seconds(10));
Vijay Paidf8b62c2016-05-02 14:34:24 -0700366 Verifier(GetParam().disable_blocking).Verify(cq_.get(), time_now);
367 Verifier(GetParam().disable_blocking).Verify(cq_.get(), time_now);
vjpai7aadf462015-03-16 23:58:44 -0700368
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700369 service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, cq_.get(),
370 cq_.get(), tag(2));
vjpai7aadf462015-03-16 23:58:44 -0700371
Vijay Paidf8b62c2016-05-02 14:34:24 -0700372 Verifier(GetParam().disable_blocking)
373 .Expect(2, true)
374 .Verify(cq_.get(), time_limit);
vjpai7aadf462015-03-16 23:58:44 -0700375 EXPECT_EQ(send_request.message(), recv_request.message());
vjpai7aadf462015-03-16 23:58:44 -0700376
377 send_response.set_message(recv_request.message());
378 response_writer.Finish(send_response, Status::OK, tag(3));
vjpai7aadf462015-03-16 23:58:44 -0700379 response_reader->Finish(&recv_response, &recv_status, tag(4));
Vijay Paidf8b62c2016-05-02 14:34:24 -0700380 Verifier(GetParam().disable_blocking)
Craig Tillere4d27482016-05-03 12:19:33 -0700381 .Expect(3, true)
Craig Tiller4c06b822015-08-06 08:41:31 -0700382 .Expect(4, true)
383 .Verify(cq_.get(), std::chrono::system_clock::time_point::max());
vjpai7aadf462015-03-16 23:58:44 -0700384
385 EXPECT_EQ(send_response.message(), recv_response.message());
Yang Gaoc1a2c312015-06-16 10:59:46 -0700386 EXPECT_TRUE(recv_status.ok());
vjpai7aadf462015-03-16 23:58:44 -0700387}
Yang Gao757afae2015-03-17 15:49:26 -0700388
Yang Gao0e0d8e12015-02-13 14:40:41 -0800389// Two pings and a final pong.
Craig Tiller69f90e62015-08-06 08:32:35 -0700390TEST_P(AsyncEnd2endTest, SimpleClientStreaming) {
Yang Gao005f18a2015-02-13 10:22:33 -0800391 ResetStub();
392
393 EchoRequest send_request;
394 EchoRequest recv_request;
395 EchoResponse send_response;
396 EchoResponse recv_response;
397 Status recv_status;
398 ClientContext cli_ctx;
399 ServerContext srv_ctx;
400 ServerAsyncReader<EchoResponse, EchoRequest> srv_stream(&srv_ctx);
401
Vijay Paid7b1e702016-05-02 15:10:21 -0700402 send_request.set_message(GetParam().message_content);
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800403 std::unique_ptr<ClientAsyncWriter<EchoRequest>> cli_stream(
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700404 stub_->AsyncRequestStream(&cli_ctx, &recv_response, cq_.get(), tag(1)));
Yang Gao005f18a2015-02-13 10:22:33 -0800405
Craig Tillerd6c98df2015-08-18 09:33:44 -0700406 service_.RequestRequestStream(&srv_ctx, &srv_stream, cq_.get(), cq_.get(),
407 tag(2));
Yang Gao005f18a2015-02-13 10:22:33 -0800408
Vijay Paidf8b62c2016-05-02 14:34:24 -0700409 Verifier(GetParam().disable_blocking)
410 .Expect(2, true)
411 .Expect(1, true)
412 .Verify(cq_.get());
Yang Gao005f18a2015-02-13 10:22:33 -0800413
414 cli_stream->Write(send_request, tag(3));
Yang Gao005f18a2015-02-13 10:22:33 -0800415 srv_stream.Read(&recv_request, tag(4));
Craig Tillere4d27482016-05-03 12:19:33 -0700416 Verifier(GetParam().disable_blocking)
417 .Expect(3, true)
418 .Expect(4, true)
419 .Verify(cq_.get());
Yang Gao005f18a2015-02-13 10:22:33 -0800420 EXPECT_EQ(send_request.message(), recv_request.message());
421
422 cli_stream->Write(send_request, tag(5));
Yang Gao005f18a2015-02-13 10:22:33 -0800423 srv_stream.Read(&recv_request, tag(6));
Craig Tillere4d27482016-05-03 12:19:33 -0700424 Verifier(GetParam().disable_blocking)
425 .Expect(5, true)
426 .Expect(6, true)
427 .Verify(cq_.get());
Yang Gao005f18a2015-02-13 10:22:33 -0800428
429 EXPECT_EQ(send_request.message(), recv_request.message());
430 cli_stream->WritesDone(tag(7));
Yang Gao005f18a2015-02-13 10:22:33 -0800431 srv_stream.Read(&recv_request, tag(8));
Craig Tillere4d27482016-05-03 12:19:33 -0700432 Verifier(GetParam().disable_blocking)
433 .Expect(7, true)
434 .Expect(8, false)
435 .Verify(cq_.get());
Yang Gao005f18a2015-02-13 10:22:33 -0800436
437 send_response.set_message(recv_request.message());
438 srv_stream.Finish(send_response, Status::OK, tag(9));
Yang Gao005f18a2015-02-13 10:22:33 -0800439 cli_stream->Finish(&recv_status, tag(10));
Craig Tillere4d27482016-05-03 12:19:33 -0700440 Verifier(GetParam().disable_blocking)
441 .Expect(9, true)
442 .Expect(10, true)
443 .Verify(cq_.get());
Yang Gao005f18a2015-02-13 10:22:33 -0800444
445 EXPECT_EQ(send_response.message(), recv_response.message());
Yang Gaoc1a2c312015-06-16 10:59:46 -0700446 EXPECT_TRUE(recv_status.ok());
Yang Gao005f18a2015-02-13 10:22:33 -0800447}
448
Yang Gao0e0d8e12015-02-13 14:40:41 -0800449// One ping, two pongs.
Craig Tiller69f90e62015-08-06 08:32:35 -0700450TEST_P(AsyncEnd2endTest, SimpleServerStreaming) {
Yang Gao0e0d8e12015-02-13 14:40:41 -0800451 ResetStub();
452
453 EchoRequest send_request;
454 EchoRequest recv_request;
455 EchoResponse send_response;
456 EchoResponse recv_response;
457 Status recv_status;
458 ClientContext cli_ctx;
459 ServerContext srv_ctx;
460 ServerAsyncWriter<EchoResponse> srv_stream(&srv_ctx);
461
Vijay Paid7b1e702016-05-02 15:10:21 -0700462 send_request.set_message(GetParam().message_content);
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800463 std::unique_ptr<ClientAsyncReader<EchoResponse>> cli_stream(
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700464 stub_->AsyncResponseStream(&cli_ctx, send_request, cq_.get(), tag(1)));
Yang Gao0e0d8e12015-02-13 14:40:41 -0800465
Craig Tillerf9e6adf2015-05-06 11:45:59 -0700466 service_.RequestResponseStream(&srv_ctx, &recv_request, &srv_stream,
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700467 cq_.get(), cq_.get(), tag(2));
Yang Gao0e0d8e12015-02-13 14:40:41 -0800468
Vijay Paidf8b62c2016-05-02 14:34:24 -0700469 Verifier(GetParam().disable_blocking)
470 .Expect(1, true)
471 .Expect(2, true)
472 .Verify(cq_.get());
Yang Gao0e0d8e12015-02-13 14:40:41 -0800473 EXPECT_EQ(send_request.message(), recv_request.message());
474
475 send_response.set_message(recv_request.message());
476 srv_stream.Write(send_response, tag(3));
Yang Gao0e0d8e12015-02-13 14:40:41 -0800477 cli_stream->Read(&recv_response, tag(4));
Craig Tillere4d27482016-05-03 12:19:33 -0700478 Verifier(GetParam().disable_blocking)
479 .Expect(3, true)
480 .Expect(4, true)
481 .Verify(cq_.get());
Yang Gao0e0d8e12015-02-13 14:40:41 -0800482 EXPECT_EQ(send_response.message(), recv_response.message());
483
484 srv_stream.Write(send_response, tag(5));
Yang Gao0e0d8e12015-02-13 14:40:41 -0800485 cli_stream->Read(&recv_response, tag(6));
Craig Tillere4d27482016-05-03 12:19:33 -0700486 Verifier(GetParam().disable_blocking)
487 .Expect(5, true)
488 .Expect(6, true)
489 .Verify(cq_.get());
Yang Gao0e0d8e12015-02-13 14:40:41 -0800490 EXPECT_EQ(send_response.message(), recv_response.message());
491
492 srv_stream.Finish(Status::OK, tag(7));
Yang Gao0e0d8e12015-02-13 14:40:41 -0800493 cli_stream->Read(&recv_response, tag(8));
Craig Tillere4d27482016-05-03 12:19:33 -0700494 Verifier(GetParam().disable_blocking)
495 .Expect(7, true)
496 .Expect(8, false)
497 .Verify(cq_.get());
Yang Gao0e0d8e12015-02-13 14:40:41 -0800498
499 cli_stream->Finish(&recv_status, tag(9));
Vijay Paidf8b62c2016-05-02 14:34:24 -0700500 Verifier(GetParam().disable_blocking).Expect(9, true).Verify(cq_.get());
Yang Gao0e0d8e12015-02-13 14:40:41 -0800501
Yang Gaoc1a2c312015-06-16 10:59:46 -0700502 EXPECT_TRUE(recv_status.ok());
Yang Gao0e0d8e12015-02-13 14:40:41 -0800503}
504
505// One ping, one pong.
Craig Tiller69f90e62015-08-06 08:32:35 -0700506TEST_P(AsyncEnd2endTest, SimpleBidiStreaming) {
Yang Gaoc05b6cb2015-02-13 00:34:10 -0800507 ResetStub();
508
509 EchoRequest send_request;
510 EchoRequest recv_request;
511 EchoResponse send_response;
512 EchoResponse recv_response;
513 Status recv_status;
514 ClientContext cli_ctx;
515 ServerContext srv_ctx;
516 ServerAsyncReaderWriter<EchoResponse, EchoRequest> srv_stream(&srv_ctx);
517
Vijay Paid7b1e702016-05-02 15:10:21 -0700518 send_request.set_message(GetParam().message_content);
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800519 std::unique_ptr<ClientAsyncReaderWriter<EchoRequest, EchoResponse>>
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700520 cli_stream(stub_->AsyncBidiStream(&cli_ctx, cq_.get(), tag(1)));
Yang Gaoc05b6cb2015-02-13 00:34:10 -0800521
Craig Tillerd6c98df2015-08-18 09:33:44 -0700522 service_.RequestBidiStream(&srv_ctx, &srv_stream, cq_.get(), cq_.get(),
523 tag(2));
Yang Gaoc05b6cb2015-02-13 00:34:10 -0800524
Vijay Paidf8b62c2016-05-02 14:34:24 -0700525 Verifier(GetParam().disable_blocking)
526 .Expect(1, true)
527 .Expect(2, true)
528 .Verify(cq_.get());
Yang Gaoc05b6cb2015-02-13 00:34:10 -0800529
530 cli_stream->Write(send_request, tag(3));
Yang Gaoc05b6cb2015-02-13 00:34:10 -0800531 srv_stream.Read(&recv_request, tag(4));
Craig Tillere4d27482016-05-03 12:19:33 -0700532 Verifier(GetParam().disable_blocking)
533 .Expect(3, true)
534 .Expect(4, true)
535 .Verify(cq_.get());
Yang Gaoc05b6cb2015-02-13 00:34:10 -0800536 EXPECT_EQ(send_request.message(), recv_request.message());
537
538 send_response.set_message(recv_request.message());
539 srv_stream.Write(send_response, tag(5));
Yang Gaoc05b6cb2015-02-13 00:34:10 -0800540 cli_stream->Read(&recv_response, tag(6));
Craig Tillere4d27482016-05-03 12:19:33 -0700541 Verifier(GetParam().disable_blocking)
542 .Expect(5, true)
543 .Expect(6, true)
544 .Verify(cq_.get());
Yang Gaoc05b6cb2015-02-13 00:34:10 -0800545 EXPECT_EQ(send_response.message(), recv_response.message());
546
547 cli_stream->WritesDone(tag(7));
Yang Gaoc05b6cb2015-02-13 00:34:10 -0800548 srv_stream.Read(&recv_request, tag(8));
Craig Tillere4d27482016-05-03 12:19:33 -0700549 Verifier(GetParam().disable_blocking)
550 .Expect(7, true)
551 .Expect(8, false)
552 .Verify(cq_.get());
Yang Gaoc05b6cb2015-02-13 00:34:10 -0800553
554 srv_stream.Finish(Status::OK, tag(9));
Yang Gaoc05b6cb2015-02-13 00:34:10 -0800555 cli_stream->Finish(&recv_status, tag(10));
Craig Tillere4d27482016-05-03 12:19:33 -0700556 Verifier(GetParam().disable_blocking)
557 .Expect(9, true)
558 .Expect(10, true)
559 .Verify(cq_.get());
Yang Gaoc05b6cb2015-02-13 00:34:10 -0800560
Yang Gaoc1a2c312015-06-16 10:59:46 -0700561 EXPECT_TRUE(recv_status.ok());
Yang Gaoc05b6cb2015-02-13 00:34:10 -0800562}
563
Yang Gao406b32f2015-02-13 16:25:33 -0800564// Metadata tests
Craig Tiller69f90e62015-08-06 08:32:35 -0700565TEST_P(AsyncEnd2endTest, ClientInitialMetadataRpc) {
Yang Gao406b32f2015-02-13 16:25:33 -0800566 ResetStub();
567
568 EchoRequest send_request;
569 EchoRequest recv_request;
570 EchoResponse send_response;
571 EchoResponse recv_response;
572 Status recv_status;
573
574 ClientContext cli_ctx;
575 ServerContext srv_ctx;
576 grpc::ServerAsyncResponseWriter<EchoResponse> response_writer(&srv_ctx);
577
Vijay Paid7b1e702016-05-02 15:10:21 -0700578 send_request.set_message(GetParam().message_content);
Yang Gao406b32f2015-02-13 16:25:33 -0800579 std::pair<grpc::string, grpc::string> meta1("key1", "val1");
580 std::pair<grpc::string, grpc::string> meta2("key2", "val2");
Craig Tiller6f871642016-02-03 16:15:31 -0800581 std::pair<grpc::string, grpc::string> meta3("g.r.d-bin", "xyz");
Yang Gao406b32f2015-02-13 16:25:33 -0800582 cli_ctx.AddMetadata(meta1.first, meta1.second);
583 cli_ctx.AddMetadata(meta2.first, meta2.second);
Craig Tiller6f871642016-02-03 16:15:31 -0800584 cli_ctx.AddMetadata(meta3.first, meta3.second);
Yang Gao406b32f2015-02-13 16:25:33 -0800585
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800586 std::unique_ptr<ClientAsyncResponseReader<EchoResponse>> response_reader(
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700587 stub_->AsyncEcho(&cli_ctx, send_request, cq_.get()));
Yang Gao406b32f2015-02-13 16:25:33 -0800588
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700589 service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, cq_.get(),
590 cq_.get(), tag(2));
Vijay Paidf8b62c2016-05-02 14:34:24 -0700591 Verifier(GetParam().disable_blocking).Expect(2, true).Verify(cq_.get());
Yang Gao406b32f2015-02-13 16:25:33 -0800592 EXPECT_EQ(send_request.message(), recv_request.message());
593 auto client_initial_metadata = srv_ctx.client_metadata();
yang-ge21908f2015-08-25 13:47:51 -0700594 EXPECT_EQ(meta1.second,
595 ToString(client_initial_metadata.find(meta1.first)->second));
596 EXPECT_EQ(meta2.second,
597 ToString(client_initial_metadata.find(meta2.first)->second));
Craig Tiller6f871642016-02-03 16:15:31 -0800598 EXPECT_EQ(meta3.second,
599 ToString(client_initial_metadata.find(meta3.first)->second));
Craig Tiller8bf2dca2015-07-10 13:08:41 -0700600 EXPECT_GE(client_initial_metadata.size(), static_cast<size_t>(2));
Yang Gao406b32f2015-02-13 16:25:33 -0800601
602 send_response.set_message(recv_request.message());
603 response_writer.Finish(send_response, Status::OK, tag(3));
Yang Gao3a5e5492015-02-18 14:32:38 -0800604 response_reader->Finish(&recv_response, &recv_status, tag(4));
Craig Tillere4d27482016-05-03 12:19:33 -0700605 Verifier(GetParam().disable_blocking)
606 .Expect(3, true)
607 .Expect(4, true)
608 .Verify(cq_.get());
Yang Gao406b32f2015-02-13 16:25:33 -0800609
610 EXPECT_EQ(send_response.message(), recv_response.message());
Yang Gaoc1a2c312015-06-16 10:59:46 -0700611 EXPECT_TRUE(recv_status.ok());
Yang Gao406b32f2015-02-13 16:25:33 -0800612}
613
Craig Tiller69f90e62015-08-06 08:32:35 -0700614TEST_P(AsyncEnd2endTest, ServerInitialMetadataRpc) {
Yang Gao2b7f5372015-02-18 00:45:53 -0800615 ResetStub();
616
617 EchoRequest send_request;
618 EchoRequest recv_request;
619 EchoResponse send_response;
620 EchoResponse recv_response;
621 Status recv_status;
622
623 ClientContext cli_ctx;
624 ServerContext srv_ctx;
625 grpc::ServerAsyncResponseWriter<EchoResponse> response_writer(&srv_ctx);
626
Vijay Paid7b1e702016-05-02 15:10:21 -0700627 send_request.set_message(GetParam().message_content);
Yang Gao2b7f5372015-02-18 00:45:53 -0800628 std::pair<grpc::string, grpc::string> meta1("key1", "val1");
629 std::pair<grpc::string, grpc::string> meta2("key2", "val2");
630
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800631 std::unique_ptr<ClientAsyncResponseReader<EchoResponse>> response_reader(
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700632 stub_->AsyncEcho(&cli_ctx, send_request, cq_.get()));
Yang Gao2b7f5372015-02-18 00:45:53 -0800633
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700634 service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, cq_.get(),
635 cq_.get(), tag(2));
Vijay Paidf8b62c2016-05-02 14:34:24 -0700636 Verifier(GetParam().disable_blocking).Expect(2, true).Verify(cq_.get());
Yang Gao2b7f5372015-02-18 00:45:53 -0800637 EXPECT_EQ(send_request.message(), recv_request.message());
638 srv_ctx.AddInitialMetadata(meta1.first, meta1.second);
639 srv_ctx.AddInitialMetadata(meta2.first, meta2.second);
640 response_writer.SendInitialMetadata(tag(3));
Vijay Paidf8b62c2016-05-02 14:34:24 -0700641 Verifier(GetParam().disable_blocking).Expect(3, true).Verify(cq_.get());
Yang Gao2b7f5372015-02-18 00:45:53 -0800642
Yang Gao3a5e5492015-02-18 14:32:38 -0800643 response_reader->ReadInitialMetadata(tag(4));
Vijay Paidf8b62c2016-05-02 14:34:24 -0700644 Verifier(GetParam().disable_blocking).Expect(4, true).Verify(cq_.get());
Yang Gao2b7f5372015-02-18 00:45:53 -0800645 auto server_initial_metadata = cli_ctx.GetServerInitialMetadata();
yang-ge21908f2015-08-25 13:47:51 -0700646 EXPECT_EQ(meta1.second,
647 ToString(server_initial_metadata.find(meta1.first)->second));
648 EXPECT_EQ(meta2.second,
649 ToString(server_initial_metadata.find(meta2.first)->second));
vjpaid5577aa2015-02-18 22:26:48 -0800650 EXPECT_EQ(static_cast<size_t>(2), server_initial_metadata.size());
Yang Gao3a5e5492015-02-18 14:32:38 -0800651
652 send_response.set_message(recv_request.message());
653 response_writer.Finish(send_response, Status::OK, tag(5));
Yang Gao3a5e5492015-02-18 14:32:38 -0800654 response_reader->Finish(&recv_response, &recv_status, tag(6));
Craig Tillere4d27482016-05-03 12:19:33 -0700655 Verifier(GetParam().disable_blocking)
656 .Expect(5, true)
657 .Expect(6, true)
658 .Verify(cq_.get());
Yang Gao3a5e5492015-02-18 14:32:38 -0800659
660 EXPECT_EQ(send_response.message(), recv_response.message());
Yang Gaoc1a2c312015-06-16 10:59:46 -0700661 EXPECT_TRUE(recv_status.ok());
Yang Gao2b7f5372015-02-18 00:45:53 -0800662}
663
Craig Tiller69f90e62015-08-06 08:32:35 -0700664TEST_P(AsyncEnd2endTest, ServerTrailingMetadataRpc) {
Yang Gao2b7f5372015-02-18 00:45:53 -0800665 ResetStub();
666
667 EchoRequest send_request;
668 EchoRequest recv_request;
669 EchoResponse send_response;
670 EchoResponse recv_response;
671 Status recv_status;
672
673 ClientContext cli_ctx;
674 ServerContext srv_ctx;
675 grpc::ServerAsyncResponseWriter<EchoResponse> response_writer(&srv_ctx);
676
Vijay Paid7b1e702016-05-02 15:10:21 -0700677 send_request.set_message(GetParam().message_content);
Yang Gao2b7f5372015-02-18 00:45:53 -0800678 std::pair<grpc::string, grpc::string> meta1("key1", "val1");
679 std::pair<grpc::string, grpc::string> meta2("key2", "val2");
680
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800681 std::unique_ptr<ClientAsyncResponseReader<EchoResponse>> response_reader(
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700682 stub_->AsyncEcho(&cli_ctx, send_request, cq_.get()));
Yang Gao2b7f5372015-02-18 00:45:53 -0800683
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700684 service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, cq_.get(),
685 cq_.get(), tag(2));
Vijay Paidf8b62c2016-05-02 14:34:24 -0700686 Verifier(GetParam().disable_blocking).Expect(2, true).Verify(cq_.get());
Yang Gao2b7f5372015-02-18 00:45:53 -0800687 EXPECT_EQ(send_request.message(), recv_request.message());
688 response_writer.SendInitialMetadata(tag(3));
Vijay Paidf8b62c2016-05-02 14:34:24 -0700689 Verifier(GetParam().disable_blocking).Expect(3, true).Verify(cq_.get());
Yang Gao2b7f5372015-02-18 00:45:53 -0800690
691 send_response.set_message(recv_request.message());
692 srv_ctx.AddTrailingMetadata(meta1.first, meta1.second);
693 srv_ctx.AddTrailingMetadata(meta2.first, meta2.second);
694 response_writer.Finish(send_response, Status::OK, tag(4));
Yang Gao3a5e5492015-02-18 14:32:38 -0800695 response_reader->Finish(&recv_response, &recv_status, tag(5));
Craig Tillere4d27482016-05-03 12:19:33 -0700696
697 Verifier(GetParam().disable_blocking)
698 .Expect(4, true)
699 .Expect(5, true)
700 .Verify(cq_.get());
701
Yang Gao2b7f5372015-02-18 00:45:53 -0800702 EXPECT_EQ(send_response.message(), recv_response.message());
Yang Gaoc1a2c312015-06-16 10:59:46 -0700703 EXPECT_TRUE(recv_status.ok());
Yang Gao2b7f5372015-02-18 00:45:53 -0800704 auto server_trailing_metadata = cli_ctx.GetServerTrailingMetadata();
yang-ge21908f2015-08-25 13:47:51 -0700705 EXPECT_EQ(meta1.second,
706 ToString(server_trailing_metadata.find(meta1.first)->second));
707 EXPECT_EQ(meta2.second,
708 ToString(server_trailing_metadata.find(meta2.first)->second));
vjpaid5577aa2015-02-18 22:26:48 -0800709 EXPECT_EQ(static_cast<size_t>(2), server_trailing_metadata.size());
Yang Gao2b7f5372015-02-18 00:45:53 -0800710}
711
Craig Tiller69f90e62015-08-06 08:32:35 -0700712TEST_P(AsyncEnd2endTest, MetadataRpc) {
Yang Gao2b7f5372015-02-18 00:45:53 -0800713 ResetStub();
714
715 EchoRequest send_request;
716 EchoRequest recv_request;
717 EchoResponse send_response;
718 EchoResponse recv_response;
719 Status recv_status;
720
721 ClientContext cli_ctx;
722 ServerContext srv_ctx;
723 grpc::ServerAsyncResponseWriter<EchoResponse> response_writer(&srv_ctx);
724
Vijay Paid7b1e702016-05-02 15:10:21 -0700725 send_request.set_message(GetParam().message_content);
Yang Gao2b7f5372015-02-18 00:45:53 -0800726 std::pair<grpc::string, grpc::string> meta1("key1", "val1");
Yang Gao3a5e5492015-02-18 14:32:38 -0800727 std::pair<grpc::string, grpc::string> meta2(
Vijay Pai92a928f2015-03-26 16:30:22 -0400728 "key2-bin",
Craig Tillerd6c98df2015-08-18 09:33:44 -0700729 grpc::string("\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc", 13));
Yang Gao2b7f5372015-02-18 00:45:53 -0800730 std::pair<grpc::string, grpc::string> meta3("key3", "val3");
Craig Tiller47c83fd2015-02-21 22:45:35 -0800731 std::pair<grpc::string, grpc::string> meta6(
732 "key4-bin",
Vijay Pai92a928f2015-03-26 16:30:22 -0400733 grpc::string("\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d",
Craig Tillerd6c98df2015-08-18 09:33:44 -0700734 14));
Yang Gao2b7f5372015-02-18 00:45:53 -0800735 std::pair<grpc::string, grpc::string> meta5("key5", "val5");
Craig Tiller47c83fd2015-02-21 22:45:35 -0800736 std::pair<grpc::string, grpc::string> meta4(
737 "key6-bin",
Craig Tillerd6c98df2015-08-18 09:33:44 -0700738 grpc::string(
739 "\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee", 15));
Yang Gao2b7f5372015-02-18 00:45:53 -0800740
741 cli_ctx.AddMetadata(meta1.first, meta1.second);
742 cli_ctx.AddMetadata(meta2.first, meta2.second);
743
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800744 std::unique_ptr<ClientAsyncResponseReader<EchoResponse>> response_reader(
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700745 stub_->AsyncEcho(&cli_ctx, send_request, cq_.get()));
Yang Gao2b7f5372015-02-18 00:45:53 -0800746
Craig Tiller06cf3cc2015-05-13 13:11:01 -0700747 service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, cq_.get(),
748 cq_.get(), tag(2));
Vijay Paidf8b62c2016-05-02 14:34:24 -0700749 Verifier(GetParam().disable_blocking).Expect(2, true).Verify(cq_.get());
Yang Gao2b7f5372015-02-18 00:45:53 -0800750 EXPECT_EQ(send_request.message(), recv_request.message());
751 auto client_initial_metadata = srv_ctx.client_metadata();
yang-ge21908f2015-08-25 13:47:51 -0700752 EXPECT_EQ(meta1.second,
753 ToString(client_initial_metadata.find(meta1.first)->second));
754 EXPECT_EQ(meta2.second,
755 ToString(client_initial_metadata.find(meta2.first)->second));
Craig Tiller8bf2dca2015-07-10 13:08:41 -0700756 EXPECT_GE(client_initial_metadata.size(), static_cast<size_t>(2));
Yang Gao2b7f5372015-02-18 00:45:53 -0800757
758 srv_ctx.AddInitialMetadata(meta3.first, meta3.second);
759 srv_ctx.AddInitialMetadata(meta4.first, meta4.second);
760 response_writer.SendInitialMetadata(tag(3));
Vijay Paidf8b62c2016-05-02 14:34:24 -0700761 Verifier(GetParam().disable_blocking).Expect(3, true).Verify(cq_.get());
Yang Gao3a5e5492015-02-18 14:32:38 -0800762 response_reader->ReadInitialMetadata(tag(4));
Vijay Paidf8b62c2016-05-02 14:34:24 -0700763 Verifier(GetParam().disable_blocking).Expect(4, true).Verify(cq_.get());
Yang Gao2b7f5372015-02-18 00:45:53 -0800764 auto server_initial_metadata = cli_ctx.GetServerInitialMetadata();
yang-ge21908f2015-08-25 13:47:51 -0700765 EXPECT_EQ(meta3.second,
766 ToString(server_initial_metadata.find(meta3.first)->second));
767 EXPECT_EQ(meta4.second,
768 ToString(server_initial_metadata.find(meta4.first)->second));
Craig Tiller8bf2dca2015-07-10 13:08:41 -0700769 EXPECT_GE(server_initial_metadata.size(), static_cast<size_t>(2));
Yang Gao3a5e5492015-02-18 14:32:38 -0800770
771 send_response.set_message(recv_request.message());
772 srv_ctx.AddTrailingMetadata(meta5.first, meta5.second);
773 srv_ctx.AddTrailingMetadata(meta6.first, meta6.second);
774 response_writer.Finish(send_response, Status::OK, tag(5));
Yang Gao3a5e5492015-02-18 14:32:38 -0800775 response_reader->Finish(&recv_response, &recv_status, tag(6));
Craig Tillere4d27482016-05-03 12:19:33 -0700776
777 Verifier(GetParam().disable_blocking)
778 .Expect(5, true)
779 .Expect(6, true)
780 .Verify(cq_.get());
781
Yang Gao3a5e5492015-02-18 14:32:38 -0800782 EXPECT_EQ(send_response.message(), recv_response.message());
Yang Gaoc1a2c312015-06-16 10:59:46 -0700783 EXPECT_TRUE(recv_status.ok());
Yang Gao2b7f5372015-02-18 00:45:53 -0800784 auto server_trailing_metadata = cli_ctx.GetServerTrailingMetadata();
yang-ge21908f2015-08-25 13:47:51 -0700785 EXPECT_EQ(meta5.second,
786 ToString(server_trailing_metadata.find(meta5.first)->second));
787 EXPECT_EQ(meta6.second,
788 ToString(server_trailing_metadata.find(meta6.first)->second));
Craig Tiller8bf2dca2015-07-10 13:08:41 -0700789 EXPECT_GE(server_trailing_metadata.size(), static_cast<size_t>(2));
Yang Gao2b7f5372015-02-18 00:45:53 -0800790}
yang-gb3352562015-08-04 14:42:06 -0700791
792// Server uses AsyncNotifyWhenDone API to check for cancellation
Craig Tiller69f90e62015-08-06 08:32:35 -0700793TEST_P(AsyncEnd2endTest, ServerCheckCancellation) {
yang-gb3352562015-08-04 14:42:06 -0700794 ResetStub();
795
796 EchoRequest send_request;
797 EchoRequest recv_request;
798 EchoResponse send_response;
799 EchoResponse recv_response;
800 Status recv_status;
801
802 ClientContext cli_ctx;
803 ServerContext srv_ctx;
804 grpc::ServerAsyncResponseWriter<EchoResponse> response_writer(&srv_ctx);
805
Vijay Paid7b1e702016-05-02 15:10:21 -0700806 send_request.set_message(GetParam().message_content);
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800807 std::unique_ptr<ClientAsyncResponseReader<EchoResponse>> response_reader(
yang-gb3352562015-08-04 14:42:06 -0700808 stub_->AsyncEcho(&cli_ctx, send_request, cq_.get()));
809
810 srv_ctx.AsyncNotifyWhenDone(tag(5));
811 service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, cq_.get(),
812 cq_.get(), tag(2));
813
Vijay Paidf8b62c2016-05-02 14:34:24 -0700814 Verifier(GetParam().disable_blocking).Expect(2, true).Verify(cq_.get());
yang-gb3352562015-08-04 14:42:06 -0700815 EXPECT_EQ(send_request.message(), recv_request.message());
816
817 cli_ctx.TryCancel();
Vijay Paidf8b62c2016-05-02 14:34:24 -0700818 Verifier(GetParam().disable_blocking).Expect(5, true).Verify(cq_.get());
yang-gb3352562015-08-04 14:42:06 -0700819 EXPECT_TRUE(srv_ctx.IsCancelled());
820
821 response_reader->Finish(&recv_response, &recv_status, tag(4));
yang-g15759f62016-06-01 11:21:27 -0700822 Verifier(GetParam().disable_blocking).Expect(4, true).Verify(cq_.get());
yang-gb3352562015-08-04 14:42:06 -0700823
824 EXPECT_EQ(StatusCode::CANCELLED, recv_status.error_code());
825}
826
827// Server uses AsyncNotifyWhenDone API to check for normal finish
Craig Tiller69f90e62015-08-06 08:32:35 -0700828TEST_P(AsyncEnd2endTest, ServerCheckDone) {
yang-gb3352562015-08-04 14:42:06 -0700829 ResetStub();
830
831 EchoRequest send_request;
832 EchoRequest recv_request;
833 EchoResponse send_response;
834 EchoResponse recv_response;
835 Status recv_status;
836
837 ClientContext cli_ctx;
838 ServerContext srv_ctx;
839 grpc::ServerAsyncResponseWriter<EchoResponse> response_writer(&srv_ctx);
840
Vijay Paid7b1e702016-05-02 15:10:21 -0700841 send_request.set_message(GetParam().message_content);
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800842 std::unique_ptr<ClientAsyncResponseReader<EchoResponse>> response_reader(
yang-gb3352562015-08-04 14:42:06 -0700843 stub_->AsyncEcho(&cli_ctx, send_request, cq_.get()));
844
845 srv_ctx.AsyncNotifyWhenDone(tag(5));
846 service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, cq_.get(),
847 cq_.get(), tag(2));
848
Vijay Paidf8b62c2016-05-02 14:34:24 -0700849 Verifier(GetParam().disable_blocking).Expect(2, true).Verify(cq_.get());
yang-gb3352562015-08-04 14:42:06 -0700850 EXPECT_EQ(send_request.message(), recv_request.message());
851
852 send_response.set_message(recv_request.message());
853 response_writer.Finish(send_response, Status::OK, tag(3));
yang-gb3352562015-08-04 14:42:06 -0700854 response_reader->Finish(&recv_response, &recv_status, tag(4));
Craig Tillere4d27482016-05-03 12:19:33 -0700855 Verifier(GetParam().disable_blocking)
856 .Expect(3, true)
857 .Expect(4, true)
858 .Expect(5, true)
859 .Verify(cq_.get());
860 EXPECT_FALSE(srv_ctx.IsCancelled());
yang-gb3352562015-08-04 14:42:06 -0700861
862 EXPECT_EQ(send_response.message(), recv_response.message());
863 EXPECT_TRUE(recv_status.ok());
864}
865
Craig Tiller8f7bff72015-08-17 13:23:14 -0700866TEST_P(AsyncEnd2endTest, UnimplementedRpc) {
Vijay Paidf8b62c2016-05-02 14:34:24 -0700867 ChannelArguments args;
868 auto channel_creds =
869 GetChannelCredentials(GetParam().credentials_type, &args);
yang-g730055d2015-08-27 12:29:45 -0700870 std::shared_ptr<Channel> channel =
Vijay Paidf8b62c2016-05-02 14:34:24 -0700871 CreateCustomChannel(server_address_.str(), channel_creds, args);
Craig Tiller1b4e3302015-12-17 16:35:00 -0800872 std::unique_ptr<grpc::testing::UnimplementedService::Stub> stub;
873 stub = grpc::testing::UnimplementedService::NewStub(channel);
yang-g9b7757d2015-08-13 11:15:53 -0700874 EchoRequest send_request;
875 EchoResponse recv_response;
876 Status recv_status;
877
878 ClientContext cli_ctx;
Vijay Paid7b1e702016-05-02 15:10:21 -0700879 send_request.set_message(GetParam().message_content);
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800880 std::unique_ptr<ClientAsyncResponseReader<EchoResponse>> response_reader(
yang-g9b7757d2015-08-13 11:15:53 -0700881 stub->AsyncUnimplemented(&cli_ctx, send_request, cq_.get()));
882
883 response_reader->Finish(&recv_response, &recv_status, tag(4));
yang-g15759f62016-06-01 11:21:27 -0700884 Verifier(GetParam().disable_blocking).Expect(4, true).Verify(cq_.get());
yang-g9b7757d2015-08-13 11:15:53 -0700885
886 EXPECT_EQ(StatusCode::UNIMPLEMENTED, recv_status.error_code());
887 EXPECT_EQ("", recv_status.error_message());
888}
889
Sree Kuchibhotla0f242ac2016-01-29 18:12:19 -0800890// This class is for testing scenarios where RPCs are cancelled on the server
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -0800891// by calling ServerContext::TryCancel(). Server uses AsyncNotifyWhenDone
892// API to check for cancellation
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800893class AsyncEnd2endServerTryCancelTest : public AsyncEnd2endTest {
894 protected:
895 typedef enum {
896 DO_NOT_CANCEL = 0,
897 CANCEL_BEFORE_PROCESSING,
898 CANCEL_DURING_PROCESSING,
899 CANCEL_AFTER_PROCESSING
900 } ServerTryCancelRequestPhase;
901
Sree Kuchibhotla0f242ac2016-01-29 18:12:19 -0800902 // Helper for testing client-streaming RPCs which are cancelled on the server.
903 // Depending on the value of server_try_cancel parameter, this will test one
904 // of the following three scenarios:
905 // CANCEL_BEFORE_PROCESSING: Rpc is cancelled by the server before reading
906 // any messages from the client
907 //
908 // CANCEL_DURING_PROCESSING: Rpc is cancelled by the server while reading
909 // messages from the client
910 //
911 // CANCEL_AFTER PROCESSING: Rpc is cancelled by server after reading all
912 // messages from the client (but before sending any status back to the
913 // client)
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800914 void TestClientStreamingServerCancel(
915 ServerTryCancelRequestPhase server_try_cancel) {
916 ResetStub();
917
918 EchoRequest send_request;
919 EchoRequest recv_request;
920 EchoResponse send_response;
921 EchoResponse recv_response;
922 Status recv_status;
923
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800924 ClientContext cli_ctx;
925 ServerContext srv_ctx;
926 ServerAsyncReader<EchoResponse, EchoRequest> srv_stream(&srv_ctx);
927
928 // Initiate the 'RequestStream' call on client
929 std::unique_ptr<ClientAsyncWriter<EchoRequest>> cli_stream(
Sree Kuchibhotla4fb59082016-01-29 11:16:24 -0800930 stub_->AsyncRequestStream(&cli_ctx, &recv_response, cq_.get(), tag(1)));
Vijay Paidf8b62c2016-05-02 14:34:24 -0700931 Verifier(GetParam().disable_blocking).Expect(1, true).Verify(cq_.get());
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800932
933 // On the server, request to be notified of 'RequestStream' calls
934 // and receive the 'RequestStream' call just made by the client
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -0800935 srv_ctx.AsyncNotifyWhenDone(tag(11));
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800936 service_.RequestRequestStream(&srv_ctx, &srv_stream, cq_.get(), cq_.get(),
937 tag(2));
Vijay Paidf8b62c2016-05-02 14:34:24 -0700938 Verifier(GetParam().disable_blocking).Expect(2, true).Verify(cq_.get());
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800939
940 // Client sends 3 messages (tags 3, 4 and 5)
941 for (int tag_idx = 3; tag_idx <= 5; tag_idx++) {
942 send_request.set_message("Ping " + std::to_string(tag_idx));
943 cli_stream->Write(send_request, tag(tag_idx));
Vijay Paidf8b62c2016-05-02 14:34:24 -0700944 Verifier(GetParam().disable_blocking)
945 .Expect(tag_idx, true)
946 .Verify(cq_.get());
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800947 }
948 cli_stream->WritesDone(tag(6));
Vijay Paidf8b62c2016-05-02 14:34:24 -0700949 Verifier(GetParam().disable_blocking).Expect(6, true).Verify(cq_.get());
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800950
951 bool expected_server_cq_result = true;
952 bool ignore_cq_result = false;
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -0800953 bool want_done_tag = false;
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800954
955 if (server_try_cancel == CANCEL_BEFORE_PROCESSING) {
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -0800956 srv_ctx.TryCancel();
Vijay Paidf8b62c2016-05-02 14:34:24 -0700957 Verifier(GetParam().disable_blocking).Expect(11, true).Verify(cq_.get());
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -0800958 EXPECT_TRUE(srv_ctx.IsCancelled());
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800959
960 // Since cancellation is done before server reads any results, we know
961 // for sure that all cq results will return false from this point forward
962 expected_server_cq_result = false;
963 }
964
965 std::thread* server_try_cancel_thd = NULL;
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -0800966
Vijay Paidf8b62c2016-05-02 14:34:24 -0700967 auto verif = Verifier(GetParam().disable_blocking);
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -0800968
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800969 if (server_try_cancel == CANCEL_DURING_PROCESSING) {
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -0800970 server_try_cancel_thd =
971 new std::thread(&ServerContext::TryCancel, &srv_ctx);
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800972 // Server will cancel the RPC in a parallel thread while reading the
973 // requests from the client. Since the cancellation can happen at anytime,
974 // some of the cq results (i.e those until cancellation) might be true but
975 // its non deterministic. So better to ignore the cq results
976 ignore_cq_result = true;
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -0800977 // Expect that we might possibly see the done tag that
978 // indicates cancellation completion in this case
979 want_done_tag = true;
980 verif.Expect(11, true);
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800981 }
982
983 // Server reads 3 messages (tags 6, 7 and 8)
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -0800984 // But if want_done_tag is true, we might also see tag 11
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800985 for (int tag_idx = 6; tag_idx <= 8; tag_idx++) {
986 srv_stream.Read(&recv_request, tag(tag_idx));
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -0800987 // Note that we'll add something to the verifier and verify that
988 // something was seen, but it might be tag 11 and not what we
989 // just added
990 int got_tag = verif.Expect(tag_idx, expected_server_cq_result)
991 .Next(cq_.get(), ignore_cq_result);
992 GPR_ASSERT((got_tag == tag_idx) || (got_tag == 11 && want_done_tag));
993 if (got_tag == 11) {
994 EXPECT_TRUE(srv_ctx.IsCancelled());
995 want_done_tag = false;
996 // Now get the other entry that we were waiting on
997 EXPECT_EQ(verif.Next(cq_.get(), ignore_cq_result), tag_idx);
998 }
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -0800999 }
1000
1001 if (server_try_cancel_thd != NULL) {
1002 server_try_cancel_thd->join();
1003 delete server_try_cancel_thd;
1004 }
1005
1006 if (server_try_cancel == CANCEL_AFTER_PROCESSING) {
Sree Kuchibhotlab0d15672016-03-07 10:51:02 -08001007 srv_ctx.TryCancel();
1008 want_done_tag = true;
1009 verif.Expect(11, true);
1010 }
1011
1012 if (want_done_tag) {
1013 verif.Verify(cq_.get());
1014 EXPECT_TRUE(srv_ctx.IsCancelled());
1015 want_done_tag = false;
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001016 }
1017
Sree Kuchibhotla0f242ac2016-01-29 18:12:19 -08001018 // The RPC has been cancelled at this point for sure (i.e irrespective of
1019 // the value of `server_try_cancel` is). So, from this point forward, we
1020 // know that cq results are supposed to return false on server.
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001021
Sree Kuchibhotla0f242ac2016-01-29 18:12:19 -08001022 // Server sends the final message and cancelled status (but the RPC is
1023 // already cancelled at this point. So we expect the operation to fail)
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001024 srv_stream.Finish(send_response, Status::CANCELLED, tag(9));
Vijay Paidf8b62c2016-05-02 14:34:24 -07001025 Verifier(GetParam().disable_blocking).Expect(9, false).Verify(cq_.get());
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001026
Sree Kuchibhotla0f242ac2016-01-29 18:12:19 -08001027 // Client will see the cancellation
Sree Kuchibhotla944f4cf2016-01-27 14:37:26 -08001028 cli_stream->Finish(&recv_status, tag(10));
yang-g15759f62016-06-01 11:21:27 -07001029 Verifier(GetParam().disable_blocking).Expect(10, true).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}