Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
Craig Tiller | 6169d5f | 2016-03-31 07:46:18 -0700 | [diff] [blame^] | 3 | * Copyright 2015, Google Inc. |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 4 | * 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 Gao | da699b8 | 2015-02-18 01:10:22 -0800 | [diff] [blame] | 34 | #include <memory> |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 35 | #include <thread> |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 36 | |
yang-g | 8c2be9f | 2015-08-19 16:28:09 -0700 | [diff] [blame] | 37 | #include <grpc++/channel.h> |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 38 | #include <grpc++/client_context.h> |
| 39 | #include <grpc++/create_channel.h> |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 40 | #include <grpc++/server.h> |
| 41 | #include <grpc++/server_builder.h> |
| 42 | #include <grpc++/server_context.h> |
Sree Kuchibhotla | b0d0c8e | 2016-01-13 22:52:17 -0800 | [diff] [blame] | 43 | #include <grpc/grpc.h> |
| 44 | #include <grpc/support/thd.h> |
| 45 | #include <grpc/support/time.h> |
Vijay Pai | b65eda4 | 2016-02-16 13:48:05 -0800 | [diff] [blame] | 46 | #include <grpc/support/tls.h> |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 47 | #include <gtest/gtest.h> |
| 48 | |
Craig Tiller | 1b4e330 | 2015-12-17 16:35:00 -0800 | [diff] [blame] | 49 | #include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h" |
| 50 | #include "src/proto/grpc/testing/echo.grpc.pb.h" |
Sree Kuchibhotla | b0d0c8e | 2016-01-13 22:52:17 -0800 | [diff] [blame] | 51 | #include "test/core/util/port.h" |
| 52 | #include "test/core/util/test_config.h" |
yang-g | e21908f | 2015-08-25 13:47:51 -0700 | [diff] [blame] | 53 | #include "test/cpp/util/string_ref_helper.h" |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 54 | |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 55 | #ifdef GPR_POSIX_SOCKET |
Craig Tiller | 9533d04 | 2016-03-25 17:11:06 -0700 | [diff] [blame] | 56 | #include "src/core/lib/iomgr/pollset_posix.h" |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 57 | #endif |
| 58 | |
Craig Tiller | 1b4e330 | 2015-12-17 16:35:00 -0800 | [diff] [blame] | 59 | using grpc::testing::EchoRequest; |
| 60 | using grpc::testing::EchoResponse; |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 61 | using std::chrono::system_clock; |
| 62 | |
Vijay Pai | b65eda4 | 2016-02-16 13:48:05 -0800 | [diff] [blame] | 63 | GPR_TLS_DECL(g_is_async_end2end_test); |
| 64 | |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 65 | namespace grpc { |
| 66 | namespace testing { |
| 67 | |
| 68 | namespace { |
| 69 | |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 70 | void* tag(int i) { return (void*)(intptr_t)i; } |
Sree Kuchibhotla | b0d1567 | 2016-03-07 10:51:02 -0800 | [diff] [blame] | 71 | int detag(void* p) { return static_cast<int>(reinterpret_cast<intptr_t>(p)); } |
Yang Gao | c05b6cb | 2015-02-13 00:34:10 -0800 | [diff] [blame] | 72 | |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 73 | #ifdef GPR_POSIX_SOCKET |
Vijay Pai | b65eda4 | 2016-02-16 13:48:05 -0800 | [diff] [blame] | 74 | static int maybe_assert_non_blocking_poll(struct pollfd* pfds, nfds_t nfds, |
| 75 | int timeout) { |
| 76 | if (gpr_tls_get(&g_is_async_end2end_test)) { |
| 77 | GPR_ASSERT(timeout == 0); |
| 78 | } |
| 79 | return poll(pfds, nfds, timeout); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | class PollOverride { |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 83 | public: |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 84 | PollOverride(grpc_poll_function_type f) { |
| 85 | prev_ = grpc_poll_function; |
| 86 | grpc_poll_function = f; |
| 87 | } |
| 88 | |
Craig Tiller | 4c06b82 | 2015-08-06 08:41:31 -0700 | [diff] [blame] | 89 | ~PollOverride() { grpc_poll_function = prev_; } |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 90 | |
| 91 | private: |
| 92 | grpc_poll_function_type prev_; |
| 93 | }; |
| 94 | |
vjpai | cf4daeb | 2016-02-15 02:33:54 -0800 | [diff] [blame] | 95 | class PollingOverrider : public PollOverride { |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 96 | public: |
vjpai | cf4daeb | 2016-02-15 02:33:54 -0800 | [diff] [blame] | 97 | explicit PollingOverrider(bool allow_blocking) |
Vijay Pai | b65eda4 | 2016-02-16 13:48:05 -0800 | [diff] [blame] | 98 | : PollOverride(allow_blocking ? poll : maybe_assert_non_blocking_poll) {} |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 99 | }; |
| 100 | #else |
vjpai | cf4daeb | 2016-02-15 02:33:54 -0800 | [diff] [blame] | 101 | class PollingOverrider { |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 102 | public: |
vjpai | cf4daeb | 2016-02-15 02:33:54 -0800 | [diff] [blame] | 103 | explicit PollingOverrider(bool allow_blocking) {} |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 104 | }; |
| 105 | #endif |
| 106 | |
vjpai | cf4daeb | 2016-02-15 02:33:54 -0800 | [diff] [blame] | 107 | class Verifier { |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 108 | public: |
vjpai | cf4daeb | 2016-02-15 02:33:54 -0800 | [diff] [blame] | 109 | explicit Verifier(bool spin) : spin_(spin) {} |
Sree Kuchibhotla | b0d1567 | 2016-03-07 10:51:02 -0800 | [diff] [blame] | 110 | // Expect sets the expected ok value for a specific tag |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 111 | Verifier& Expect(int i, bool expect_ok) { |
| 112 | expectations_[tag(i)] = expect_ok; |
| 113 | return *this; |
vjpai | 7aadf46 | 2015-03-16 23:58:44 -0700 | [diff] [blame] | 114 | } |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 115 | |
Sree Kuchibhotla | b0d1567 | 2016-03-07 10:51:02 -0800 | [diff] [blame] | 116 | // Next waits for 1 async tag to complete, checks its |
| 117 | // expectations, and returns the tag |
| 118 | int Next(CompletionQueue* cq, bool ignore_ok) { |
| 119 | bool ok; |
| 120 | void* got_tag; |
| 121 | if (spin_) { |
| 122 | for (;;) { |
| 123 | auto r = cq->AsyncNext(&got_tag, &ok, gpr_time_0(GPR_CLOCK_REALTIME)); |
| 124 | if (r == CompletionQueue::TIMEOUT) continue; |
| 125 | if (r == CompletionQueue::GOT_EVENT) break; |
| 126 | gpr_log(GPR_ERROR, "unexpected result from AsyncNext"); |
| 127 | abort(); |
| 128 | } |
| 129 | } else { |
| 130 | EXPECT_TRUE(cq->Next(&got_tag, &ok)); |
| 131 | } |
| 132 | auto it = expectations_.find(got_tag); |
| 133 | EXPECT_TRUE(it != expectations_.end()); |
| 134 | if (!ignore_ok) { |
| 135 | EXPECT_EQ(it->second, ok); |
| 136 | } |
| 137 | expectations_.erase(it); |
| 138 | return detag(got_tag); |
| 139 | } |
| 140 | |
| 141 | // Verify keeps calling Next until all currently set |
| 142 | // expected tags are complete |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 143 | void Verify(CompletionQueue* cq) { Verify(cq, false); } |
| 144 | |
Sree Kuchibhotla | b0d1567 | 2016-03-07 10:51:02 -0800 | [diff] [blame] | 145 | // This version of Verify allows optionally ignoring the |
| 146 | // outcome of the expectation |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 147 | void Verify(CompletionQueue* cq, bool ignore_ok) { |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 148 | GPR_ASSERT(!expectations_.empty()); |
| 149 | while (!expectations_.empty()) { |
Sree Kuchibhotla | b0d1567 | 2016-03-07 10:51:02 -0800 | [diff] [blame] | 150 | Next(cq, ignore_ok); |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 151 | } |
| 152 | } |
Sree Kuchibhotla | b0d1567 | 2016-03-07 10:51:02 -0800 | [diff] [blame] | 153 | // This version of Verify stops after a certain deadline |
Craig Tiller | d6c98df | 2015-08-18 09:33:44 -0700 | [diff] [blame] | 154 | void Verify(CompletionQueue* cq, |
| 155 | std::chrono::system_clock::time_point deadline) { |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 156 | if (expectations_.empty()) { |
| 157 | bool ok; |
Craig Tiller | d6c98df | 2015-08-18 09:33:44 -0700 | [diff] [blame] | 158 | void* got_tag; |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 159 | if (spin_) { |
| 160 | while (std::chrono::system_clock::now() < deadline) { |
Craig Tiller | 4c06b82 | 2015-08-06 08:41:31 -0700 | [diff] [blame] | 161 | EXPECT_EQ( |
| 162 | cq->AsyncNext(&got_tag, &ok, gpr_time_0(GPR_CLOCK_REALTIME)), |
| 163 | CompletionQueue::TIMEOUT); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 164 | } |
| 165 | } else { |
Craig Tiller | 4c06b82 | 2015-08-06 08:41:31 -0700 | [diff] [blame] | 166 | EXPECT_EQ(cq->AsyncNext(&got_tag, &ok, deadline), |
| 167 | CompletionQueue::TIMEOUT); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 168 | } |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 169 | } else { |
| 170 | while (!expectations_.empty()) { |
| 171 | bool ok; |
Craig Tiller | d6c98df | 2015-08-18 09:33:44 -0700 | [diff] [blame] | 172 | void* got_tag; |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 173 | if (spin_) { |
| 174 | for (;;) { |
| 175 | GPR_ASSERT(std::chrono::system_clock::now() < deadline); |
Craig Tiller | 4c06b82 | 2015-08-06 08:41:31 -0700 | [diff] [blame] | 176 | auto r = |
| 177 | cq->AsyncNext(&got_tag, &ok, gpr_time_0(GPR_CLOCK_REALTIME)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 178 | if (r == CompletionQueue::TIMEOUT) continue; |
| 179 | if (r == CompletionQueue::GOT_EVENT) break; |
| 180 | gpr_log(GPR_ERROR, "unexpected result from AsyncNext"); |
| 181 | abort(); |
Craig Tiller | 4c06b82 | 2015-08-06 08:41:31 -0700 | [diff] [blame] | 182 | } |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 183 | } else { |
Craig Tiller | 4c06b82 | 2015-08-06 08:41:31 -0700 | [diff] [blame] | 184 | EXPECT_EQ(cq->AsyncNext(&got_tag, &ok, deadline), |
| 185 | CompletionQueue::GOT_EVENT); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 186 | } |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 187 | auto it = expectations_.find(got_tag); |
| 188 | EXPECT_TRUE(it != expectations_.end()); |
| 189 | EXPECT_EQ(it->second, ok); |
| 190 | expectations_.erase(it); |
| 191 | } |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | private: |
| 196 | std::map<void*, bool> expectations_; |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 197 | bool spin_; |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 198 | }; |
vjpai | 7aadf46 | 2015-03-16 23:58:44 -0700 | [diff] [blame] | 199 | |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 200 | class AsyncEnd2endTest : public ::testing::TestWithParam<bool> { |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 201 | protected: |
Vijay Pai | 018879a | 2016-02-16 09:20:50 -0800 | [diff] [blame] | 202 | AsyncEnd2endTest() {} |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 203 | |
Craig Tiller | cf133f4 | 2015-02-26 14:05:56 -0800 | [diff] [blame] | 204 | void SetUp() GRPC_OVERRIDE { |
Vijay Pai | 018879a | 2016-02-16 09:20:50 -0800 | [diff] [blame] | 205 | poll_overrider_.reset(new PollingOverrider(!GetParam())); |
| 206 | |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 207 | int port = grpc_pick_unused_port_or_die(); |
| 208 | server_address_ << "localhost:" << port; |
vjpai | 017ed62 | 2015-12-09 10:42:54 -0800 | [diff] [blame] | 209 | |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 210 | // Setup server |
| 211 | ServerBuilder builder; |
Craig Tiller | d6c98df | 2015-08-18 09:33:44 -0700 | [diff] [blame] | 212 | builder.AddListeningPort(server_address_.str(), |
| 213 | grpc::InsecureServerCredentials()); |
Craig Tiller | 15f383c | 2016-01-07 12:45:32 -0800 | [diff] [blame] | 214 | builder.RegisterService(&service_); |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 215 | cq_ = builder.AddCompletionQueue(); |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 216 | server_ = builder.BuildAndStart(); |
Vijay Pai | b65eda4 | 2016-02-16 13:48:05 -0800 | [diff] [blame] | 217 | |
| 218 | gpr_tls_set(&g_is_async_end2end_test, 1); |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 219 | } |
| 220 | |
Craig Tiller | cf133f4 | 2015-02-26 14:05:56 -0800 | [diff] [blame] | 221 | void TearDown() GRPC_OVERRIDE { |
Craig Tiller | 492968f | 2015-02-18 13:14:03 -0800 | [diff] [blame] | 222 | server_->Shutdown(); |
| 223 | void* ignored_tag; |
| 224 | bool ignored_ok; |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 225 | cq_->Shutdown(); |
| 226 | while (cq_->Next(&ignored_tag, &ignored_ok)) |
Craig Tiller | 492968f | 2015-02-18 13:14:03 -0800 | [diff] [blame] | 227 | ; |
Vijay Pai | 018879a | 2016-02-16 09:20:50 -0800 | [diff] [blame] | 228 | poll_overrider_.reset(); |
Vijay Pai | b65eda4 | 2016-02-16 13:48:05 -0800 | [diff] [blame] | 229 | gpr_tls_set(&g_is_async_end2end_test, 0); |
Craig Tiller | 492968f | 2015-02-18 13:14:03 -0800 | [diff] [blame] | 230 | } |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 231 | |
| 232 | void ResetStub() { |
yang-g | 730055d | 2015-08-27 12:29:45 -0700 | [diff] [blame] | 233 | std::shared_ptr<Channel> channel = |
Julien Boeuf | e5adc0e | 2015-10-12 14:08:10 -0700 | [diff] [blame] | 234 | CreateChannel(server_address_.str(), InsecureChannelCredentials()); |
Sree Kuchibhotla | 5a05f51 | 2016-01-13 22:43:20 -0800 | [diff] [blame] | 235 | stub_ = grpc::testing::EchoTestService::NewStub(channel); |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 236 | } |
| 237 | |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 238 | void SendRpc(int num_rpcs) { |
| 239 | for (int i = 0; i < num_rpcs; i++) { |
| 240 | EchoRequest send_request; |
| 241 | EchoRequest recv_request; |
| 242 | EchoResponse send_response; |
| 243 | EchoResponse recv_response; |
| 244 | Status recv_status; |
| 245 | |
| 246 | ClientContext cli_ctx; |
| 247 | ServerContext srv_ctx; |
| 248 | grpc::ServerAsyncResponseWriter<EchoResponse> response_writer(&srv_ctx); |
| 249 | |
| 250 | send_request.set_message("Hello"); |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 251 | std::unique_ptr<ClientAsyncResponseReader<EchoResponse>> response_reader( |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 252 | stub_->AsyncEcho(&cli_ctx, send_request, cq_.get())); |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 253 | |
Craig Tiller | d6c98df | 2015-08-18 09:33:44 -0700 | [diff] [blame] | 254 | service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, cq_.get(), |
| 255 | cq_.get(), tag(2)); |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 256 | |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 257 | Verifier(GetParam()).Expect(2, true).Verify(cq_.get()); |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 258 | EXPECT_EQ(send_request.message(), recv_request.message()); |
| 259 | |
| 260 | send_response.set_message(recv_request.message()); |
| 261 | response_writer.Finish(send_response, Status::OK, tag(3)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 262 | Verifier(GetParam()).Expect(3, true).Verify(cq_.get()); |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 263 | |
Yang Gao | 3a5e549 | 2015-02-18 14:32:38 -0800 | [diff] [blame] | 264 | response_reader->Finish(&recv_response, &recv_status, tag(4)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 265 | Verifier(GetParam()).Expect(4, true).Verify(cq_.get()); |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 266 | |
| 267 | EXPECT_EQ(send_response.message(), recv_response.message()); |
Yang Gao | c1a2c31 | 2015-06-16 10:59:46 -0700 | [diff] [blame] | 268 | EXPECT_TRUE(recv_status.ok()); |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 269 | } |
| 270 | } |
| 271 | |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 272 | std::unique_ptr<ServerCompletionQueue> cq_; |
Sree Kuchibhotla | 5a05f51 | 2016-01-13 22:43:20 -0800 | [diff] [blame] | 273 | std::unique_ptr<grpc::testing::EchoTestService::Stub> stub_; |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 274 | std::unique_ptr<Server> server_; |
Sree Kuchibhotla | 5a05f51 | 2016-01-13 22:43:20 -0800 | [diff] [blame] | 275 | grpc::testing::EchoTestService::AsyncService service_; |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 276 | std::ostringstream server_address_; |
vjpai | cf4daeb | 2016-02-15 02:33:54 -0800 | [diff] [blame] | 277 | |
Vijay Pai | 018879a | 2016-02-16 09:20:50 -0800 | [diff] [blame] | 278 | std::unique_ptr<PollingOverrider> poll_overrider_; |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 279 | }; |
| 280 | |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 281 | TEST_P(AsyncEnd2endTest, SimpleRpc) { |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 282 | ResetStub(); |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 283 | SendRpc(1); |
| 284 | } |
Yang Gao | bb84a30 | 2015-02-12 23:30:12 -0800 | [diff] [blame] | 285 | |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 286 | TEST_P(AsyncEnd2endTest, SequentialRpcs) { |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 287 | ResetStub(); |
| 288 | SendRpc(10); |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 289 | } |
| 290 | |
vjpai | 7aadf46 | 2015-03-16 23:58:44 -0700 | [diff] [blame] | 291 | // Test a simple RPC using the async version of Next |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 292 | TEST_P(AsyncEnd2endTest, AsyncNextRpc) { |
vjpai | 7aadf46 | 2015-03-16 23:58:44 -0700 | [diff] [blame] | 293 | ResetStub(); |
| 294 | |
| 295 | EchoRequest send_request; |
| 296 | EchoRequest recv_request; |
| 297 | EchoResponse send_response; |
| 298 | EchoResponse recv_response; |
| 299 | Status recv_status; |
| 300 | |
| 301 | ClientContext cli_ctx; |
| 302 | ServerContext srv_ctx; |
| 303 | grpc::ServerAsyncResponseWriter<EchoResponse> response_writer(&srv_ctx); |
| 304 | |
| 305 | send_request.set_message("Hello"); |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 306 | std::unique_ptr<ClientAsyncResponseReader<EchoResponse>> response_reader( |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 307 | stub_->AsyncEcho(&cli_ctx, send_request, cq_.get())); |
vjpai | 7aadf46 | 2015-03-16 23:58:44 -0700 | [diff] [blame] | 308 | |
Yang Gao | 757afae | 2015-03-17 15:49:26 -0700 | [diff] [blame] | 309 | std::chrono::system_clock::time_point time_now( |
Craig Tiller | f51199f | 2015-05-08 09:32:53 -0700 | [diff] [blame] | 310 | std::chrono::system_clock::now()); |
| 311 | std::chrono::system_clock::time_point time_limit( |
| 312 | std::chrono::system_clock::now() + std::chrono::seconds(10)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 313 | Verifier(GetParam()).Verify(cq_.get(), time_now); |
| 314 | Verifier(GetParam()).Verify(cq_.get(), time_now); |
vjpai | 7aadf46 | 2015-03-16 23:58:44 -0700 | [diff] [blame] | 315 | |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 316 | service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, cq_.get(), |
| 317 | cq_.get(), tag(2)); |
vjpai | 7aadf46 | 2015-03-16 23:58:44 -0700 | [diff] [blame] | 318 | |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 319 | Verifier(GetParam()).Expect(2, true).Verify(cq_.get(), time_limit); |
vjpai | 7aadf46 | 2015-03-16 23:58:44 -0700 | [diff] [blame] | 320 | EXPECT_EQ(send_request.message(), recv_request.message()); |
vjpai | 7aadf46 | 2015-03-16 23:58:44 -0700 | [diff] [blame] | 321 | |
| 322 | send_response.set_message(recv_request.message()); |
| 323 | response_writer.Finish(send_response, Status::OK, tag(3)); |
Craig Tiller | 4c06b82 | 2015-08-06 08:41:31 -0700 | [diff] [blame] | 324 | Verifier(GetParam()) |
| 325 | .Expect(3, true) |
| 326 | .Verify(cq_.get(), std::chrono::system_clock::time_point::max()); |
vjpai | 7aadf46 | 2015-03-16 23:58:44 -0700 | [diff] [blame] | 327 | |
| 328 | response_reader->Finish(&recv_response, &recv_status, tag(4)); |
Craig Tiller | 4c06b82 | 2015-08-06 08:41:31 -0700 | [diff] [blame] | 329 | Verifier(GetParam()) |
| 330 | .Expect(4, true) |
| 331 | .Verify(cq_.get(), std::chrono::system_clock::time_point::max()); |
vjpai | 7aadf46 | 2015-03-16 23:58:44 -0700 | [diff] [blame] | 332 | |
| 333 | EXPECT_EQ(send_response.message(), recv_response.message()); |
Yang Gao | c1a2c31 | 2015-06-16 10:59:46 -0700 | [diff] [blame] | 334 | EXPECT_TRUE(recv_status.ok()); |
vjpai | 7aadf46 | 2015-03-16 23:58:44 -0700 | [diff] [blame] | 335 | } |
Yang Gao | 757afae | 2015-03-17 15:49:26 -0700 | [diff] [blame] | 336 | |
Yang Gao | 0e0d8e1 | 2015-02-13 14:40:41 -0800 | [diff] [blame] | 337 | // Two pings and a final pong. |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 338 | TEST_P(AsyncEnd2endTest, SimpleClientStreaming) { |
Yang Gao | 005f18a | 2015-02-13 10:22:33 -0800 | [diff] [blame] | 339 | ResetStub(); |
| 340 | |
| 341 | EchoRequest send_request; |
| 342 | EchoRequest recv_request; |
| 343 | EchoResponse send_response; |
| 344 | EchoResponse recv_response; |
| 345 | Status recv_status; |
| 346 | ClientContext cli_ctx; |
| 347 | ServerContext srv_ctx; |
| 348 | ServerAsyncReader<EchoResponse, EchoRequest> srv_stream(&srv_ctx); |
| 349 | |
| 350 | send_request.set_message("Hello"); |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 351 | std::unique_ptr<ClientAsyncWriter<EchoRequest>> cli_stream( |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 352 | stub_->AsyncRequestStream(&cli_ctx, &recv_response, cq_.get(), tag(1))); |
Yang Gao | 005f18a | 2015-02-13 10:22:33 -0800 | [diff] [blame] | 353 | |
Craig Tiller | d6c98df | 2015-08-18 09:33:44 -0700 | [diff] [blame] | 354 | service_.RequestRequestStream(&srv_ctx, &srv_stream, cq_.get(), cq_.get(), |
| 355 | tag(2)); |
Yang Gao | 005f18a | 2015-02-13 10:22:33 -0800 | [diff] [blame] | 356 | |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 357 | Verifier(GetParam()).Expect(2, true).Expect(1, true).Verify(cq_.get()); |
Yang Gao | 005f18a | 2015-02-13 10:22:33 -0800 | [diff] [blame] | 358 | |
| 359 | cli_stream->Write(send_request, tag(3)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 360 | Verifier(GetParam()).Expect(3, true).Verify(cq_.get()); |
Yang Gao | 005f18a | 2015-02-13 10:22:33 -0800 | [diff] [blame] | 361 | |
| 362 | srv_stream.Read(&recv_request, tag(4)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 363 | Verifier(GetParam()).Expect(4, true).Verify(cq_.get()); |
Yang Gao | 005f18a | 2015-02-13 10:22:33 -0800 | [diff] [blame] | 364 | EXPECT_EQ(send_request.message(), recv_request.message()); |
| 365 | |
| 366 | cli_stream->Write(send_request, tag(5)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 367 | Verifier(GetParam()).Expect(5, true).Verify(cq_.get()); |
Yang Gao | 005f18a | 2015-02-13 10:22:33 -0800 | [diff] [blame] | 368 | |
| 369 | srv_stream.Read(&recv_request, tag(6)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 370 | Verifier(GetParam()).Expect(6, true).Verify(cq_.get()); |
Yang Gao | 005f18a | 2015-02-13 10:22:33 -0800 | [diff] [blame] | 371 | |
| 372 | EXPECT_EQ(send_request.message(), recv_request.message()); |
| 373 | cli_stream->WritesDone(tag(7)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 374 | Verifier(GetParam()).Expect(7, true).Verify(cq_.get()); |
Yang Gao | 005f18a | 2015-02-13 10:22:33 -0800 | [diff] [blame] | 375 | |
| 376 | srv_stream.Read(&recv_request, tag(8)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 377 | Verifier(GetParam()).Expect(8, false).Verify(cq_.get()); |
Yang Gao | 005f18a | 2015-02-13 10:22:33 -0800 | [diff] [blame] | 378 | |
| 379 | send_response.set_message(recv_request.message()); |
| 380 | srv_stream.Finish(send_response, Status::OK, tag(9)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 381 | Verifier(GetParam()).Expect(9, true).Verify(cq_.get()); |
Yang Gao | 005f18a | 2015-02-13 10:22:33 -0800 | [diff] [blame] | 382 | |
| 383 | cli_stream->Finish(&recv_status, tag(10)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 384 | Verifier(GetParam()).Expect(10, true).Verify(cq_.get()); |
Yang Gao | 005f18a | 2015-02-13 10:22:33 -0800 | [diff] [blame] | 385 | |
| 386 | EXPECT_EQ(send_response.message(), recv_response.message()); |
Yang Gao | c1a2c31 | 2015-06-16 10:59:46 -0700 | [diff] [blame] | 387 | EXPECT_TRUE(recv_status.ok()); |
Yang Gao | 005f18a | 2015-02-13 10:22:33 -0800 | [diff] [blame] | 388 | } |
| 389 | |
Yang Gao | 0e0d8e1 | 2015-02-13 14:40:41 -0800 | [diff] [blame] | 390 | // One ping, two pongs. |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 391 | TEST_P(AsyncEnd2endTest, SimpleServerStreaming) { |
Yang Gao | 0e0d8e1 | 2015-02-13 14:40:41 -0800 | [diff] [blame] | 392 | ResetStub(); |
| 393 | |
| 394 | EchoRequest send_request; |
| 395 | EchoRequest recv_request; |
| 396 | EchoResponse send_response; |
| 397 | EchoResponse recv_response; |
| 398 | Status recv_status; |
| 399 | ClientContext cli_ctx; |
| 400 | ServerContext srv_ctx; |
| 401 | ServerAsyncWriter<EchoResponse> srv_stream(&srv_ctx); |
| 402 | |
| 403 | send_request.set_message("Hello"); |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 404 | std::unique_ptr<ClientAsyncReader<EchoResponse>> cli_stream( |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 405 | stub_->AsyncResponseStream(&cli_ctx, send_request, cq_.get(), tag(1))); |
Yang Gao | 0e0d8e1 | 2015-02-13 14:40:41 -0800 | [diff] [blame] | 406 | |
Craig Tiller | f9e6adf | 2015-05-06 11:45:59 -0700 | [diff] [blame] | 407 | service_.RequestResponseStream(&srv_ctx, &recv_request, &srv_stream, |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 408 | cq_.get(), cq_.get(), tag(2)); |
Yang Gao | 0e0d8e1 | 2015-02-13 14:40:41 -0800 | [diff] [blame] | 409 | |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 410 | Verifier(GetParam()).Expect(1, true).Expect(2, true).Verify(cq_.get()); |
Yang Gao | 0e0d8e1 | 2015-02-13 14:40:41 -0800 | [diff] [blame] | 411 | EXPECT_EQ(send_request.message(), recv_request.message()); |
| 412 | |
| 413 | send_response.set_message(recv_request.message()); |
| 414 | srv_stream.Write(send_response, tag(3)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 415 | Verifier(GetParam()).Expect(3, true).Verify(cq_.get()); |
Yang Gao | 0e0d8e1 | 2015-02-13 14:40:41 -0800 | [diff] [blame] | 416 | |
| 417 | cli_stream->Read(&recv_response, tag(4)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 418 | Verifier(GetParam()).Expect(4, true).Verify(cq_.get()); |
Yang Gao | 0e0d8e1 | 2015-02-13 14:40:41 -0800 | [diff] [blame] | 419 | EXPECT_EQ(send_response.message(), recv_response.message()); |
| 420 | |
| 421 | srv_stream.Write(send_response, tag(5)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 422 | Verifier(GetParam()).Expect(5, true).Verify(cq_.get()); |
Yang Gao | 0e0d8e1 | 2015-02-13 14:40:41 -0800 | [diff] [blame] | 423 | |
| 424 | cli_stream->Read(&recv_response, tag(6)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 425 | Verifier(GetParam()).Expect(6, true).Verify(cq_.get()); |
Yang Gao | 0e0d8e1 | 2015-02-13 14:40:41 -0800 | [diff] [blame] | 426 | EXPECT_EQ(send_response.message(), recv_response.message()); |
| 427 | |
| 428 | srv_stream.Finish(Status::OK, tag(7)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 429 | Verifier(GetParam()).Expect(7, true).Verify(cq_.get()); |
Yang Gao | 0e0d8e1 | 2015-02-13 14:40:41 -0800 | [diff] [blame] | 430 | |
| 431 | cli_stream->Read(&recv_response, tag(8)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 432 | Verifier(GetParam()).Expect(8, false).Verify(cq_.get()); |
Yang Gao | 0e0d8e1 | 2015-02-13 14:40:41 -0800 | [diff] [blame] | 433 | |
| 434 | cli_stream->Finish(&recv_status, tag(9)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 435 | Verifier(GetParam()).Expect(9, true).Verify(cq_.get()); |
Yang Gao | 0e0d8e1 | 2015-02-13 14:40:41 -0800 | [diff] [blame] | 436 | |
Yang Gao | c1a2c31 | 2015-06-16 10:59:46 -0700 | [diff] [blame] | 437 | EXPECT_TRUE(recv_status.ok()); |
Yang Gao | 0e0d8e1 | 2015-02-13 14:40:41 -0800 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | // One ping, one pong. |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 441 | TEST_P(AsyncEnd2endTest, SimpleBidiStreaming) { |
Yang Gao | c05b6cb | 2015-02-13 00:34:10 -0800 | [diff] [blame] | 442 | ResetStub(); |
| 443 | |
| 444 | EchoRequest send_request; |
| 445 | EchoRequest recv_request; |
| 446 | EchoResponse send_response; |
| 447 | EchoResponse recv_response; |
| 448 | Status recv_status; |
| 449 | ClientContext cli_ctx; |
| 450 | ServerContext srv_ctx; |
| 451 | ServerAsyncReaderWriter<EchoResponse, EchoRequest> srv_stream(&srv_ctx); |
| 452 | |
| 453 | send_request.set_message("Hello"); |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 454 | std::unique_ptr<ClientAsyncReaderWriter<EchoRequest, EchoResponse>> |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 455 | cli_stream(stub_->AsyncBidiStream(&cli_ctx, cq_.get(), tag(1))); |
Yang Gao | c05b6cb | 2015-02-13 00:34:10 -0800 | [diff] [blame] | 456 | |
Craig Tiller | d6c98df | 2015-08-18 09:33:44 -0700 | [diff] [blame] | 457 | service_.RequestBidiStream(&srv_ctx, &srv_stream, cq_.get(), cq_.get(), |
| 458 | tag(2)); |
Yang Gao | c05b6cb | 2015-02-13 00:34:10 -0800 | [diff] [blame] | 459 | |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 460 | Verifier(GetParam()).Expect(1, true).Expect(2, true).Verify(cq_.get()); |
Yang Gao | c05b6cb | 2015-02-13 00:34:10 -0800 | [diff] [blame] | 461 | |
| 462 | cli_stream->Write(send_request, tag(3)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 463 | Verifier(GetParam()).Expect(3, true).Verify(cq_.get()); |
Yang Gao | c05b6cb | 2015-02-13 00:34:10 -0800 | [diff] [blame] | 464 | |
| 465 | srv_stream.Read(&recv_request, tag(4)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 466 | Verifier(GetParam()).Expect(4, true).Verify(cq_.get()); |
Yang Gao | c05b6cb | 2015-02-13 00:34:10 -0800 | [diff] [blame] | 467 | EXPECT_EQ(send_request.message(), recv_request.message()); |
| 468 | |
| 469 | send_response.set_message(recv_request.message()); |
| 470 | srv_stream.Write(send_response, tag(5)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 471 | Verifier(GetParam()).Expect(5, true).Verify(cq_.get()); |
Yang Gao | c05b6cb | 2015-02-13 00:34:10 -0800 | [diff] [blame] | 472 | |
| 473 | cli_stream->Read(&recv_response, tag(6)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 474 | Verifier(GetParam()).Expect(6, true).Verify(cq_.get()); |
Yang Gao | c05b6cb | 2015-02-13 00:34:10 -0800 | [diff] [blame] | 475 | EXPECT_EQ(send_response.message(), recv_response.message()); |
| 476 | |
| 477 | cli_stream->WritesDone(tag(7)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 478 | Verifier(GetParam()).Expect(7, true).Verify(cq_.get()); |
Yang Gao | c05b6cb | 2015-02-13 00:34:10 -0800 | [diff] [blame] | 479 | |
| 480 | srv_stream.Read(&recv_request, tag(8)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 481 | Verifier(GetParam()).Expect(8, false).Verify(cq_.get()); |
Yang Gao | c05b6cb | 2015-02-13 00:34:10 -0800 | [diff] [blame] | 482 | |
| 483 | srv_stream.Finish(Status::OK, tag(9)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 484 | Verifier(GetParam()).Expect(9, true).Verify(cq_.get()); |
Yang Gao | c05b6cb | 2015-02-13 00:34:10 -0800 | [diff] [blame] | 485 | |
| 486 | cli_stream->Finish(&recv_status, tag(10)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 487 | Verifier(GetParam()).Expect(10, true).Verify(cq_.get()); |
Yang Gao | c05b6cb | 2015-02-13 00:34:10 -0800 | [diff] [blame] | 488 | |
Yang Gao | c1a2c31 | 2015-06-16 10:59:46 -0700 | [diff] [blame] | 489 | EXPECT_TRUE(recv_status.ok()); |
Yang Gao | c05b6cb | 2015-02-13 00:34:10 -0800 | [diff] [blame] | 490 | } |
| 491 | |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 492 | // Metadata tests |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 493 | TEST_P(AsyncEnd2endTest, ClientInitialMetadataRpc) { |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 494 | ResetStub(); |
| 495 | |
| 496 | EchoRequest send_request; |
| 497 | EchoRequest recv_request; |
| 498 | EchoResponse send_response; |
| 499 | EchoResponse recv_response; |
| 500 | Status recv_status; |
| 501 | |
| 502 | ClientContext cli_ctx; |
| 503 | ServerContext srv_ctx; |
| 504 | grpc::ServerAsyncResponseWriter<EchoResponse> response_writer(&srv_ctx); |
| 505 | |
| 506 | send_request.set_message("Hello"); |
| 507 | std::pair<grpc::string, grpc::string> meta1("key1", "val1"); |
| 508 | std::pair<grpc::string, grpc::string> meta2("key2", "val2"); |
Craig Tiller | 6f87164 | 2016-02-03 16:15:31 -0800 | [diff] [blame] | 509 | std::pair<grpc::string, grpc::string> meta3("g.r.d-bin", "xyz"); |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 510 | cli_ctx.AddMetadata(meta1.first, meta1.second); |
| 511 | cli_ctx.AddMetadata(meta2.first, meta2.second); |
Craig Tiller | 6f87164 | 2016-02-03 16:15:31 -0800 | [diff] [blame] | 512 | cli_ctx.AddMetadata(meta3.first, meta3.second); |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 513 | |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 514 | std::unique_ptr<ClientAsyncResponseReader<EchoResponse>> response_reader( |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 515 | stub_->AsyncEcho(&cli_ctx, send_request, cq_.get())); |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 516 | |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 517 | service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, cq_.get(), |
| 518 | cq_.get(), tag(2)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 519 | Verifier(GetParam()).Expect(2, true).Verify(cq_.get()); |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 520 | EXPECT_EQ(send_request.message(), recv_request.message()); |
| 521 | auto client_initial_metadata = srv_ctx.client_metadata(); |
yang-g | e21908f | 2015-08-25 13:47:51 -0700 | [diff] [blame] | 522 | EXPECT_EQ(meta1.second, |
| 523 | ToString(client_initial_metadata.find(meta1.first)->second)); |
| 524 | EXPECT_EQ(meta2.second, |
| 525 | ToString(client_initial_metadata.find(meta2.first)->second)); |
Craig Tiller | 6f87164 | 2016-02-03 16:15:31 -0800 | [diff] [blame] | 526 | EXPECT_EQ(meta3.second, |
| 527 | ToString(client_initial_metadata.find(meta3.first)->second)); |
Craig Tiller | 8bf2dca | 2015-07-10 13:08:41 -0700 | [diff] [blame] | 528 | EXPECT_GE(client_initial_metadata.size(), static_cast<size_t>(2)); |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 529 | |
| 530 | send_response.set_message(recv_request.message()); |
| 531 | response_writer.Finish(send_response, Status::OK, tag(3)); |
| 532 | |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 533 | Verifier(GetParam()).Expect(3, true).Verify(cq_.get()); |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 534 | |
Yang Gao | 3a5e549 | 2015-02-18 14:32:38 -0800 | [diff] [blame] | 535 | response_reader->Finish(&recv_response, &recv_status, tag(4)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 536 | Verifier(GetParam()).Expect(4, true).Verify(cq_.get()); |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 537 | |
| 538 | EXPECT_EQ(send_response.message(), recv_response.message()); |
Yang Gao | c1a2c31 | 2015-06-16 10:59:46 -0700 | [diff] [blame] | 539 | EXPECT_TRUE(recv_status.ok()); |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 540 | } |
| 541 | |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 542 | TEST_P(AsyncEnd2endTest, ServerInitialMetadataRpc) { |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 543 | ResetStub(); |
| 544 | |
| 545 | EchoRequest send_request; |
| 546 | EchoRequest recv_request; |
| 547 | EchoResponse send_response; |
| 548 | EchoResponse recv_response; |
| 549 | Status recv_status; |
| 550 | |
| 551 | ClientContext cli_ctx; |
| 552 | ServerContext srv_ctx; |
| 553 | grpc::ServerAsyncResponseWriter<EchoResponse> response_writer(&srv_ctx); |
| 554 | |
| 555 | send_request.set_message("Hello"); |
| 556 | std::pair<grpc::string, grpc::string> meta1("key1", "val1"); |
| 557 | std::pair<grpc::string, grpc::string> meta2("key2", "val2"); |
| 558 | |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 559 | std::unique_ptr<ClientAsyncResponseReader<EchoResponse>> response_reader( |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 560 | stub_->AsyncEcho(&cli_ctx, send_request, cq_.get())); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 561 | |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 562 | service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, cq_.get(), |
| 563 | cq_.get(), tag(2)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 564 | Verifier(GetParam()).Expect(2, true).Verify(cq_.get()); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 565 | EXPECT_EQ(send_request.message(), recv_request.message()); |
| 566 | srv_ctx.AddInitialMetadata(meta1.first, meta1.second); |
| 567 | srv_ctx.AddInitialMetadata(meta2.first, meta2.second); |
| 568 | response_writer.SendInitialMetadata(tag(3)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 569 | Verifier(GetParam()).Expect(3, true).Verify(cq_.get()); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 570 | |
Yang Gao | 3a5e549 | 2015-02-18 14:32:38 -0800 | [diff] [blame] | 571 | response_reader->ReadInitialMetadata(tag(4)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 572 | Verifier(GetParam()).Expect(4, true).Verify(cq_.get()); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 573 | auto server_initial_metadata = cli_ctx.GetServerInitialMetadata(); |
yang-g | e21908f | 2015-08-25 13:47:51 -0700 | [diff] [blame] | 574 | EXPECT_EQ(meta1.second, |
| 575 | ToString(server_initial_metadata.find(meta1.first)->second)); |
| 576 | EXPECT_EQ(meta2.second, |
| 577 | ToString(server_initial_metadata.find(meta2.first)->second)); |
vjpai | d5577aa | 2015-02-18 22:26:48 -0800 | [diff] [blame] | 578 | EXPECT_EQ(static_cast<size_t>(2), server_initial_metadata.size()); |
Yang Gao | 3a5e549 | 2015-02-18 14:32:38 -0800 | [diff] [blame] | 579 | |
| 580 | send_response.set_message(recv_request.message()); |
| 581 | response_writer.Finish(send_response, Status::OK, tag(5)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 582 | Verifier(GetParam()).Expect(5, true).Verify(cq_.get()); |
Yang Gao | 3a5e549 | 2015-02-18 14:32:38 -0800 | [diff] [blame] | 583 | |
| 584 | response_reader->Finish(&recv_response, &recv_status, tag(6)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 585 | Verifier(GetParam()).Expect(6, true).Verify(cq_.get()); |
Yang Gao | 3a5e549 | 2015-02-18 14:32:38 -0800 | [diff] [blame] | 586 | |
| 587 | EXPECT_EQ(send_response.message(), recv_response.message()); |
Yang Gao | c1a2c31 | 2015-06-16 10:59:46 -0700 | [diff] [blame] | 588 | EXPECT_TRUE(recv_status.ok()); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 589 | } |
| 590 | |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 591 | TEST_P(AsyncEnd2endTest, ServerTrailingMetadataRpc) { |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 592 | ResetStub(); |
| 593 | |
| 594 | EchoRequest send_request; |
| 595 | EchoRequest recv_request; |
| 596 | EchoResponse send_response; |
| 597 | EchoResponse recv_response; |
| 598 | Status recv_status; |
| 599 | |
| 600 | ClientContext cli_ctx; |
| 601 | ServerContext srv_ctx; |
| 602 | grpc::ServerAsyncResponseWriter<EchoResponse> response_writer(&srv_ctx); |
| 603 | |
| 604 | send_request.set_message("Hello"); |
| 605 | std::pair<grpc::string, grpc::string> meta1("key1", "val1"); |
| 606 | std::pair<grpc::string, grpc::string> meta2("key2", "val2"); |
| 607 | |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 608 | std::unique_ptr<ClientAsyncResponseReader<EchoResponse>> response_reader( |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 609 | stub_->AsyncEcho(&cli_ctx, send_request, cq_.get())); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 610 | |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 611 | service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, cq_.get(), |
| 612 | cq_.get(), tag(2)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 613 | Verifier(GetParam()).Expect(2, true).Verify(cq_.get()); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 614 | EXPECT_EQ(send_request.message(), recv_request.message()); |
| 615 | response_writer.SendInitialMetadata(tag(3)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 616 | Verifier(GetParam()).Expect(3, true).Verify(cq_.get()); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 617 | |
| 618 | send_response.set_message(recv_request.message()); |
| 619 | srv_ctx.AddTrailingMetadata(meta1.first, meta1.second); |
| 620 | srv_ctx.AddTrailingMetadata(meta2.first, meta2.second); |
| 621 | response_writer.Finish(send_response, Status::OK, tag(4)); |
| 622 | |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 623 | Verifier(GetParam()).Expect(4, true).Verify(cq_.get()); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 624 | |
Yang Gao | 3a5e549 | 2015-02-18 14:32:38 -0800 | [diff] [blame] | 625 | response_reader->Finish(&recv_response, &recv_status, tag(5)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 626 | Verifier(GetParam()).Expect(5, true).Verify(cq_.get()); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 627 | EXPECT_EQ(send_response.message(), recv_response.message()); |
Yang Gao | c1a2c31 | 2015-06-16 10:59:46 -0700 | [diff] [blame] | 628 | EXPECT_TRUE(recv_status.ok()); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 629 | auto server_trailing_metadata = cli_ctx.GetServerTrailingMetadata(); |
yang-g | e21908f | 2015-08-25 13:47:51 -0700 | [diff] [blame] | 630 | EXPECT_EQ(meta1.second, |
| 631 | ToString(server_trailing_metadata.find(meta1.first)->second)); |
| 632 | EXPECT_EQ(meta2.second, |
| 633 | ToString(server_trailing_metadata.find(meta2.first)->second)); |
vjpai | d5577aa | 2015-02-18 22:26:48 -0800 | [diff] [blame] | 634 | EXPECT_EQ(static_cast<size_t>(2), server_trailing_metadata.size()); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 635 | } |
| 636 | |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 637 | TEST_P(AsyncEnd2endTest, MetadataRpc) { |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 638 | ResetStub(); |
| 639 | |
| 640 | EchoRequest send_request; |
| 641 | EchoRequest recv_request; |
| 642 | EchoResponse send_response; |
| 643 | EchoResponse recv_response; |
| 644 | Status recv_status; |
| 645 | |
| 646 | ClientContext cli_ctx; |
| 647 | ServerContext srv_ctx; |
| 648 | grpc::ServerAsyncResponseWriter<EchoResponse> response_writer(&srv_ctx); |
| 649 | |
| 650 | send_request.set_message("Hello"); |
| 651 | std::pair<grpc::string, grpc::string> meta1("key1", "val1"); |
Yang Gao | 3a5e549 | 2015-02-18 14:32:38 -0800 | [diff] [blame] | 652 | std::pair<grpc::string, grpc::string> meta2( |
Vijay Pai | 92a928f | 2015-03-26 16:30:22 -0400 | [diff] [blame] | 653 | "key2-bin", |
Craig Tiller | d6c98df | 2015-08-18 09:33:44 -0700 | [diff] [blame] | 654 | grpc::string("\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc", 13)); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 655 | std::pair<grpc::string, grpc::string> meta3("key3", "val3"); |
Craig Tiller | 47c83fd | 2015-02-21 22:45:35 -0800 | [diff] [blame] | 656 | std::pair<grpc::string, grpc::string> meta6( |
| 657 | "key4-bin", |
Vijay Pai | 92a928f | 2015-03-26 16:30:22 -0400 | [diff] [blame] | 658 | grpc::string("\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d", |
Craig Tiller | d6c98df | 2015-08-18 09:33:44 -0700 | [diff] [blame] | 659 | 14)); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 660 | std::pair<grpc::string, grpc::string> meta5("key5", "val5"); |
Craig Tiller | 47c83fd | 2015-02-21 22:45:35 -0800 | [diff] [blame] | 661 | std::pair<grpc::string, grpc::string> meta4( |
| 662 | "key6-bin", |
Craig Tiller | d6c98df | 2015-08-18 09:33:44 -0700 | [diff] [blame] | 663 | grpc::string( |
| 664 | "\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee", 15)); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 665 | |
| 666 | cli_ctx.AddMetadata(meta1.first, meta1.second); |
| 667 | cli_ctx.AddMetadata(meta2.first, meta2.second); |
| 668 | |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 669 | std::unique_ptr<ClientAsyncResponseReader<EchoResponse>> response_reader( |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 670 | stub_->AsyncEcho(&cli_ctx, send_request, cq_.get())); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 671 | |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 672 | service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, cq_.get(), |
| 673 | cq_.get(), tag(2)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 674 | Verifier(GetParam()).Expect(2, true).Verify(cq_.get()); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 675 | EXPECT_EQ(send_request.message(), recv_request.message()); |
| 676 | auto client_initial_metadata = srv_ctx.client_metadata(); |
yang-g | e21908f | 2015-08-25 13:47:51 -0700 | [diff] [blame] | 677 | EXPECT_EQ(meta1.second, |
| 678 | ToString(client_initial_metadata.find(meta1.first)->second)); |
| 679 | EXPECT_EQ(meta2.second, |
| 680 | ToString(client_initial_metadata.find(meta2.first)->second)); |
Craig Tiller | 8bf2dca | 2015-07-10 13:08:41 -0700 | [diff] [blame] | 681 | EXPECT_GE(client_initial_metadata.size(), static_cast<size_t>(2)); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 682 | |
| 683 | srv_ctx.AddInitialMetadata(meta3.first, meta3.second); |
| 684 | srv_ctx.AddInitialMetadata(meta4.first, meta4.second); |
| 685 | response_writer.SendInitialMetadata(tag(3)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 686 | Verifier(GetParam()).Expect(3, true).Verify(cq_.get()); |
Yang Gao | 3a5e549 | 2015-02-18 14:32:38 -0800 | [diff] [blame] | 687 | response_reader->ReadInitialMetadata(tag(4)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 688 | Verifier(GetParam()).Expect(4, true).Verify(cq_.get()); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 689 | auto server_initial_metadata = cli_ctx.GetServerInitialMetadata(); |
yang-g | e21908f | 2015-08-25 13:47:51 -0700 | [diff] [blame] | 690 | EXPECT_EQ(meta3.second, |
| 691 | ToString(server_initial_metadata.find(meta3.first)->second)); |
| 692 | EXPECT_EQ(meta4.second, |
| 693 | ToString(server_initial_metadata.find(meta4.first)->second)); |
Craig Tiller | 8bf2dca | 2015-07-10 13:08:41 -0700 | [diff] [blame] | 694 | EXPECT_GE(server_initial_metadata.size(), static_cast<size_t>(2)); |
Yang Gao | 3a5e549 | 2015-02-18 14:32:38 -0800 | [diff] [blame] | 695 | |
| 696 | send_response.set_message(recv_request.message()); |
| 697 | srv_ctx.AddTrailingMetadata(meta5.first, meta5.second); |
| 698 | srv_ctx.AddTrailingMetadata(meta6.first, meta6.second); |
| 699 | response_writer.Finish(send_response, Status::OK, tag(5)); |
| 700 | |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 701 | Verifier(GetParam()).Expect(5, true).Verify(cq_.get()); |
Yang Gao | 3a5e549 | 2015-02-18 14:32:38 -0800 | [diff] [blame] | 702 | |
Yang Gao | 3a5e549 | 2015-02-18 14:32:38 -0800 | [diff] [blame] | 703 | response_reader->Finish(&recv_response, &recv_status, tag(6)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 704 | Verifier(GetParam()).Expect(6, true).Verify(cq_.get()); |
Yang Gao | 3a5e549 | 2015-02-18 14:32:38 -0800 | [diff] [blame] | 705 | EXPECT_EQ(send_response.message(), recv_response.message()); |
Yang Gao | c1a2c31 | 2015-06-16 10:59:46 -0700 | [diff] [blame] | 706 | EXPECT_TRUE(recv_status.ok()); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 707 | auto server_trailing_metadata = cli_ctx.GetServerTrailingMetadata(); |
yang-g | e21908f | 2015-08-25 13:47:51 -0700 | [diff] [blame] | 708 | EXPECT_EQ(meta5.second, |
| 709 | ToString(server_trailing_metadata.find(meta5.first)->second)); |
| 710 | EXPECT_EQ(meta6.second, |
| 711 | ToString(server_trailing_metadata.find(meta6.first)->second)); |
Craig Tiller | 8bf2dca | 2015-07-10 13:08:41 -0700 | [diff] [blame] | 712 | EXPECT_GE(server_trailing_metadata.size(), static_cast<size_t>(2)); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 713 | } |
yang-g | b335256 | 2015-08-04 14:42:06 -0700 | [diff] [blame] | 714 | |
| 715 | // Server uses AsyncNotifyWhenDone API to check for cancellation |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 716 | TEST_P(AsyncEnd2endTest, ServerCheckCancellation) { |
yang-g | b335256 | 2015-08-04 14:42:06 -0700 | [diff] [blame] | 717 | ResetStub(); |
| 718 | |
| 719 | EchoRequest send_request; |
| 720 | EchoRequest recv_request; |
| 721 | EchoResponse send_response; |
| 722 | EchoResponse recv_response; |
| 723 | Status recv_status; |
| 724 | |
| 725 | ClientContext cli_ctx; |
| 726 | ServerContext srv_ctx; |
| 727 | grpc::ServerAsyncResponseWriter<EchoResponse> response_writer(&srv_ctx); |
| 728 | |
| 729 | send_request.set_message("Hello"); |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 730 | std::unique_ptr<ClientAsyncResponseReader<EchoResponse>> response_reader( |
yang-g | b335256 | 2015-08-04 14:42:06 -0700 | [diff] [blame] | 731 | stub_->AsyncEcho(&cli_ctx, send_request, cq_.get())); |
| 732 | |
| 733 | srv_ctx.AsyncNotifyWhenDone(tag(5)); |
| 734 | service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, cq_.get(), |
| 735 | cq_.get(), tag(2)); |
| 736 | |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 737 | Verifier(GetParam()).Expect(2, true).Verify(cq_.get()); |
yang-g | b335256 | 2015-08-04 14:42:06 -0700 | [diff] [blame] | 738 | EXPECT_EQ(send_request.message(), recv_request.message()); |
| 739 | |
| 740 | cli_ctx.TryCancel(); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 741 | Verifier(GetParam()).Expect(5, true).Verify(cq_.get()); |
yang-g | b335256 | 2015-08-04 14:42:06 -0700 | [diff] [blame] | 742 | EXPECT_TRUE(srv_ctx.IsCancelled()); |
| 743 | |
| 744 | response_reader->Finish(&recv_response, &recv_status, tag(4)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 745 | Verifier(GetParam()).Expect(4, false).Verify(cq_.get()); |
yang-g | b335256 | 2015-08-04 14:42:06 -0700 | [diff] [blame] | 746 | |
| 747 | EXPECT_EQ(StatusCode::CANCELLED, recv_status.error_code()); |
| 748 | } |
| 749 | |
| 750 | // Server uses AsyncNotifyWhenDone API to check for normal finish |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 751 | TEST_P(AsyncEnd2endTest, ServerCheckDone) { |
yang-g | b335256 | 2015-08-04 14:42:06 -0700 | [diff] [blame] | 752 | ResetStub(); |
| 753 | |
| 754 | EchoRequest send_request; |
| 755 | EchoRequest recv_request; |
| 756 | EchoResponse send_response; |
| 757 | EchoResponse recv_response; |
| 758 | Status recv_status; |
| 759 | |
| 760 | ClientContext cli_ctx; |
| 761 | ServerContext srv_ctx; |
| 762 | grpc::ServerAsyncResponseWriter<EchoResponse> response_writer(&srv_ctx); |
| 763 | |
| 764 | send_request.set_message("Hello"); |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 765 | std::unique_ptr<ClientAsyncResponseReader<EchoResponse>> response_reader( |
yang-g | b335256 | 2015-08-04 14:42:06 -0700 | [diff] [blame] | 766 | stub_->AsyncEcho(&cli_ctx, send_request, cq_.get())); |
| 767 | |
| 768 | srv_ctx.AsyncNotifyWhenDone(tag(5)); |
| 769 | service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, cq_.get(), |
| 770 | cq_.get(), tag(2)); |
| 771 | |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 772 | Verifier(GetParam()).Expect(2, true).Verify(cq_.get()); |
yang-g | b335256 | 2015-08-04 14:42:06 -0700 | [diff] [blame] | 773 | EXPECT_EQ(send_request.message(), recv_request.message()); |
| 774 | |
| 775 | send_response.set_message(recv_request.message()); |
| 776 | response_writer.Finish(send_response, Status::OK, tag(3)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 777 | Verifier(GetParam()).Expect(3, true).Verify(cq_.get()); |
| 778 | Verifier(GetParam()).Expect(5, true).Verify(cq_.get()); |
yang-g | b335256 | 2015-08-04 14:42:06 -0700 | [diff] [blame] | 779 | EXPECT_FALSE(srv_ctx.IsCancelled()); |
| 780 | |
| 781 | response_reader->Finish(&recv_response, &recv_status, tag(4)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 782 | Verifier(GetParam()).Expect(4, true).Verify(cq_.get()); |
yang-g | b335256 | 2015-08-04 14:42:06 -0700 | [diff] [blame] | 783 | |
| 784 | EXPECT_EQ(send_response.message(), recv_response.message()); |
| 785 | EXPECT_TRUE(recv_status.ok()); |
| 786 | } |
| 787 | |
Craig Tiller | 8f7bff7 | 2015-08-17 13:23:14 -0700 | [diff] [blame] | 788 | TEST_P(AsyncEnd2endTest, UnimplementedRpc) { |
yang-g | 730055d | 2015-08-27 12:29:45 -0700 | [diff] [blame] | 789 | std::shared_ptr<Channel> channel = |
Julien Boeuf | e5adc0e | 2015-10-12 14:08:10 -0700 | [diff] [blame] | 790 | CreateChannel(server_address_.str(), InsecureChannelCredentials()); |
Craig Tiller | 1b4e330 | 2015-12-17 16:35:00 -0800 | [diff] [blame] | 791 | std::unique_ptr<grpc::testing::UnimplementedService::Stub> stub; |
| 792 | stub = grpc::testing::UnimplementedService::NewStub(channel); |
yang-g | 9b7757d | 2015-08-13 11:15:53 -0700 | [diff] [blame] | 793 | EchoRequest send_request; |
| 794 | EchoResponse recv_response; |
| 795 | Status recv_status; |
| 796 | |
| 797 | ClientContext cli_ctx; |
| 798 | send_request.set_message("Hello"); |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 799 | std::unique_ptr<ClientAsyncResponseReader<EchoResponse>> response_reader( |
yang-g | 9b7757d | 2015-08-13 11:15:53 -0700 | [diff] [blame] | 800 | stub->AsyncUnimplemented(&cli_ctx, send_request, cq_.get())); |
| 801 | |
| 802 | response_reader->Finish(&recv_response, &recv_status, tag(4)); |
Craig Tiller | 8f7bff7 | 2015-08-17 13:23:14 -0700 | [diff] [blame] | 803 | Verifier(GetParam()).Expect(4, false).Verify(cq_.get()); |
yang-g | 9b7757d | 2015-08-13 11:15:53 -0700 | [diff] [blame] | 804 | |
| 805 | EXPECT_EQ(StatusCode::UNIMPLEMENTED, recv_status.error_code()); |
| 806 | EXPECT_EQ("", recv_status.error_message()); |
| 807 | } |
| 808 | |
Sree Kuchibhotla | 0f242ac | 2016-01-29 18:12:19 -0800 | [diff] [blame] | 809 | // This class is for testing scenarios where RPCs are cancelled on the server |
Sree Kuchibhotla | b0d1567 | 2016-03-07 10:51:02 -0800 | [diff] [blame] | 810 | // by calling ServerContext::TryCancel(). Server uses AsyncNotifyWhenDone |
| 811 | // API to check for cancellation |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 812 | class AsyncEnd2endServerTryCancelTest : public AsyncEnd2endTest { |
| 813 | protected: |
| 814 | typedef enum { |
| 815 | DO_NOT_CANCEL = 0, |
| 816 | CANCEL_BEFORE_PROCESSING, |
| 817 | CANCEL_DURING_PROCESSING, |
| 818 | CANCEL_AFTER_PROCESSING |
| 819 | } ServerTryCancelRequestPhase; |
| 820 | |
Sree Kuchibhotla | 0f242ac | 2016-01-29 18:12:19 -0800 | [diff] [blame] | 821 | // Helper for testing client-streaming RPCs which are cancelled on the server. |
| 822 | // Depending on the value of server_try_cancel parameter, this will test one |
| 823 | // of the following three scenarios: |
| 824 | // CANCEL_BEFORE_PROCESSING: Rpc is cancelled by the server before reading |
| 825 | // any messages from the client |
| 826 | // |
| 827 | // CANCEL_DURING_PROCESSING: Rpc is cancelled by the server while reading |
| 828 | // messages from the client |
| 829 | // |
| 830 | // CANCEL_AFTER PROCESSING: Rpc is cancelled by server after reading all |
| 831 | // messages from the client (but before sending any status back to the |
| 832 | // client) |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 833 | void TestClientStreamingServerCancel( |
| 834 | ServerTryCancelRequestPhase server_try_cancel) { |
| 835 | ResetStub(); |
| 836 | |
| 837 | EchoRequest send_request; |
| 838 | EchoRequest recv_request; |
| 839 | EchoResponse send_response; |
| 840 | EchoResponse recv_response; |
| 841 | Status recv_status; |
| 842 | |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 843 | ClientContext cli_ctx; |
| 844 | ServerContext srv_ctx; |
| 845 | ServerAsyncReader<EchoResponse, EchoRequest> srv_stream(&srv_ctx); |
| 846 | |
| 847 | // Initiate the 'RequestStream' call on client |
| 848 | std::unique_ptr<ClientAsyncWriter<EchoRequest>> cli_stream( |
Sree Kuchibhotla | 4fb5908 | 2016-01-29 11:16:24 -0800 | [diff] [blame] | 849 | stub_->AsyncRequestStream(&cli_ctx, &recv_response, cq_.get(), tag(1))); |
| 850 | Verifier(GetParam()).Expect(1, true).Verify(cq_.get()); |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 851 | |
| 852 | // On the server, request to be notified of 'RequestStream' calls |
| 853 | // and receive the 'RequestStream' call just made by the client |
Sree Kuchibhotla | b0d1567 | 2016-03-07 10:51:02 -0800 | [diff] [blame] | 854 | srv_ctx.AsyncNotifyWhenDone(tag(11)); |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 855 | service_.RequestRequestStream(&srv_ctx, &srv_stream, cq_.get(), cq_.get(), |
| 856 | tag(2)); |
| 857 | Verifier(GetParam()).Expect(2, true).Verify(cq_.get()); |
| 858 | |
| 859 | // Client sends 3 messages (tags 3, 4 and 5) |
| 860 | for (int tag_idx = 3; tag_idx <= 5; tag_idx++) { |
| 861 | send_request.set_message("Ping " + std::to_string(tag_idx)); |
| 862 | cli_stream->Write(send_request, tag(tag_idx)); |
Sree Kuchibhotla | 4fb5908 | 2016-01-29 11:16:24 -0800 | [diff] [blame] | 863 | Verifier(GetParam()).Expect(tag_idx, true).Verify(cq_.get()); |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 864 | } |
| 865 | cli_stream->WritesDone(tag(6)); |
Sree Kuchibhotla | 4fb5908 | 2016-01-29 11:16:24 -0800 | [diff] [blame] | 866 | Verifier(GetParam()).Expect(6, true).Verify(cq_.get()); |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 867 | |
| 868 | bool expected_server_cq_result = true; |
| 869 | bool ignore_cq_result = false; |
Sree Kuchibhotla | b0d1567 | 2016-03-07 10:51:02 -0800 | [diff] [blame] | 870 | bool want_done_tag = false; |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 871 | |
| 872 | if (server_try_cancel == CANCEL_BEFORE_PROCESSING) { |
Sree Kuchibhotla | b0d1567 | 2016-03-07 10:51:02 -0800 | [diff] [blame] | 873 | srv_ctx.TryCancel(); |
| 874 | Verifier(GetParam()).Expect(11, true).Verify(cq_.get()); |
| 875 | EXPECT_TRUE(srv_ctx.IsCancelled()); |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 876 | |
| 877 | // Since cancellation is done before server reads any results, we know |
| 878 | // for sure that all cq results will return false from this point forward |
| 879 | expected_server_cq_result = false; |
| 880 | } |
| 881 | |
| 882 | std::thread* server_try_cancel_thd = NULL; |
Sree Kuchibhotla | b0d1567 | 2016-03-07 10:51:02 -0800 | [diff] [blame] | 883 | |
| 884 | auto verif = Verifier(GetParam()); |
| 885 | |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 886 | if (server_try_cancel == CANCEL_DURING_PROCESSING) { |
Sree Kuchibhotla | b0d1567 | 2016-03-07 10:51:02 -0800 | [diff] [blame] | 887 | server_try_cancel_thd = |
| 888 | new std::thread(&ServerContext::TryCancel, &srv_ctx); |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 889 | // Server will cancel the RPC in a parallel thread while reading the |
| 890 | // requests from the client. Since the cancellation can happen at anytime, |
| 891 | // some of the cq results (i.e those until cancellation) might be true but |
| 892 | // its non deterministic. So better to ignore the cq results |
| 893 | ignore_cq_result = true; |
Sree Kuchibhotla | b0d1567 | 2016-03-07 10:51:02 -0800 | [diff] [blame] | 894 | // Expect that we might possibly see the done tag that |
| 895 | // indicates cancellation completion in this case |
| 896 | want_done_tag = true; |
| 897 | verif.Expect(11, true); |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 898 | } |
| 899 | |
| 900 | // Server reads 3 messages (tags 6, 7 and 8) |
Sree Kuchibhotla | b0d1567 | 2016-03-07 10:51:02 -0800 | [diff] [blame] | 901 | // But if want_done_tag is true, we might also see tag 11 |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 902 | for (int tag_idx = 6; tag_idx <= 8; tag_idx++) { |
| 903 | srv_stream.Read(&recv_request, tag(tag_idx)); |
Sree Kuchibhotla | b0d1567 | 2016-03-07 10:51:02 -0800 | [diff] [blame] | 904 | // Note that we'll add something to the verifier and verify that |
| 905 | // something was seen, but it might be tag 11 and not what we |
| 906 | // just added |
| 907 | int got_tag = verif.Expect(tag_idx, expected_server_cq_result) |
| 908 | .Next(cq_.get(), ignore_cq_result); |
| 909 | GPR_ASSERT((got_tag == tag_idx) || (got_tag == 11 && want_done_tag)); |
| 910 | if (got_tag == 11) { |
| 911 | EXPECT_TRUE(srv_ctx.IsCancelled()); |
| 912 | want_done_tag = false; |
| 913 | // Now get the other entry that we were waiting on |
| 914 | EXPECT_EQ(verif.Next(cq_.get(), ignore_cq_result), tag_idx); |
| 915 | } |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 916 | } |
| 917 | |
| 918 | if (server_try_cancel_thd != NULL) { |
| 919 | server_try_cancel_thd->join(); |
| 920 | delete server_try_cancel_thd; |
| 921 | } |
| 922 | |
| 923 | if (server_try_cancel == CANCEL_AFTER_PROCESSING) { |
Sree Kuchibhotla | b0d1567 | 2016-03-07 10:51:02 -0800 | [diff] [blame] | 924 | srv_ctx.TryCancel(); |
| 925 | want_done_tag = true; |
| 926 | verif.Expect(11, true); |
| 927 | } |
| 928 | |
| 929 | if (want_done_tag) { |
| 930 | verif.Verify(cq_.get()); |
| 931 | EXPECT_TRUE(srv_ctx.IsCancelled()); |
| 932 | want_done_tag = false; |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 933 | } |
| 934 | |
Sree Kuchibhotla | 0f242ac | 2016-01-29 18:12:19 -0800 | [diff] [blame] | 935 | // The RPC has been cancelled at this point for sure (i.e irrespective of |
| 936 | // the value of `server_try_cancel` is). So, from this point forward, we |
| 937 | // know that cq results are supposed to return false on server. |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 938 | |
Sree Kuchibhotla | 0f242ac | 2016-01-29 18:12:19 -0800 | [diff] [blame] | 939 | // Server sends the final message and cancelled status (but the RPC is |
| 940 | // already cancelled at this point. So we expect the operation to fail) |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 941 | srv_stream.Finish(send_response, Status::CANCELLED, tag(9)); |
| 942 | Verifier(GetParam()).Expect(9, false).Verify(cq_.get()); |
| 943 | |
Sree Kuchibhotla | 0f242ac | 2016-01-29 18:12:19 -0800 | [diff] [blame] | 944 | // Client will see the cancellation |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 945 | cli_stream->Finish(&recv_status, tag(10)); |
Sree Kuchibhotla | 369a04a | 2016-02-01 10:53:13 -0800 | [diff] [blame] | 946 | // TODO(sreek): The expectation here should be true. This is a bug (github |
Sree Kuchibhotla | 0f242ac | 2016-01-29 18:12:19 -0800 | [diff] [blame] | 947 | // issue #4972) |
Sree Kuchibhotla | 4fb5908 | 2016-01-29 11:16:24 -0800 | [diff] [blame] | 948 | Verifier(GetParam()).Expect(10, false).Verify(cq_.get()); |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 949 | EXPECT_FALSE(recv_status.ok()); |
| 950 | EXPECT_EQ(::grpc::StatusCode::CANCELLED, recv_status.error_code()); |
| 951 | } |
| 952 | |
Sree Kuchibhotla | 0f242ac | 2016-01-29 18:12:19 -0800 | [diff] [blame] | 953 | // Helper for testing server-streaming RPCs which are cancelled on the server. |
| 954 | // Depending on the value of server_try_cancel parameter, this will test one |
| 955 | // of the following three scenarios: |
| 956 | // CANCEL_BEFORE_PROCESSING: Rpc is cancelled by the server before sending |
| 957 | // any messages to the client |
| 958 | // |
| 959 | // CANCEL_DURING_PROCESSING: Rpc is cancelled by the server while sending |
| 960 | // messages to the client |
| 961 | // |
| 962 | // CANCEL_AFTER PROCESSING: Rpc is cancelled by server after sending all |
| 963 | // messages to the client (but before sending any status back to the |
| 964 | // client) |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 965 | void TestServerStreamingServerCancel( |
| 966 | ServerTryCancelRequestPhase server_try_cancel) { |
| 967 | ResetStub(); |
| 968 | |
| 969 | EchoRequest send_request; |
| 970 | EchoRequest recv_request; |
| 971 | EchoResponse send_response; |
| 972 | EchoResponse recv_response; |
| 973 | Status recv_status; |
| 974 | ClientContext cli_ctx; |
| 975 | ServerContext srv_ctx; |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 976 | ServerAsyncWriter<EchoResponse> srv_stream(&srv_ctx); |
| 977 | |
| 978 | send_request.set_message("Ping"); |
| 979 | // Initiate the 'ResponseStream' call on the client |
| 980 | std::unique_ptr<ClientAsyncReader<EchoResponse>> cli_stream( |
Sree Kuchibhotla | 4fb5908 | 2016-01-29 11:16:24 -0800 | [diff] [blame] | 981 | stub_->AsyncResponseStream(&cli_ctx, send_request, cq_.get(), tag(1))); |
| 982 | Verifier(GetParam()).Expect(1, true).Verify(cq_.get()); |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 983 | // On the server, request to be notified of 'ResponseStream' calls and |
| 984 | // receive the call just made by the client |
Sree Kuchibhotla | b0d1567 | 2016-03-07 10:51:02 -0800 | [diff] [blame] | 985 | srv_ctx.AsyncNotifyWhenDone(tag(11)); |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 986 | service_.RequestResponseStream(&srv_ctx, &recv_request, &srv_stream, |
| 987 | cq_.get(), cq_.get(), tag(2)); |
| 988 | Verifier(GetParam()).Expect(2, true).Verify(cq_.get()); |
| 989 | EXPECT_EQ(send_request.message(), recv_request.message()); |
| 990 | |
| 991 | bool expected_cq_result = true; |
| 992 | bool ignore_cq_result = false; |
Sree Kuchibhotla | b0d1567 | 2016-03-07 10:51:02 -0800 | [diff] [blame] | 993 | bool want_done_tag = false; |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 994 | |
| 995 | if (server_try_cancel == CANCEL_BEFORE_PROCESSING) { |
Sree Kuchibhotla | b0d1567 | 2016-03-07 10:51:02 -0800 | [diff] [blame] | 996 | srv_ctx.TryCancel(); |
| 997 | Verifier(GetParam()).Expect(11, true).Verify(cq_.get()); |
| 998 | EXPECT_TRUE(srv_ctx.IsCancelled()); |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 999 | |
| 1000 | // We know for sure that all cq results will be false from this point |
| 1001 | // since the server cancelled the RPC |
| 1002 | expected_cq_result = false; |
| 1003 | } |
| 1004 | |
| 1005 | std::thread* server_try_cancel_thd = NULL; |
Sree Kuchibhotla | b0d1567 | 2016-03-07 10:51:02 -0800 | [diff] [blame] | 1006 | |
| 1007 | auto verif = Verifier(GetParam()); |
| 1008 | |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 1009 | if (server_try_cancel == CANCEL_DURING_PROCESSING) { |
Sree Kuchibhotla | b0d1567 | 2016-03-07 10:51:02 -0800 | [diff] [blame] | 1010 | server_try_cancel_thd = |
| 1011 | new std::thread(&ServerContext::TryCancel, &srv_ctx); |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 1012 | |
| 1013 | // Server will cancel the RPC in a parallel thread while writing responses |
| 1014 | // to the client. Since the cancellation can happen at anytime, some of |
Sree Kuchibhotla | 0f242ac | 2016-01-29 18:12:19 -0800 | [diff] [blame] | 1015 | // the cq results (i.e those until cancellation) might be true but it is |
| 1016 | // non deterministic. So better to ignore the cq results |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 1017 | ignore_cq_result = true; |
Sree Kuchibhotla | b0d1567 | 2016-03-07 10:51:02 -0800 | [diff] [blame] | 1018 | // Expect that we might possibly see the done tag that |
| 1019 | // indicates cancellation completion in this case |
| 1020 | want_done_tag = true; |
| 1021 | verif.Expect(11, true); |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 1022 | } |
| 1023 | |
| 1024 | // Server sends three messages (tags 3, 4 and 5) |
Sree Kuchibhotla | b0d1567 | 2016-03-07 10:51:02 -0800 | [diff] [blame] | 1025 | // But if want_done tag is true, we might also see tag 11 |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 1026 | for (int tag_idx = 3; tag_idx <= 5; tag_idx++) { |
| 1027 | send_response.set_message("Pong " + std::to_string(tag_idx)); |
| 1028 | srv_stream.Write(send_response, tag(tag_idx)); |
Sree Kuchibhotla | b0d1567 | 2016-03-07 10:51:02 -0800 | [diff] [blame] | 1029 | // Note that we'll add something to the verifier and verify that |
| 1030 | // something was seen, but it might be tag 11 and not what we |
| 1031 | // just added |
| 1032 | int got_tag = verif.Expect(tag_idx, expected_cq_result) |
| 1033 | .Next(cq_.get(), ignore_cq_result); |
| 1034 | GPR_ASSERT((got_tag == tag_idx) || (got_tag == 11 && want_done_tag)); |
| 1035 | if (got_tag == 11) { |
| 1036 | EXPECT_TRUE(srv_ctx.IsCancelled()); |
| 1037 | want_done_tag = false; |
| 1038 | // Now get the other entry that we were waiting on |
| 1039 | EXPECT_EQ(verif.Next(cq_.get(), ignore_cq_result), tag_idx); |
| 1040 | } |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 1041 | } |
| 1042 | |
Sree Kuchibhotla | 0f242ac | 2016-01-29 18:12:19 -0800 | [diff] [blame] | 1043 | if (server_try_cancel_thd != NULL) { |
| 1044 | server_try_cancel_thd->join(); |
| 1045 | delete server_try_cancel_thd; |
| 1046 | } |
| 1047 | |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 1048 | if (server_try_cancel == CANCEL_AFTER_PROCESSING) { |
Sree Kuchibhotla | b0d1567 | 2016-03-07 10:51:02 -0800 | [diff] [blame] | 1049 | srv_ctx.TryCancel(); |
| 1050 | want_done_tag = true; |
| 1051 | verif.Expect(11, true); |
yang-g | ad0df7b | 2016-02-22 10:00:20 -0800 | [diff] [blame] | 1052 | |
| 1053 | // Client reads may fail bacause it is notified that the stream is |
| 1054 | // cancelled. |
| 1055 | ignore_cq_result = true; |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 1056 | } |
| 1057 | |
Sree Kuchibhotla | b0d1567 | 2016-03-07 10:51:02 -0800 | [diff] [blame] | 1058 | if (want_done_tag) { |
| 1059 | verif.Verify(cq_.get()); |
| 1060 | EXPECT_TRUE(srv_ctx.IsCancelled()); |
| 1061 | want_done_tag = false; |
| 1062 | } |
| 1063 | |
Sree Kuchibhotla | 0f242ac | 2016-01-29 18:12:19 -0800 | [diff] [blame] | 1064 | // Client attemts to read the three messages from the server |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 1065 | for (int tag_idx = 6; tag_idx <= 8; tag_idx++) { |
| 1066 | cli_stream->Read(&recv_response, tag(tag_idx)); |
| 1067 | Verifier(GetParam()) |
| 1068 | .Expect(tag_idx, expected_cq_result) |
Sree Kuchibhotla | 4fb5908 | 2016-01-29 11:16:24 -0800 | [diff] [blame] | 1069 | .Verify(cq_.get(), ignore_cq_result); |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 1070 | } |
| 1071 | |
Sree Kuchibhotla | 0f242ac | 2016-01-29 18:12:19 -0800 | [diff] [blame] | 1072 | // The RPC has been cancelled at this point for sure (i.e irrespective of |
| 1073 | // the value of `server_try_cancel` is). So, from this point forward, we |
| 1074 | // know that cq results are supposed to return false on server. |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 1075 | |
Sree Kuchibhotla | 0f242ac | 2016-01-29 18:12:19 -0800 | [diff] [blame] | 1076 | // Server finishes the stream (but the RPC is already cancelled) |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 1077 | srv_stream.Finish(Status::CANCELLED, tag(9)); |
| 1078 | Verifier(GetParam()).Expect(9, false).Verify(cq_.get()); |
| 1079 | |
Sree Kuchibhotla | 0f242ac | 2016-01-29 18:12:19 -0800 | [diff] [blame] | 1080 | // Client will see the cancellation |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 1081 | cli_stream->Finish(&recv_status, tag(10)); |
Sree Kuchibhotla | 4fb5908 | 2016-01-29 11:16:24 -0800 | [diff] [blame] | 1082 | Verifier(GetParam()).Expect(10, true).Verify(cq_.get()); |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 1083 | EXPECT_FALSE(recv_status.ok()); |
| 1084 | EXPECT_EQ(::grpc::StatusCode::CANCELLED, recv_status.error_code()); |
| 1085 | } |
| 1086 | |
Sree Kuchibhotla | 0f242ac | 2016-01-29 18:12:19 -0800 | [diff] [blame] | 1087 | // Helper for testing bidirectinal-streaming RPCs which are cancelled on the |
| 1088 | // server. |
| 1089 | // |
| 1090 | // Depending on the value of server_try_cancel parameter, this will |
| 1091 | // test one of the following three scenarios: |
| 1092 | // CANCEL_BEFORE_PROCESSING: Rpc is cancelled by the server before reading/ |
| 1093 | // writing any messages from/to the client |
| 1094 | // |
| 1095 | // CANCEL_DURING_PROCESSING: Rpc is cancelled by the server while reading |
| 1096 | // messages from the client |
| 1097 | // |
| 1098 | // CANCEL_AFTER PROCESSING: Rpc is cancelled by server after reading all |
| 1099 | // messages from the client (but before sending any status back to the |
| 1100 | // client) |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 1101 | void TestBidiStreamingServerCancel( |
| 1102 | ServerTryCancelRequestPhase server_try_cancel) { |
| 1103 | ResetStub(); |
| 1104 | |
| 1105 | EchoRequest send_request; |
| 1106 | EchoRequest recv_request; |
| 1107 | EchoResponse send_response; |
| 1108 | EchoResponse recv_response; |
| 1109 | Status recv_status; |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 1110 | ClientContext cli_ctx; |
| 1111 | ServerContext srv_ctx; |
| 1112 | ServerAsyncReaderWriter<EchoResponse, EchoRequest> srv_stream(&srv_ctx); |
| 1113 | |
| 1114 | // Initiate the call from the client side |
| 1115 | std::unique_ptr<ClientAsyncReaderWriter<EchoRequest, EchoResponse>> |
Sree Kuchibhotla | 4fb5908 | 2016-01-29 11:16:24 -0800 | [diff] [blame] | 1116 | cli_stream(stub_->AsyncBidiStream(&cli_ctx, cq_.get(), tag(1))); |
| 1117 | Verifier(GetParam()).Expect(1, true).Verify(cq_.get()); |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 1118 | |
| 1119 | // On the server, request to be notified of the 'BidiStream' call and |
| 1120 | // receive the call just made by the client |
Sree Kuchibhotla | b0d1567 | 2016-03-07 10:51:02 -0800 | [diff] [blame] | 1121 | srv_ctx.AsyncNotifyWhenDone(tag(11)); |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 1122 | service_.RequestBidiStream(&srv_ctx, &srv_stream, cq_.get(), cq_.get(), |
| 1123 | tag(2)); |
| 1124 | Verifier(GetParam()).Expect(2, true).Verify(cq_.get()); |
| 1125 | |
Sree Kuchibhotla | 0f242ac | 2016-01-29 18:12:19 -0800 | [diff] [blame] | 1126 | // Client sends the first and the only message |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 1127 | send_request.set_message("Ping"); |
| 1128 | cli_stream->Write(send_request, tag(3)); |
Sree Kuchibhotla | 4fb5908 | 2016-01-29 11:16:24 -0800 | [diff] [blame] | 1129 | Verifier(GetParam()).Expect(3, true).Verify(cq_.get()); |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 1130 | |
| 1131 | bool expected_cq_result = true; |
| 1132 | bool ignore_cq_result = false; |
Sree Kuchibhotla | b0d1567 | 2016-03-07 10:51:02 -0800 | [diff] [blame] | 1133 | bool want_done_tag = false; |
Sree Kuchibhotla | 0f242ac | 2016-01-29 18:12:19 -0800 | [diff] [blame] | 1134 | |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 1135 | if (server_try_cancel == CANCEL_BEFORE_PROCESSING) { |
Sree Kuchibhotla | b0d1567 | 2016-03-07 10:51:02 -0800 | [diff] [blame] | 1136 | srv_ctx.TryCancel(); |
| 1137 | Verifier(GetParam()).Expect(11, true).Verify(cq_.get()); |
| 1138 | EXPECT_TRUE(srv_ctx.IsCancelled()); |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 1139 | |
| 1140 | // We know for sure that all cq results will be false from this point |
| 1141 | // since the server cancelled the RPC |
| 1142 | expected_cq_result = false; |
| 1143 | } |
| 1144 | |
| 1145 | std::thread* server_try_cancel_thd = NULL; |
Sree Kuchibhotla | b0d1567 | 2016-03-07 10:51:02 -0800 | [diff] [blame] | 1146 | |
| 1147 | auto verif = Verifier(GetParam()); |
| 1148 | |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 1149 | if (server_try_cancel == CANCEL_DURING_PROCESSING) { |
Sree Kuchibhotla | b0d1567 | 2016-03-07 10:51:02 -0800 | [diff] [blame] | 1150 | server_try_cancel_thd = |
| 1151 | new std::thread(&ServerContext::TryCancel, &srv_ctx); |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 1152 | |
| 1153 | // Since server is going to cancel the RPC in a parallel thread, some of |
| 1154 | // the cq results (i.e those until the cancellation) might be true. Since |
| 1155 | // that number is non-deterministic, it is better to ignore the cq results |
| 1156 | ignore_cq_result = true; |
Sree Kuchibhotla | b0d1567 | 2016-03-07 10:51:02 -0800 | [diff] [blame] | 1157 | // Expect that we might possibly see the done tag that |
| 1158 | // indicates cancellation completion in this case |
| 1159 | want_done_tag = true; |
| 1160 | verif.Expect(11, true); |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 1161 | } |
| 1162 | |
Sree Kuchibhotla | b0d1567 | 2016-03-07 10:51:02 -0800 | [diff] [blame] | 1163 | int got_tag; |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 1164 | srv_stream.Read(&recv_request, tag(4)); |
Sree Kuchibhotla | b0d1567 | 2016-03-07 10:51:02 -0800 | [diff] [blame] | 1165 | verif.Expect(4, expected_cq_result); |
| 1166 | got_tag = verif.Next(cq_.get(), ignore_cq_result); |
| 1167 | GPR_ASSERT((got_tag == 4) || (got_tag == 11 && want_done_tag)); |
| 1168 | if (got_tag == 11) { |
| 1169 | EXPECT_TRUE(srv_ctx.IsCancelled()); |
| 1170 | want_done_tag = false; |
| 1171 | // Now get the other entry that we were waiting on |
| 1172 | EXPECT_EQ(verif.Next(cq_.get(), ignore_cq_result), 4); |
| 1173 | } |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 1174 | |
| 1175 | send_response.set_message("Pong"); |
| 1176 | srv_stream.Write(send_response, tag(5)); |
Sree Kuchibhotla | b0d1567 | 2016-03-07 10:51:02 -0800 | [diff] [blame] | 1177 | verif.Expect(5, expected_cq_result); |
| 1178 | got_tag = verif.Next(cq_.get(), ignore_cq_result); |
| 1179 | GPR_ASSERT((got_tag == 5) || (got_tag == 11 && want_done_tag)); |
| 1180 | if (got_tag == 11) { |
| 1181 | EXPECT_TRUE(srv_ctx.IsCancelled()); |
| 1182 | want_done_tag = false; |
| 1183 | // Now get the other entry that we were waiting on |
| 1184 | EXPECT_EQ(verif.Next(cq_.get(), ignore_cq_result), 5); |
| 1185 | } |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 1186 | |
| 1187 | cli_stream->Read(&recv_response, tag(6)); |
Sree Kuchibhotla | b0d1567 | 2016-03-07 10:51:02 -0800 | [diff] [blame] | 1188 | verif.Expect(6, expected_cq_result); |
| 1189 | got_tag = verif.Next(cq_.get(), ignore_cq_result); |
| 1190 | GPR_ASSERT((got_tag == 6) || (got_tag == 11 && want_done_tag)); |
| 1191 | if (got_tag == 11) { |
| 1192 | EXPECT_TRUE(srv_ctx.IsCancelled()); |
| 1193 | want_done_tag = false; |
| 1194 | // Now get the other entry that we were waiting on |
| 1195 | EXPECT_EQ(verif.Next(cq_.get(), ignore_cq_result), 6); |
| 1196 | } |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 1197 | |
| 1198 | // This is expected to succeed in all cases |
| 1199 | cli_stream->WritesDone(tag(7)); |
Sree Kuchibhotla | b0d1567 | 2016-03-07 10:51:02 -0800 | [diff] [blame] | 1200 | verif.Expect(7, true); |
| 1201 | got_tag = verif.Next(cq_.get(), ignore_cq_result); |
| 1202 | GPR_ASSERT((got_tag == 7) || (got_tag == 11 && want_done_tag)); |
| 1203 | if (got_tag == 11) { |
| 1204 | EXPECT_TRUE(srv_ctx.IsCancelled()); |
| 1205 | want_done_tag = false; |
| 1206 | // Now get the other entry that we were waiting on |
| 1207 | EXPECT_EQ(verif.Next(cq_.get(), ignore_cq_result), 7); |
| 1208 | } |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 1209 | |
Sree Kuchibhotla | 0f242ac | 2016-01-29 18:12:19 -0800 | [diff] [blame] | 1210 | // This is expected to fail in all cases i.e for all values of |
Vijay Pai | 018879a | 2016-02-16 09:20:50 -0800 | [diff] [blame] | 1211 | // server_try_cancel. This is because at this point, either there are no |
Sree Kuchibhotla | 0f242ac | 2016-01-29 18:12:19 -0800 | [diff] [blame] | 1212 | // more msgs from the client (because client called WritesDone) or the RPC |
| 1213 | // is cancelled on the server |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 1214 | srv_stream.Read(&recv_request, tag(8)); |
Sree Kuchibhotla | b0d1567 | 2016-03-07 10:51:02 -0800 | [diff] [blame] | 1215 | verif.Expect(8, false); |
| 1216 | got_tag = verif.Next(cq_.get(), ignore_cq_result); |
| 1217 | GPR_ASSERT((got_tag == 8) || (got_tag == 11 && want_done_tag)); |
| 1218 | if (got_tag == 11) { |
| 1219 | EXPECT_TRUE(srv_ctx.IsCancelled()); |
| 1220 | want_done_tag = false; |
| 1221 | // Now get the other entry that we were waiting on |
| 1222 | EXPECT_EQ(verif.Next(cq_.get(), ignore_cq_result), 8); |
| 1223 | } |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 1224 | |
| 1225 | if (server_try_cancel_thd != NULL) { |
| 1226 | server_try_cancel_thd->join(); |
| 1227 | delete server_try_cancel_thd; |
| 1228 | } |
| 1229 | |
| 1230 | if (server_try_cancel == CANCEL_AFTER_PROCESSING) { |
Sree Kuchibhotla | b0d1567 | 2016-03-07 10:51:02 -0800 | [diff] [blame] | 1231 | srv_ctx.TryCancel(); |
| 1232 | want_done_tag = true; |
| 1233 | verif.Expect(11, true); |
| 1234 | } |
| 1235 | |
| 1236 | if (want_done_tag) { |
| 1237 | verif.Verify(cq_.get()); |
| 1238 | EXPECT_TRUE(srv_ctx.IsCancelled()); |
| 1239 | want_done_tag = false; |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 1240 | } |
| 1241 | |
Sree Kuchibhotla | 0f242ac | 2016-01-29 18:12:19 -0800 | [diff] [blame] | 1242 | // The RPC has been cancelled at this point for sure (i.e irrespective of |
| 1243 | // the value of `server_try_cancel` is). So, from this point forward, we |
| 1244 | // know that cq results are supposed to return false on server. |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 1245 | |
| 1246 | srv_stream.Finish(Status::CANCELLED, tag(9)); |
| 1247 | Verifier(GetParam()).Expect(9, false).Verify(cq_.get()); |
| 1248 | |
| 1249 | cli_stream->Finish(&recv_status, tag(10)); |
Sree Kuchibhotla | 4fb5908 | 2016-01-29 11:16:24 -0800 | [diff] [blame] | 1250 | Verifier(GetParam()).Expect(10, true).Verify(cq_.get()); |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 1251 | EXPECT_FALSE(recv_status.ok()); |
| 1252 | EXPECT_EQ(grpc::StatusCode::CANCELLED, recv_status.error_code()); |
| 1253 | } |
| 1254 | }; |
| 1255 | |
| 1256 | TEST_P(AsyncEnd2endServerTryCancelTest, ClientStreamingServerTryCancelBefore) { |
| 1257 | TestClientStreamingServerCancel(CANCEL_BEFORE_PROCESSING); |
| 1258 | } |
| 1259 | |
| 1260 | TEST_P(AsyncEnd2endServerTryCancelTest, ClientStreamingServerTryCancelDuring) { |
| 1261 | TestClientStreamingServerCancel(CANCEL_DURING_PROCESSING); |
| 1262 | } |
| 1263 | |
| 1264 | TEST_P(AsyncEnd2endServerTryCancelTest, ClientStreamingServerTryCancelAfter) { |
| 1265 | TestClientStreamingServerCancel(CANCEL_AFTER_PROCESSING); |
| 1266 | } |
| 1267 | |
| 1268 | TEST_P(AsyncEnd2endServerTryCancelTest, ServerStreamingServerTryCancelBefore) { |
| 1269 | TestServerStreamingServerCancel(CANCEL_BEFORE_PROCESSING); |
| 1270 | } |
| 1271 | |
| 1272 | TEST_P(AsyncEnd2endServerTryCancelTest, ServerStreamingServerTryCancelDuring) { |
| 1273 | TestServerStreamingServerCancel(CANCEL_DURING_PROCESSING); |
| 1274 | } |
| 1275 | |
| 1276 | TEST_P(AsyncEnd2endServerTryCancelTest, ServerStreamingServerTryCancelAfter) { |
| 1277 | TestServerStreamingServerCancel(CANCEL_AFTER_PROCESSING); |
| 1278 | } |
| 1279 | |
| 1280 | TEST_P(AsyncEnd2endServerTryCancelTest, ServerBidiStreamingTryCancelBefore) { |
| 1281 | TestBidiStreamingServerCancel(CANCEL_BEFORE_PROCESSING); |
| 1282 | } |
| 1283 | |
| 1284 | TEST_P(AsyncEnd2endServerTryCancelTest, ServerBidiStreamingTryCancelDuring) { |
| 1285 | TestBidiStreamingServerCancel(CANCEL_DURING_PROCESSING); |
| 1286 | } |
| 1287 | |
| 1288 | TEST_P(AsyncEnd2endServerTryCancelTest, ServerBidiStreamingTryCancelAfter) { |
| 1289 | TestBidiStreamingServerCancel(CANCEL_AFTER_PROCESSING); |
| 1290 | } |
| 1291 | |
Craig Tiller | 4c06b82 | 2015-08-06 08:41:31 -0700 | [diff] [blame] | 1292 | INSTANTIATE_TEST_CASE_P(AsyncEnd2end, AsyncEnd2endTest, |
| 1293 | ::testing::Values(false, true)); |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 1294 | INSTANTIATE_TEST_CASE_P(AsyncEnd2endServerTryCancel, |
| 1295 | AsyncEnd2endServerTryCancelTest, |
| 1296 | ::testing::Values(false)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 1297 | |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 1298 | } // namespace |
| 1299 | } // namespace testing |
| 1300 | } // namespace grpc |
| 1301 | |
| 1302 | int main(int argc, char** argv) { |
| 1303 | grpc_test_init(argc, argv); |
Vijay Pai | b65eda4 | 2016-02-16 13:48:05 -0800 | [diff] [blame] | 1304 | gpr_tls_init(&g_is_async_end2end_test); |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 1305 | ::testing::InitGoogleTest(&argc, argv); |
Vijay Pai | b65eda4 | 2016-02-16 13:48:05 -0800 | [diff] [blame] | 1306 | int ret = RUN_ALL_TESTS(); |
| 1307 | gpr_tls_destroy(&g_is_async_end2end_test); |
| 1308 | return ret; |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 1309 | } |