Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 3 | * Copyright 2015 gRPC authors. |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 4 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 8 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 10 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 16 | * |
| 17 | */ |
| 18 | |
Yang Gao | 69fe075 | 2015-06-01 14:32:38 -0700 | [diff] [blame] | 19 | #include <mutex> |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 20 | #include <thread> |
yangg | ed5e7e0 | 2015-01-06 10:16:15 -0800 | [diff] [blame] | 21 | |
yang-g | 9e2f90c | 2015-08-21 15:35:03 -0700 | [diff] [blame] | 22 | #include <grpc++/channel.h> |
| 23 | #include <grpc++/client_context.h> |
| 24 | #include <grpc++/create_channel.h> |
Craig Tiller | 20afa3d | 2016-10-17 14:52:14 -0700 | [diff] [blame] | 25 | #include <grpc++/resource_quota.h> |
Julien Boeuf | 5be92a3 | 2015-08-28 16:28:18 -0700 | [diff] [blame] | 26 | #include <grpc++/security/auth_metadata_processor.h> |
| 27 | #include <grpc++/security/credentials.h> |
| 28 | #include <grpc++/security/server_credentials.h> |
yang-g | 9e2f90c | 2015-08-21 15:35:03 -0700 | [diff] [blame] | 29 | #include <grpc++/server.h> |
| 30 | #include <grpc++/server_builder.h> |
| 31 | #include <grpc++/server_context.h> |
Sree Kuchibhotla | b0d0c8e | 2016-01-13 22:52:17 -0800 | [diff] [blame] | 32 | #include <grpc/grpc.h> |
Yuchen Zeng | 7fa814f | 2017-10-15 19:00:16 -0700 | [diff] [blame] | 33 | #include <grpc/support/alloc.h> |
David Garcia Quintas | c79b065 | 2016-07-27 21:11:58 -0700 | [diff] [blame] | 34 | #include <grpc/support/log.h> |
Sree Kuchibhotla | b0d0c8e | 2016-01-13 22:52:17 -0800 | [diff] [blame] | 35 | #include <grpc/support/thd.h> |
| 36 | #include <grpc/support/time.h> |
yang-g | 9e2f90c | 2015-08-21 15:35:03 -0700 | [diff] [blame] | 37 | |
Mark D. Roth | dbdf495 | 2018-01-18 11:21:12 -0800 | [diff] [blame] | 38 | #include "src/core/lib/gpr/env.h" |
Julien Boeuf | 8ca294e | 2016-05-02 14:56:30 -0700 | [diff] [blame] | 39 | #include "src/core/lib/security/credentials/credentials.h" |
Sree Kuchibhotla | b0d0c8e | 2016-01-13 22:52:17 -0800 | [diff] [blame] | 40 | #include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h" |
| 41 | #include "src/proto/grpc/testing/echo.grpc.pb.h" |
Nicolas Noble | 8921916 | 2015-04-07 18:01:18 -0700 | [diff] [blame] | 42 | #include "test/core/util/port.h" |
Craig Tiller | 14e60e9 | 2015-01-13 17:26:46 -0800 | [diff] [blame] | 43 | #include "test/core/util/test_config.h" |
yang-g | 7b0edbd | 2016-02-02 16:05:21 -0800 | [diff] [blame] | 44 | #include "test/cpp/end2end/test_service_impl.h" |
yang-g | e21908f | 2015-08-25 13:47:51 -0700 | [diff] [blame] | 45 | #include "test/cpp/util/string_ref_helper.h" |
yang-g | 7d2a3e1 | 2016-02-18 15:41:56 -0800 | [diff] [blame] | 46 | #include "test/cpp/util/test_credentials_provider.h" |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 47 | |
Nicolas "Pixel" Noble | 3726e3d | 2017-05-10 18:33:12 +0200 | [diff] [blame] | 48 | #include <gtest/gtest.h> |
| 49 | |
Craig Tiller | 1b4e330 | 2015-12-17 16:35:00 -0800 | [diff] [blame] | 50 | using grpc::testing::EchoRequest; |
| 51 | using grpc::testing::EchoResponse; |
Dan Born | f2f7d57 | 2016-03-03 17:26:12 -0800 | [diff] [blame] | 52 | using grpc::testing::kTlsCredentialsType; |
yangg | ed5e7e0 | 2015-01-06 10:16:15 -0800 | [diff] [blame] | 53 | using std::chrono::system_clock; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 54 | |
| 55 | namespace grpc { |
yangg | ed5e7e0 | 2015-01-06 10:16:15 -0800 | [diff] [blame] | 56 | namespace testing { |
yangg | ed5e7e0 | 2015-01-06 10:16:15 -0800 | [diff] [blame] | 57 | namespace { |
| 58 | |
yang-g | d7ead69 | 2015-07-30 10:57:45 -0700 | [diff] [blame] | 59 | bool CheckIsLocalhost(const grpc::string& addr) { |
| 60 | const grpc::string kIpv6("ipv6:[::1]:"); |
| 61 | const grpc::string kIpv4MappedIpv6("ipv6:[::ffff:127.0.0.1]:"); |
| 62 | const grpc::string kIpv4("ipv4:127.0.0.1:"); |
| 63 | return addr.substr(0, kIpv4.size()) == kIpv4 || |
| 64 | addr.substr(0, kIpv4MappedIpv6.size()) == kIpv4MappedIpv6 || |
| 65 | addr.substr(0, kIpv6.size()) == kIpv6; |
| 66 | } |
| 67 | |
Julien Boeuf | 38c0cde | 2016-06-06 14:46:08 +0200 | [diff] [blame] | 68 | const char kTestCredsPluginErrorMsg[] = "Could not find plugin metadata."; |
| 69 | |
Julien Boeuf | 1928d49 | 2015-09-15 15:20:11 -0700 | [diff] [blame] | 70 | class TestMetadataCredentialsPlugin : public MetadataCredentialsPlugin { |
| 71 | public: |
yang-g | c580af3 | 2016-09-15 15:28:38 -0700 | [diff] [blame] | 72 | static const char kGoodMetadataKey[]; |
| 73 | static const char kBadMetadataKey[]; |
Julien Boeuf | 1928d49 | 2015-09-15 15:20:11 -0700 | [diff] [blame] | 74 | |
yang-g | c580af3 | 2016-09-15 15:28:38 -0700 | [diff] [blame] | 75 | TestMetadataCredentialsPlugin(grpc::string_ref metadata_key, |
| 76 | grpc::string_ref metadata_value, |
Julien Boeuf | 1928d49 | 2015-09-15 15:20:11 -0700 | [diff] [blame] | 77 | bool is_blocking, bool is_successful) |
yang-g | c580af3 | 2016-09-15 15:28:38 -0700 | [diff] [blame] | 78 | : metadata_key_(metadata_key.data(), metadata_key.length()), |
| 79 | metadata_value_(metadata_value.data(), metadata_value.length()), |
Julien Boeuf | 1928d49 | 2015-09-15 15:20:11 -0700 | [diff] [blame] | 80 | is_blocking_(is_blocking), |
| 81 | is_successful_(is_successful) {} |
| 82 | |
Vijay Pai | c0b2acb | 2016-11-01 16:31:56 -0700 | [diff] [blame] | 83 | bool IsBlocking() const override { return is_blocking_; } |
Julien Boeuf | 1928d49 | 2015-09-15 15:20:11 -0700 | [diff] [blame] | 84 | |
Vijay Pai | 713c7b8 | 2016-11-01 16:33:18 -0700 | [diff] [blame] | 85 | Status GetMetadata( |
| 86 | grpc::string_ref service_url, grpc::string_ref method_name, |
| 87 | const grpc::AuthContext& channel_auth_context, |
| 88 | std::multimap<grpc::string, grpc::string>* metadata) override { |
Julien Boeuf | 1928d49 | 2015-09-15 15:20:11 -0700 | [diff] [blame] | 89 | EXPECT_GT(service_url.length(), 0UL); |
Julien Boeuf | 114f394 | 2015-11-19 21:45:52 -0800 | [diff] [blame] | 90 | EXPECT_GT(method_name.length(), 0UL); |
| 91 | EXPECT_TRUE(channel_auth_context.IsPeerAuthenticated()); |
Julien Boeuf | 1928d49 | 2015-09-15 15:20:11 -0700 | [diff] [blame] | 92 | EXPECT_TRUE(metadata != nullptr); |
| 93 | if (is_successful_) { |
yang-g | c580af3 | 2016-09-15 15:28:38 -0700 | [diff] [blame] | 94 | metadata->insert(std::make_pair(metadata_key_, metadata_value_)); |
Julien Boeuf | 1928d49 | 2015-09-15 15:20:11 -0700 | [diff] [blame] | 95 | return Status::OK; |
| 96 | } else { |
Julien Boeuf | 38c0cde | 2016-06-06 14:46:08 +0200 | [diff] [blame] | 97 | return Status(StatusCode::NOT_FOUND, kTestCredsPluginErrorMsg); |
Julien Boeuf | 1928d49 | 2015-09-15 15:20:11 -0700 | [diff] [blame] | 98 | } |
| 99 | } |
| 100 | |
| 101 | private: |
yang-g | c580af3 | 2016-09-15 15:28:38 -0700 | [diff] [blame] | 102 | grpc::string metadata_key_; |
Julien Boeuf | 1928d49 | 2015-09-15 15:20:11 -0700 | [diff] [blame] | 103 | grpc::string metadata_value_; |
| 104 | bool is_blocking_; |
| 105 | bool is_successful_; |
| 106 | }; |
| 107 | |
yang-g | c580af3 | 2016-09-15 15:28:38 -0700 | [diff] [blame] | 108 | const char TestMetadataCredentialsPlugin::kBadMetadataKey[] = |
| 109 | "TestPluginMetadata"; |
| 110 | const char TestMetadataCredentialsPlugin::kGoodMetadataKey[] = |
| 111 | "test-plugin-metadata"; |
Julien Boeuf | 1928d49 | 2015-09-15 15:20:11 -0700 | [diff] [blame] | 112 | |
Julien Boeuf | 0c711ad | 2015-08-28 14:10:58 -0700 | [diff] [blame] | 113 | class TestAuthMetadataProcessor : public AuthMetadataProcessor { |
| 114 | public: |
| 115 | static const char kGoodGuy[]; |
| 116 | |
| 117 | TestAuthMetadataProcessor(bool is_blocking) : is_blocking_(is_blocking) {} |
| 118 | |
Julien Boeuf | e5adc0e | 2015-10-12 14:08:10 -0700 | [diff] [blame] | 119 | std::shared_ptr<CallCredentials> GetCompatibleClientCreds() { |
Julien Boeuf | 1928d49 | 2015-09-15 15:20:11 -0700 | [diff] [blame] | 120 | return MetadataCredentialsFromPlugin( |
| 121 | std::unique_ptr<MetadataCredentialsPlugin>( |
yang-g | c580af3 | 2016-09-15 15:28:38 -0700 | [diff] [blame] | 122 | new TestMetadataCredentialsPlugin( |
| 123 | TestMetadataCredentialsPlugin::kGoodMetadataKey, kGoodGuy, |
| 124 | is_blocking_, true))); |
Julien Boeuf | 0c711ad | 2015-08-28 14:10:58 -0700 | [diff] [blame] | 125 | } |
Julien Boeuf | 1928d49 | 2015-09-15 15:20:11 -0700 | [diff] [blame] | 126 | |
Julien Boeuf | e5adc0e | 2015-10-12 14:08:10 -0700 | [diff] [blame] | 127 | std::shared_ptr<CallCredentials> GetIncompatibleClientCreds() { |
Julien Boeuf | 1928d49 | 2015-09-15 15:20:11 -0700 | [diff] [blame] | 128 | return MetadataCredentialsFromPlugin( |
| 129 | std::unique_ptr<MetadataCredentialsPlugin>( |
yang-g | c580af3 | 2016-09-15 15:28:38 -0700 | [diff] [blame] | 130 | new TestMetadataCredentialsPlugin( |
| 131 | TestMetadataCredentialsPlugin::kGoodMetadataKey, "Mr Hyde", |
| 132 | is_blocking_, true))); |
Julien Boeuf | 0c711ad | 2015-08-28 14:10:58 -0700 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | // Interface implementation |
Vijay Pai | c0b2acb | 2016-11-01 16:31:56 -0700 | [diff] [blame] | 136 | bool IsBlocking() const override { return is_blocking_; } |
Julien Boeuf | 0c711ad | 2015-08-28 14:10:58 -0700 | [diff] [blame] | 137 | |
| 138 | Status Process(const InputMetadata& auth_metadata, AuthContext* context, |
| 139 | OutputMetadata* consumed_auth_metadata, |
Vijay Pai | c0b2acb | 2016-11-01 16:31:56 -0700 | [diff] [blame] | 140 | OutputMetadata* response_metadata) override { |
Julien Boeuf | 0c711ad | 2015-08-28 14:10:58 -0700 | [diff] [blame] | 141 | EXPECT_TRUE(consumed_auth_metadata != nullptr); |
| 142 | EXPECT_TRUE(context != nullptr); |
| 143 | EXPECT_TRUE(response_metadata != nullptr); |
Julien Boeuf | 1928d49 | 2015-09-15 15:20:11 -0700 | [diff] [blame] | 144 | auto auth_md = |
yang-g | c580af3 | 2016-09-15 15:28:38 -0700 | [diff] [blame] | 145 | auth_metadata.find(TestMetadataCredentialsPlugin::kGoodMetadataKey); |
Julien Boeuf | 0c711ad | 2015-08-28 14:10:58 -0700 | [diff] [blame] | 146 | EXPECT_NE(auth_md, auth_metadata.end()); |
| 147 | string_ref auth_md_value = auth_md->second; |
Julien Boeuf | 1928d49 | 2015-09-15 15:20:11 -0700 | [diff] [blame] | 148 | if (auth_md_value == kGoodGuy) { |
Julien Boeuf | 0c711ad | 2015-08-28 14:10:58 -0700 | [diff] [blame] | 149 | context->AddProperty(kIdentityPropName, kGoodGuy); |
| 150 | context->SetPeerIdentityPropertyName(kIdentityPropName); |
Julien Boeuf | 8b0b6f4 | 2015-09-22 13:31:16 -0700 | [diff] [blame] | 151 | consumed_auth_metadata->insert(std::make_pair( |
| 152 | string(auth_md->first.data(), auth_md->first.length()), |
| 153 | string(auth_md->second.data(), auth_md->second.length()))); |
Julien Boeuf | 0c711ad | 2015-08-28 14:10:58 -0700 | [diff] [blame] | 154 | return Status::OK; |
| 155 | } else { |
| 156 | return Status(StatusCode::UNAUTHENTICATED, |
| 157 | string("Invalid principal: ") + |
| 158 | string(auth_md_value.data(), auth_md_value.length())); |
| 159 | } |
| 160 | } |
| 161 | |
Julien Boeuf | 1928d49 | 2015-09-15 15:20:11 -0700 | [diff] [blame] | 162 | private: |
Julien Boeuf | 0c711ad | 2015-08-28 14:10:58 -0700 | [diff] [blame] | 163 | static const char kIdentityPropName[]; |
| 164 | bool is_blocking_; |
| 165 | }; |
| 166 | |
| 167 | const char TestAuthMetadataProcessor::kGoodGuy[] = "Dr Jekyll"; |
| 168 | const char TestAuthMetadataProcessor::kIdentityPropName[] = "novel identity"; |
| 169 | |
Sree Kuchibhotla | 5a05f51 | 2016-01-13 22:43:20 -0800 | [diff] [blame] | 170 | class Proxy : public ::grpc::testing::EchoTestService::Service { |
Craig Tiller | 2c3be1d | 2015-08-05 15:59:27 -0700 | [diff] [blame] | 171 | public: |
yang-g | 8c2be9f | 2015-08-19 16:28:09 -0700 | [diff] [blame] | 172 | Proxy(std::shared_ptr<Channel> channel) |
Sree Kuchibhotla | 5a05f51 | 2016-01-13 22:43:20 -0800 | [diff] [blame] | 173 | : stub_(grpc::testing::EchoTestService::NewStub(channel)) {} |
Craig Tiller | 2c3be1d | 2015-08-05 15:59:27 -0700 | [diff] [blame] | 174 | |
| 175 | Status Echo(ServerContext* server_context, const EchoRequest* request, |
Vijay Pai | c0b2acb | 2016-11-01 16:31:56 -0700 | [diff] [blame] | 176 | EchoResponse* response) override { |
Craig Tiller | 2c3be1d | 2015-08-05 15:59:27 -0700 | [diff] [blame] | 177 | std::unique_ptr<ClientContext> client_context = |
| 178 | ClientContext::FromServerContext(*server_context); |
| 179 | return stub_->Echo(client_context.get(), *request, response); |
| 180 | } |
| 181 | |
| 182 | private: |
Sree Kuchibhotla | 5a05f51 | 2016-01-13 22:43:20 -0800 | [diff] [blame] | 183 | std::unique_ptr< ::grpc::testing::EchoTestService::Stub> stub_; |
Craig Tiller | 2c3be1d | 2015-08-05 15:59:27 -0700 | [diff] [blame] | 184 | }; |
| 185 | |
yangg | 1456d15 | 2015-01-08 15:39:58 -0800 | [diff] [blame] | 186 | class TestServiceImplDupPkg |
Sree Kuchibhotla | 5a05f51 | 2016-01-13 22:43:20 -0800 | [diff] [blame] | 187 | : public ::grpc::testing::duplicate::EchoTestService::Service { |
yangg | 1456d15 | 2015-01-08 15:39:58 -0800 | [diff] [blame] | 188 | public: |
| 189 | Status Echo(ServerContext* context, const EchoRequest* request, |
Vijay Pai | c0b2acb | 2016-11-01 16:31:56 -0700 | [diff] [blame] | 190 | EchoResponse* response) override { |
yangg | 1456d15 | 2015-01-08 15:39:58 -0800 | [diff] [blame] | 191 | response->set_message("no package"); |
| 192 | return Status::OK; |
| 193 | } |
| 194 | }; |
| 195 | |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 196 | class TestScenario { |
| 197 | public: |
Vijay Pai | 3d7d5f4 | 2017-05-04 10:02:24 -0700 | [diff] [blame] | 198 | TestScenario(bool proxy, bool inproc_stub, const grpc::string& creds_type) |
| 199 | : use_proxy(proxy), inproc(inproc_stub), credentials_type(creds_type) {} |
Craig Tiller | 7c70b6c | 2017-01-23 07:48:42 -0800 | [diff] [blame] | 200 | void Log() const; |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 201 | bool use_proxy; |
Vijay Pai | 3d7d5f4 | 2017-05-04 10:02:24 -0700 | [diff] [blame] | 202 | bool inproc; |
Vijay Pai | f063f79 | 2017-10-05 15:41:40 -0700 | [diff] [blame] | 203 | const grpc::string credentials_type; |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 204 | }; |
| 205 | |
Craig Tiller | 7c70b6c | 2017-01-23 07:48:42 -0800 | [diff] [blame] | 206 | static std::ostream& operator<<(std::ostream& out, |
| 207 | const TestScenario& scenario) { |
| 208 | return out << "TestScenario{use_proxy=" |
Vijay Pai | 3d7d5f4 | 2017-05-04 10:02:24 -0700 | [diff] [blame] | 209 | << (scenario.use_proxy ? "true" : "false") |
| 210 | << ", inproc=" << (scenario.inproc ? "true" : "false") |
| 211 | << ", credentials='" << scenario.credentials_type << "'}"; |
Craig Tiller | 7c70b6c | 2017-01-23 07:48:42 -0800 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | void TestScenario::Log() const { |
| 215 | std::ostringstream out; |
| 216 | out << *this; |
| 217 | gpr_log(GPR_DEBUG, "%s", out.str().c_str()); |
| 218 | } |
| 219 | |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 220 | class End2endTest : public ::testing::TestWithParam<TestScenario> { |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 221 | protected: |
Vijay Pai | 181ef45 | 2015-07-14 13:52:48 -0700 | [diff] [blame] | 222 | End2endTest() |
Julien Boeuf | 0c711ad | 2015-08-28 14:10:58 -0700 | [diff] [blame] | 223 | : is_server_started_(false), |
| 224 | kMaxMessageSize_(8192), |
Alexander Polcyn | 7a57b0c | 2017-10-13 17:01:32 -0700 | [diff] [blame] | 225 | special_service_("special"), |
| 226 | first_picked_port_(0) { |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 227 | GetParam().Log(); |
| 228 | } |
Craig Tiller | 7418d01 | 2015-02-11 15:25:03 -0800 | [diff] [blame] | 229 | |
Vijay Pai | c0b2acb | 2016-11-01 16:31:56 -0700 | [diff] [blame] | 230 | void TearDown() override { |
Julien Boeuf | 0c711ad | 2015-08-28 14:10:58 -0700 | [diff] [blame] | 231 | if (is_server_started_) { |
| 232 | server_->Shutdown(); |
| 233 | if (proxy_server_) proxy_server_->Shutdown(); |
| 234 | } |
Alexander Polcyn | 7a57b0c | 2017-10-13 17:01:32 -0700 | [diff] [blame] | 235 | if (first_picked_port_ > 0) { |
| 236 | grpc_recycle_unused_port(first_picked_port_); |
| 237 | } |
Julien Boeuf | 0c711ad | 2015-08-28 14:10:58 -0700 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | void StartServer(const std::shared_ptr<AuthMetadataProcessor>& processor) { |
Craig Tiller | 35e3971 | 2015-01-12 16:41:24 -0800 | [diff] [blame] | 241 | int port = grpc_pick_unused_port_or_die(); |
Alexander Polcyn | 7a57b0c | 2017-10-13 17:01:32 -0700 | [diff] [blame] | 242 | first_picked_port_ = port; |
yang-g | d7ead69 | 2015-07-30 10:57:45 -0700 | [diff] [blame] | 243 | server_address_ << "127.0.0.1:" << port; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 244 | // Setup server |
Yuchen Zeng | ee3e331 | 2017-08-04 13:54:04 -0700 | [diff] [blame] | 245 | BuildAndStartServer(processor); |
| 246 | } |
| 247 | |
| 248 | void RestartServer(const std::shared_ptr<AuthMetadataProcessor>& processor) { |
| 249 | if (is_server_started_) { |
| 250 | server_->Shutdown(); |
| 251 | BuildAndStartServer(processor); |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | void BuildAndStartServer( |
| 256 | const std::shared_ptr<AuthMetadataProcessor>& processor) { |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 257 | ServerBuilder builder; |
Craig Tiller | db1a5cc | 2016-09-28 14:22:12 -0700 | [diff] [blame] | 258 | ConfigureServerBuilder(&builder); |
yang-g | cc59102 | 2017-01-11 11:10:43 -0800 | [diff] [blame] | 259 | auto server_creds = GetCredentialsProvider()->GetServerCredentials( |
| 260 | GetParam().credentials_type); |
yang-g | 17197dd | 2016-02-19 00:04:22 -0800 | [diff] [blame] | 261 | if (GetParam().credentials_type != kInsecureCredentialsType) { |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 262 | server_creds->SetAuthMetadataProcessor(processor); |
| 263 | } |
Julien Boeuf | 0c711ad | 2015-08-28 14:10:58 -0700 | [diff] [blame] | 264 | builder.AddListeningPort(server_address_.str(), server_creds); |
Craig Tiller | f8ac5d8 | 2015-02-09 16:24:20 -0800 | [diff] [blame] | 265 | builder.RegisterService(&service_); |
yang-g | 8b25f2a | 2015-07-21 23:54:36 -0700 | [diff] [blame] | 266 | builder.RegisterService("foo.test.youtube.com", &special_service_); |
Craig Tiller | f8ac5d8 | 2015-02-09 16:24:20 -0800 | [diff] [blame] | 267 | builder.RegisterService(&dup_pkg_service_); |
Sree Kuchibhotla | 892dbf4 | 2016-09-27 19:42:27 -0700 | [diff] [blame] | 268 | |
Sree Kuchibhotla | c37a8a5 | 2016-10-13 15:40:15 -0700 | [diff] [blame] | 269 | builder.SetSyncServerOption(ServerBuilder::SyncServerOption::NUM_CQS, 4); |
| 270 | builder.SetSyncServerOption( |
| 271 | ServerBuilder::SyncServerOption::CQ_TIMEOUT_MSEC, 10); |
Sree Kuchibhotla | 892dbf4 | 2016-09-27 19:42:27 -0700 | [diff] [blame] | 272 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 273 | server_ = builder.BuildAndStart(); |
Julien Boeuf | 0c711ad | 2015-08-28 14:10:58 -0700 | [diff] [blame] | 274 | is_server_started_ = true; |
Craig Tiller | 2c3be1d | 2015-08-05 15:59:27 -0700 | [diff] [blame] | 275 | } |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 276 | |
Craig Tiller | db1a5cc | 2016-09-28 14:22:12 -0700 | [diff] [blame] | 277 | virtual void ConfigureServerBuilder(ServerBuilder* builder) { |
| 278 | builder->SetMaxMessageSize( |
| 279 | kMaxMessageSize_); // For testing max message size. |
| 280 | } |
| 281 | |
yang-g | 9b7757d | 2015-08-13 11:15:53 -0700 | [diff] [blame] | 282 | void ResetChannel() { |
Julien Boeuf | 0c711ad | 2015-08-28 14:10:58 -0700 | [diff] [blame] | 283 | if (!is_server_started_) { |
| 284 | StartServer(std::shared_ptr<AuthMetadataProcessor>()); |
| 285 | } |
| 286 | EXPECT_TRUE(is_server_started_); |
Craig Tiller | 0dc5e6c | 2015-07-10 10:07:53 -0700 | [diff] [blame] | 287 | ChannelArguments args; |
yang-g | cc59102 | 2017-01-11 11:10:43 -0800 | [diff] [blame] | 288 | auto channel_creds = GetCredentialsProvider()->GetChannelCredentials( |
| 289 | GetParam().credentials_type, &args); |
yang-g | d59ad7e | 2016-02-10 12:42:53 -0800 | [diff] [blame] | 290 | if (!user_agent_prefix_.empty()) { |
| 291 | args.SetUserAgentPrefix(user_agent_prefix_); |
| 292 | } |
Craig Tiller | 0dc5e6c | 2015-07-10 10:07:53 -0700 | [diff] [blame] | 293 | args.SetString(GRPC_ARG_SECONDARY_USER_AGENT_STRING, "end2end_test"); |
Vijay Pai | 3d7d5f4 | 2017-05-04 10:02:24 -0700 | [diff] [blame] | 294 | |
| 295 | if (!GetParam().inproc) { |
| 296 | channel_ = |
| 297 | CreateCustomChannel(server_address_.str(), channel_creds, args); |
| 298 | } else { |
| 299 | channel_ = server_->InProcessChannel(args); |
| 300 | } |
yang-g | 9b7757d | 2015-08-13 11:15:53 -0700 | [diff] [blame] | 301 | } |
| 302 | |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 303 | void ResetStub() { |
yang-g | 9b7757d | 2015-08-13 11:15:53 -0700 | [diff] [blame] | 304 | ResetChannel(); |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 305 | if (GetParam().use_proxy) { |
Craig Tiller | 2c3be1d | 2015-08-05 15:59:27 -0700 | [diff] [blame] | 306 | proxy_service_.reset(new Proxy(channel_)); |
| 307 | int port = grpc_pick_unused_port_or_die(); |
| 308 | std::ostringstream proxyaddr; |
| 309 | proxyaddr << "localhost:" << port; |
| 310 | ServerBuilder builder; |
| 311 | builder.AddListeningPort(proxyaddr.str(), InsecureServerCredentials()); |
| 312 | builder.RegisterService(proxy_service_.get()); |
Sree Kuchibhotla | c37a8a5 | 2016-10-13 15:40:15 -0700 | [diff] [blame] | 313 | |
| 314 | builder.SetSyncServerOption(ServerBuilder::SyncServerOption::NUM_CQS, 4); |
| 315 | builder.SetSyncServerOption( |
| 316 | ServerBuilder::SyncServerOption::CQ_TIMEOUT_MSEC, 10); |
Sree Kuchibhotla | 892dbf4 | 2016-09-27 19:42:27 -0700 | [diff] [blame] | 317 | |
Craig Tiller | 2c3be1d | 2015-08-05 15:59:27 -0700 | [diff] [blame] | 318 | proxy_server_ = builder.BuildAndStart(); |
| 319 | |
Julien Boeuf | e5adc0e | 2015-10-12 14:08:10 -0700 | [diff] [blame] | 320 | channel_ = CreateChannel(proxyaddr.str(), InsecureChannelCredentials()); |
Craig Tiller | 2c3be1d | 2015-08-05 15:59:27 -0700 | [diff] [blame] | 321 | } |
| 322 | |
Sree Kuchibhotla | 5a05f51 | 2016-01-13 22:43:20 -0800 | [diff] [blame] | 323 | stub_ = grpc::testing::EchoTestService::NewStub(channel_); |
yangg | 1456d15 | 2015-01-08 15:39:58 -0800 | [diff] [blame] | 324 | } |
| 325 | |
Julien Boeuf | 0c711ad | 2015-08-28 14:10:58 -0700 | [diff] [blame] | 326 | bool is_server_started_; |
yang-g | 8c2be9f | 2015-08-19 16:28:09 -0700 | [diff] [blame] | 327 | std::shared_ptr<Channel> channel_; |
Sree Kuchibhotla | 5a05f51 | 2016-01-13 22:43:20 -0800 | [diff] [blame] | 328 | std::unique_ptr<grpc::testing::EchoTestService::Stub> stub_; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 329 | std::unique_ptr<Server> server_; |
Craig Tiller | 2c3be1d | 2015-08-05 15:59:27 -0700 | [diff] [blame] | 330 | std::unique_ptr<Server> proxy_server_; |
| 331 | std::unique_ptr<Proxy> proxy_service_; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 332 | std::ostringstream server_address_; |
Yang Gao | 3921c56 | 2015-04-30 16:07:06 -0700 | [diff] [blame] | 333 | const int kMaxMessageSize_; |
nnoble | 0c475f0 | 2014-12-05 15:37:39 -0800 | [diff] [blame] | 334 | TestServiceImpl service_; |
Craig Tiller | 822d2c7 | 2015-07-07 16:08:00 -0700 | [diff] [blame] | 335 | TestServiceImpl special_service_; |
yangg | 1456d15 | 2015-01-08 15:39:58 -0800 | [diff] [blame] | 336 | TestServiceImplDupPkg dup_pkg_service_; |
yang-g | d59ad7e | 2016-02-10 12:42:53 -0800 | [diff] [blame] | 337 | grpc::string user_agent_prefix_; |
Alexander Polcyn | 7a57b0c | 2017-10-13 17:01:32 -0700 | [diff] [blame] | 338 | int first_picked_port_; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 339 | }; |
| 340 | |
yang-g | f8174ea | 2016-02-01 00:09:13 -0800 | [diff] [blame] | 341 | static void SendRpc(grpc::testing::EchoTestService::Stub* stub, int num_rpcs, |
| 342 | bool with_binary_metadata) { |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 343 | EchoRequest request; |
| 344 | EchoResponse response; |
David Garcia Quintas | d7d9ce2 | 2015-06-30 23:29:03 -0700 | [diff] [blame] | 345 | request.set_message("Hello hello hello hello"); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 346 | |
| 347 | for (int i = 0; i < num_rpcs; ++i) { |
| 348 | ClientContext context; |
yang-g | f8174ea | 2016-02-01 00:09:13 -0800 | [diff] [blame] | 349 | if (with_binary_metadata) { |
| 350 | char bytes[8] = {'\0', '\1', '\2', '\3', '\4', '\5', '\6', (char)i}; |
| 351 | context.AddMetadata("custom-bin", grpc::string(bytes, 8)); |
| 352 | } |
Muxi Yan | 8fa4d15 | 2017-09-26 09:53:55 -0700 | [diff] [blame] | 353 | context.set_compression_algorithm(GRPC_COMPRESS_MESSAGE_GZIP); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 354 | Status s = stub->Echo(&context, request, &response); |
| 355 | EXPECT_EQ(response.message(), request.message()); |
Yang Gao | c1a2c31 | 2015-06-16 10:59:46 -0700 | [diff] [blame] | 356 | EXPECT_TRUE(s.ok()); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 357 | } |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 358 | } |
| 359 | |
Sree Kuchibhotla | 0f242ac | 2016-01-29 18:12:19 -0800 | [diff] [blame] | 360 | // This class is for testing scenarios where RPCs are cancelled on the server |
| 361 | // by calling ServerContext::TryCancel() |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 362 | class End2endServerTryCancelTest : public End2endTest { |
| 363 | protected: |
Sree Kuchibhotla | 0f242ac | 2016-01-29 18:12:19 -0800 | [diff] [blame] | 364 | // Helper for testing client-streaming RPCs which are cancelled on the server. |
| 365 | // Depending on the value of server_try_cancel parameter, this will test one |
| 366 | // of the following three scenarios: |
| 367 | // CANCEL_BEFORE_PROCESSING: Rpc is cancelled by the server before reading |
| 368 | // any messages from the client |
| 369 | // |
| 370 | // CANCEL_DURING_PROCESSING: Rpc is cancelled by the server while reading |
| 371 | // messages from the client |
| 372 | // |
| 373 | // CANCEL_AFTER PROCESSING: Rpc is cancelled by server after reading all |
| 374 | // the messages from the client |
| 375 | // |
| 376 | // NOTE: Do not call this function with server_try_cancel == DO_NOT_CANCEL. |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 377 | void TestRequestStreamServerCancel( |
| 378 | ServerTryCancelRequestPhase server_try_cancel, int num_msgs_to_send) { |
| 379 | ResetStub(); |
| 380 | EchoRequest request; |
| 381 | EchoResponse response; |
| 382 | ClientContext context; |
| 383 | |
Sree Kuchibhotla | 0f242ac | 2016-01-29 18:12:19 -0800 | [diff] [blame] | 384 | // Send server_try_cancel value in the client metadata |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 385 | context.AddMetadata(kServerTryCancelRequest, |
Vijay Pai | a63271c | 2016-06-15 12:56:38 -0700 | [diff] [blame] | 386 | grpc::to_string(server_try_cancel)); |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 387 | |
| 388 | auto stream = stub_->RequestStream(&context, &response); |
Sree Kuchibhotla | 0f242ac | 2016-01-29 18:12:19 -0800 | [diff] [blame] | 389 | |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 390 | int num_msgs_sent = 0; |
| 391 | while (num_msgs_sent < num_msgs_to_send) { |
| 392 | request.set_message("hello"); |
| 393 | if (!stream->Write(request)) { |
| 394 | break; |
| 395 | } |
| 396 | num_msgs_sent++; |
| 397 | } |
| 398 | gpr_log(GPR_INFO, "Sent %d messages", num_msgs_sent); |
Sree Kuchibhotla | 0f242ac | 2016-01-29 18:12:19 -0800 | [diff] [blame] | 399 | |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 400 | stream->WritesDone(); |
| 401 | Status s = stream->Finish(); |
| 402 | |
Sree Kuchibhotla | 0f242ac | 2016-01-29 18:12:19 -0800 | [diff] [blame] | 403 | // At this point, we know for sure that RPC was cancelled by the server |
| 404 | // since we passed server_try_cancel value in the metadata. Depending on the |
| 405 | // value of server_try_cancel, the RPC might have been cancelled by the |
| 406 | // server at different stages. The following validates our expectations of |
| 407 | // number of messages sent in various cancellation scenarios: |
| 408 | |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 409 | switch (server_try_cancel) { |
| 410 | case CANCEL_BEFORE_PROCESSING: |
| 411 | case CANCEL_DURING_PROCESSING: |
Sree Kuchibhotla | 0f242ac | 2016-01-29 18:12:19 -0800 | [diff] [blame] | 412 | // If the RPC is cancelled by server before / during messages from the |
| 413 | // client, it means that the client most likely did not get a chance to |
| 414 | // send all the messages it wanted to send. i.e num_msgs_sent <= |
| 415 | // num_msgs_to_send |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 416 | EXPECT_LE(num_msgs_sent, num_msgs_to_send); |
| 417 | break; |
Sree Kuchibhotla | 0f242ac | 2016-01-29 18:12:19 -0800 | [diff] [blame] | 418 | |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 419 | case CANCEL_AFTER_PROCESSING: |
Sree Kuchibhotla | 0f242ac | 2016-01-29 18:12:19 -0800 | [diff] [blame] | 420 | // If the RPC was cancelled after all messages were read by the server, |
| 421 | // the client did get a chance to send all its messages |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 422 | EXPECT_EQ(num_msgs_sent, num_msgs_to_send); |
| 423 | break; |
Sree Kuchibhotla | 0f242ac | 2016-01-29 18:12:19 -0800 | [diff] [blame] | 424 | |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 425 | default: |
| 426 | gpr_log(GPR_ERROR, "Invalid server_try_cancel value: %d", |
| 427 | server_try_cancel); |
| 428 | EXPECT_TRUE(server_try_cancel > DO_NOT_CANCEL && |
| 429 | server_try_cancel <= CANCEL_AFTER_PROCESSING); |
| 430 | break; |
| 431 | } |
| 432 | |
| 433 | EXPECT_FALSE(s.ok()); |
| 434 | EXPECT_EQ(grpc::StatusCode::CANCELLED, s.error_code()); |
| 435 | } |
| 436 | |
Sree Kuchibhotla | 0f242ac | 2016-01-29 18:12:19 -0800 | [diff] [blame] | 437 | // Helper for testing server-streaming RPCs which are cancelled on the server. |
| 438 | // Depending on the value of server_try_cancel parameter, this will test one |
| 439 | // of the following three scenarios: |
| 440 | // CANCEL_BEFORE_PROCESSING: Rpc is cancelled by the server before writing |
| 441 | // any messages to the client |
| 442 | // |
| 443 | // CANCEL_DURING_PROCESSING: Rpc is cancelled by the server while writing |
| 444 | // messages to the client |
| 445 | // |
| 446 | // CANCEL_AFTER PROCESSING: Rpc is cancelled by server after writing all |
| 447 | // the messages to the client |
| 448 | // |
| 449 | // NOTE: Do not call this function with server_try_cancel == DO_NOT_CANCEL. |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 450 | void TestResponseStreamServerCancel( |
| 451 | ServerTryCancelRequestPhase server_try_cancel) { |
| 452 | ResetStub(); |
| 453 | EchoRequest request; |
| 454 | EchoResponse response; |
| 455 | ClientContext context; |
| 456 | |
Sree Kuchibhotla | 0f242ac | 2016-01-29 18:12:19 -0800 | [diff] [blame] | 457 | // Send server_try_cancel in the client metadata |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 458 | context.AddMetadata(kServerTryCancelRequest, |
Vijay Pai | a63271c | 2016-06-15 12:56:38 -0700 | [diff] [blame] | 459 | grpc::to_string(server_try_cancel)); |
Sree Kuchibhotla | 0f242ac | 2016-01-29 18:12:19 -0800 | [diff] [blame] | 460 | |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 461 | request.set_message("hello"); |
| 462 | auto stream = stub_->ResponseStream(&context, request); |
| 463 | |
| 464 | int num_msgs_read = 0; |
ncteisen | 9bee308 | 2017-06-20 12:30:24 -0700 | [diff] [blame] | 465 | while (num_msgs_read < kServerDefaultResponseStreamsToSend) { |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 466 | if (!stream->Read(&response)) { |
| 467 | break; |
| 468 | } |
| 469 | EXPECT_EQ(response.message(), |
Vijay Pai | a63271c | 2016-06-15 12:56:38 -0700 | [diff] [blame] | 470 | request.message() + grpc::to_string(num_msgs_read)); |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 471 | num_msgs_read++; |
| 472 | } |
| 473 | gpr_log(GPR_INFO, "Read %d messages", num_msgs_read); |
| 474 | |
| 475 | Status s = stream->Finish(); |
| 476 | |
Sree Kuchibhotla | 0f242ac | 2016-01-29 18:12:19 -0800 | [diff] [blame] | 477 | // Depending on the value of server_try_cancel, the RPC might have been |
| 478 | // cancelled by the server at different stages. The following validates our |
| 479 | // expectations of number of messages read in various cancellation |
| 480 | // scenarios: |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 481 | switch (server_try_cancel) { |
Sree Kuchibhotla | 0f242ac | 2016-01-29 18:12:19 -0800 | [diff] [blame] | 482 | case CANCEL_BEFORE_PROCESSING: |
| 483 | // Server cancelled before sending any messages. Which means the client |
| 484 | // wouldn't have read any |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 485 | EXPECT_EQ(num_msgs_read, 0); |
| 486 | break; |
Sree Kuchibhotla | 0f242ac | 2016-01-29 18:12:19 -0800 | [diff] [blame] | 487 | |
| 488 | case CANCEL_DURING_PROCESSING: |
| 489 | // Server cancelled while writing messages. Client must have read less |
| 490 | // than or equal to the expected number of messages |
ncteisen | 9bee308 | 2017-06-20 12:30:24 -0700 | [diff] [blame] | 491 | EXPECT_LE(num_msgs_read, kServerDefaultResponseStreamsToSend); |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 492 | break; |
Sree Kuchibhotla | 0f242ac | 2016-01-29 18:12:19 -0800 | [diff] [blame] | 493 | |
| 494 | case CANCEL_AFTER_PROCESSING: |
Sree Kuchibhotla | 8d543e8 | 2016-02-29 18:22:25 -0800 | [diff] [blame] | 495 | // Even though the Server cancelled after writing all messages, the RPC |
| 496 | // may be cancelled before the Client got a chance to read all the |
| 497 | // messages. |
ncteisen | 9bee308 | 2017-06-20 12:30:24 -0700 | [diff] [blame] | 498 | EXPECT_LE(num_msgs_read, kServerDefaultResponseStreamsToSend); |
Sree Kuchibhotla | 0f242ac | 2016-01-29 18:12:19 -0800 | [diff] [blame] | 499 | break; |
| 500 | |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 501 | default: { |
| 502 | gpr_log(GPR_ERROR, "Invalid server_try_cancel value: %d", |
| 503 | server_try_cancel); |
| 504 | EXPECT_TRUE(server_try_cancel > DO_NOT_CANCEL && |
| 505 | server_try_cancel <= CANCEL_AFTER_PROCESSING); |
| 506 | break; |
| 507 | } |
| 508 | } |
| 509 | |
| 510 | EXPECT_FALSE(s.ok()); |
| 511 | EXPECT_EQ(grpc::StatusCode::CANCELLED, s.error_code()); |
| 512 | } |
| 513 | |
Sree Kuchibhotla | 0f242ac | 2016-01-29 18:12:19 -0800 | [diff] [blame] | 514 | // Helper for testing bidirectional-streaming RPCs which are cancelled on the |
| 515 | // server. Depending on the value of server_try_cancel parameter, this will |
| 516 | // test one of the following three scenarios: |
| 517 | // CANCEL_BEFORE_PROCESSING: Rpc is cancelled by the server before reading/ |
| 518 | // writing any messages from/to the client |
| 519 | // |
| 520 | // CANCEL_DURING_PROCESSING: Rpc is cancelled by the server while reading/ |
| 521 | // writing messages from/to the client |
| 522 | // |
| 523 | // CANCEL_AFTER PROCESSING: Rpc is cancelled by server after reading/writing |
| 524 | // all the messages from/to the client |
| 525 | // |
| 526 | // NOTE: Do not call this function with server_try_cancel == DO_NOT_CANCEL. |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 527 | void TestBidiStreamServerCancel(ServerTryCancelRequestPhase server_try_cancel, |
| 528 | int num_messages) { |
| 529 | ResetStub(); |
| 530 | EchoRequest request; |
| 531 | EchoResponse response; |
| 532 | ClientContext context; |
| 533 | |
Sree Kuchibhotla | 0f242ac | 2016-01-29 18:12:19 -0800 | [diff] [blame] | 534 | // Send server_try_cancel in the client metadata |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 535 | context.AddMetadata(kServerTryCancelRequest, |
Vijay Pai | a63271c | 2016-06-15 12:56:38 -0700 | [diff] [blame] | 536 | grpc::to_string(server_try_cancel)); |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 537 | |
| 538 | auto stream = stub_->BidiStream(&context); |
| 539 | |
| 540 | int num_msgs_read = 0; |
| 541 | int num_msgs_sent = 0; |
| 542 | while (num_msgs_sent < num_messages) { |
Vijay Pai | a63271c | 2016-06-15 12:56:38 -0700 | [diff] [blame] | 543 | request.set_message("hello " + grpc::to_string(num_msgs_sent)); |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 544 | if (!stream->Write(request)) { |
| 545 | break; |
| 546 | } |
| 547 | num_msgs_sent++; |
| 548 | |
| 549 | if (!stream->Read(&response)) { |
| 550 | break; |
| 551 | } |
| 552 | num_msgs_read++; |
| 553 | |
| 554 | EXPECT_EQ(response.message(), request.message()); |
| 555 | } |
| 556 | gpr_log(GPR_INFO, "Sent %d messages", num_msgs_sent); |
| 557 | gpr_log(GPR_INFO, "Read %d messages", num_msgs_read); |
| 558 | |
| 559 | stream->WritesDone(); |
| 560 | Status s = stream->Finish(); |
| 561 | |
Sree Kuchibhotla | 0f242ac | 2016-01-29 18:12:19 -0800 | [diff] [blame] | 562 | // Depending on the value of server_try_cancel, the RPC might have been |
| 563 | // cancelled by the server at different stages. The following validates our |
| 564 | // expectations of number of messages read in various cancellation |
| 565 | // scenarios: |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 566 | switch (server_try_cancel) { |
Sree Kuchibhotla | 0f242ac | 2016-01-29 18:12:19 -0800 | [diff] [blame] | 567 | case CANCEL_BEFORE_PROCESSING: |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 568 | EXPECT_EQ(num_msgs_read, 0); |
| 569 | break; |
Sree Kuchibhotla | 0f242ac | 2016-01-29 18:12:19 -0800 | [diff] [blame] | 570 | |
| 571 | case CANCEL_DURING_PROCESSING: |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 572 | EXPECT_LE(num_msgs_sent, num_messages); |
| 573 | EXPECT_LE(num_msgs_read, num_msgs_sent); |
| 574 | break; |
Sree Kuchibhotla | 0f242ac | 2016-01-29 18:12:19 -0800 | [diff] [blame] | 575 | |
| 576 | case CANCEL_AFTER_PROCESSING: |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 577 | EXPECT_EQ(num_msgs_sent, num_messages); |
Sree Kuchibhotla | 8d543e8 | 2016-02-29 18:22:25 -0800 | [diff] [blame] | 578 | |
| 579 | // The Server cancelled after reading the last message and after writing |
| 580 | // the message to the client. However, the RPC cancellation might have |
| 581 | // taken effect before the client actually read the response. |
| 582 | EXPECT_LE(num_msgs_read, num_msgs_sent); |
Sree Kuchibhotla | 0f242ac | 2016-01-29 18:12:19 -0800 | [diff] [blame] | 583 | break; |
| 584 | |
| 585 | default: |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 586 | gpr_log(GPR_ERROR, "Invalid server_try_cancel value: %d", |
| 587 | server_try_cancel); |
| 588 | EXPECT_TRUE(server_try_cancel > DO_NOT_CANCEL && |
| 589 | server_try_cancel <= CANCEL_AFTER_PROCESSING); |
| 590 | break; |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | EXPECT_FALSE(s.ok()); |
| 594 | EXPECT_EQ(grpc::StatusCode::CANCELLED, s.error_code()); |
| 595 | } |
| 596 | }; |
| 597 | |
| 598 | TEST_P(End2endServerTryCancelTest, RequestEchoServerCancel) { |
| 599 | ResetStub(); |
| 600 | EchoRequest request; |
| 601 | EchoResponse response; |
| 602 | ClientContext context; |
| 603 | |
| 604 | context.AddMetadata(kServerTryCancelRequest, |
Vijay Pai | a63271c | 2016-06-15 12:56:38 -0700 | [diff] [blame] | 605 | grpc::to_string(CANCEL_BEFORE_PROCESSING)); |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 606 | Status s = stub_->Echo(&context, request, &response); |
| 607 | EXPECT_FALSE(s.ok()); |
| 608 | EXPECT_EQ(grpc::StatusCode::CANCELLED, s.error_code()); |
| 609 | } |
| 610 | |
| 611 | // Server to cancel before doing reading the request |
| 612 | TEST_P(End2endServerTryCancelTest, RequestStreamServerCancelBeforeReads) { |
| 613 | TestRequestStreamServerCancel(CANCEL_BEFORE_PROCESSING, 1); |
| 614 | } |
| 615 | |
| 616 | // Server to cancel while reading a request from the stream in parallel |
| 617 | TEST_P(End2endServerTryCancelTest, RequestStreamServerCancelDuringRead) { |
| 618 | TestRequestStreamServerCancel(CANCEL_DURING_PROCESSING, 10); |
| 619 | } |
| 620 | |
| 621 | // Server to cancel after reading all the requests but before returning to the |
| 622 | // client |
| 623 | TEST_P(End2endServerTryCancelTest, RequestStreamServerCancelAfterReads) { |
| 624 | TestRequestStreamServerCancel(CANCEL_AFTER_PROCESSING, 4); |
| 625 | } |
| 626 | |
| 627 | // Server to cancel before sending any response messages |
| 628 | TEST_P(End2endServerTryCancelTest, ResponseStreamServerCancelBefore) { |
| 629 | TestResponseStreamServerCancel(CANCEL_BEFORE_PROCESSING); |
| 630 | } |
| 631 | |
| 632 | // Server to cancel while writing a response to the stream in parallel |
| 633 | TEST_P(End2endServerTryCancelTest, ResponseStreamServerCancelDuring) { |
| 634 | TestResponseStreamServerCancel(CANCEL_DURING_PROCESSING); |
| 635 | } |
| 636 | |
| 637 | // Server to cancel after writing all the respones to the stream but before |
| 638 | // returning to the client |
| 639 | TEST_P(End2endServerTryCancelTest, ResponseStreamServerCancelAfter) { |
| 640 | TestResponseStreamServerCancel(CANCEL_AFTER_PROCESSING); |
| 641 | } |
| 642 | |
| 643 | // Server to cancel before reading/writing any requests/responses on the stream |
| 644 | TEST_P(End2endServerTryCancelTest, BidiStreamServerCancelBefore) { |
| 645 | TestBidiStreamServerCancel(CANCEL_BEFORE_PROCESSING, 2); |
| 646 | } |
| 647 | |
| 648 | // Server to cancel while reading/writing requests/responses on the stream in |
| 649 | // parallel |
| 650 | TEST_P(End2endServerTryCancelTest, BidiStreamServerCancelDuring) { |
| 651 | TestBidiStreamServerCancel(CANCEL_DURING_PROCESSING, 10); |
| 652 | } |
| 653 | |
| 654 | // Server to cancel after reading/writing all requests/responses on the stream |
| 655 | // but before returning to the client |
| 656 | TEST_P(End2endServerTryCancelTest, BidiStreamServerCancelAfter) { |
| 657 | TestBidiStreamServerCancel(CANCEL_AFTER_PROCESSING, 5); |
| 658 | } |
| 659 | |
Craig Tiller | 7c70b6c | 2017-01-23 07:48:42 -0800 | [diff] [blame] | 660 | TEST_P(End2endTest, SimpleRpcWithCustomUserAgentPrefix) { |
Vijay Pai | 3d7d5f4 | 2017-05-04 10:02:24 -0700 | [diff] [blame] | 661 | // User-Agent is an HTTP header for HTTP transports only |
| 662 | if (GetParam().inproc) { |
| 663 | return; |
| 664 | } |
yang-g | d59ad7e | 2016-02-10 12:42:53 -0800 | [diff] [blame] | 665 | user_agent_prefix_ = "custom_prefix"; |
| 666 | ResetStub(); |
| 667 | EchoRequest request; |
| 668 | EchoResponse response; |
| 669 | request.set_message("Hello hello hello hello"); |
| 670 | request.mutable_param()->set_echo_metadata(true); |
| 671 | |
| 672 | ClientContext context; |
| 673 | Status s = stub_->Echo(&context, request, &response); |
| 674 | EXPECT_EQ(response.message(), request.message()); |
| 675 | EXPECT_TRUE(s.ok()); |
| 676 | const auto& trailing_metadata = context.GetServerTrailingMetadata(); |
| 677 | auto iter = trailing_metadata.find("user-agent"); |
| 678 | EXPECT_TRUE(iter != trailing_metadata.end()); |
| 679 | grpc::string expected_prefix = user_agent_prefix_ + " grpc-c++/"; |
Mark D. Roth | e3a2100 | 2016-10-24 13:29:05 -0700 | [diff] [blame] | 680 | EXPECT_TRUE(iter->second.starts_with(expected_prefix)) << iter->second; |
yang-g | d59ad7e | 2016-02-10 12:42:53 -0800 | [diff] [blame] | 681 | } |
| 682 | |
yang-g | f8174ea | 2016-02-01 00:09:13 -0800 | [diff] [blame] | 683 | TEST_P(End2endTest, MultipleRpcsWithVariedBinaryMetadataValue) { |
| 684 | ResetStub(); |
Vijay Pai | b0a6be2 | 2016-11-03 12:45:02 -0700 | [diff] [blame] | 685 | std::vector<std::thread> threads; |
yang-g | f8174ea | 2016-02-01 00:09:13 -0800 | [diff] [blame] | 686 | for (int i = 0; i < 10; ++i) { |
Vijay Pai | b0a6be2 | 2016-11-03 12:45:02 -0700 | [diff] [blame] | 687 | threads.emplace_back(SendRpc, stub_.get(), 10, true); |
yang-g | f8174ea | 2016-02-01 00:09:13 -0800 | [diff] [blame] | 688 | } |
| 689 | for (int i = 0; i < 10; ++i) { |
Vijay Pai | b0a6be2 | 2016-11-03 12:45:02 -0700 | [diff] [blame] | 690 | threads[i].join(); |
yang-g | f8174ea | 2016-02-01 00:09:13 -0800 | [diff] [blame] | 691 | } |
| 692 | } |
| 693 | |
| 694 | TEST_P(End2endTest, MultipleRpcs) { |
| 695 | ResetStub(); |
Vijay Pai | b0a6be2 | 2016-11-03 12:45:02 -0700 | [diff] [blame] | 696 | std::vector<std::thread> threads; |
yang-g | f8174ea | 2016-02-01 00:09:13 -0800 | [diff] [blame] | 697 | for (int i = 0; i < 10; ++i) { |
Vijay Pai | b0a6be2 | 2016-11-03 12:45:02 -0700 | [diff] [blame] | 698 | threads.emplace_back(SendRpc, stub_.get(), 10, false); |
yang-g | f8174ea | 2016-02-01 00:09:13 -0800 | [diff] [blame] | 699 | } |
| 700 | for (int i = 0; i < 10; ++i) { |
Vijay Pai | b0a6be2 | 2016-11-03 12:45:02 -0700 | [diff] [blame] | 701 | threads[i].join(); |
yang-g | f8174ea | 2016-02-01 00:09:13 -0800 | [diff] [blame] | 702 | } |
| 703 | } |
| 704 | |
Yuchen Zeng | ee3e331 | 2017-08-04 13:54:04 -0700 | [diff] [blame] | 705 | TEST_P(End2endTest, ReconnectChannel) { |
| 706 | if (GetParam().inproc) { |
| 707 | return; |
| 708 | } |
Yuchen Zeng | 7fa814f | 2017-10-15 19:00:16 -0700 | [diff] [blame] | 709 | int poller_slowdown_factor = 1; |
| 710 | // It needs 2 pollset_works to reconnect the channel with polling engine |
| 711 | // "poll" |
| 712 | char* s = gpr_getenv("GRPC_POLL_STRATEGY"); |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 713 | if (s != nullptr && 0 == strcmp(s, "poll")) { |
Yuchen Zeng | 7fa814f | 2017-10-15 19:00:16 -0700 | [diff] [blame] | 714 | poller_slowdown_factor = 2; |
| 715 | } |
| 716 | gpr_free(s); |
Yuchen Zeng | ee3e331 | 2017-08-04 13:54:04 -0700 | [diff] [blame] | 717 | ResetStub(); |
| 718 | SendRpc(stub_.get(), 1, false); |
| 719 | RestartServer(std::shared_ptr<AuthMetadataProcessor>()); |
Yuchen Zeng | cbb9296 | 2017-10-18 11:47:10 -0700 | [diff] [blame] | 720 | // It needs more than GRPC_CLIENT_CHANNEL_BACKUP_POLL_INTERVAL_MS time to |
| 721 | // reconnect the channel. |
Yuchen Zeng | 0bad30a | 2017-10-05 21:47:39 -0700 | [diff] [blame] | 722 | gpr_sleep_until(gpr_time_add( |
| 723 | gpr_now(GPR_CLOCK_REALTIME), |
Yuchen Zeng | 7fa814f | 2017-10-15 19:00:16 -0700 | [diff] [blame] | 724 | gpr_time_from_millis( |
Yuchen Zeng | cbb9296 | 2017-10-18 11:47:10 -0700 | [diff] [blame] | 725 | 300 * poller_slowdown_factor * grpc_test_slowdown_factor(), |
Yuchen Zeng | 7fa814f | 2017-10-15 19:00:16 -0700 | [diff] [blame] | 726 | GPR_TIMESPAN))); |
Yuchen Zeng | ee3e331 | 2017-08-04 13:54:04 -0700 | [diff] [blame] | 727 | SendRpc(stub_.get(), 1, false); |
| 728 | } |
| 729 | |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 730 | TEST_P(End2endTest, RequestStreamOneRequest) { |
| 731 | ResetStub(); |
nnoble | 0c475f0 | 2014-12-05 15:37:39 -0800 | [diff] [blame] | 732 | EchoRequest request; |
| 733 | EchoResponse response; |
| 734 | ClientContext context; |
| 735 | |
Craig Tiller | fd1b49b | 2015-02-23 12:53:39 -0800 | [diff] [blame] | 736 | auto stream = stub_->RequestStream(&context, &response); |
nnoble | 0c475f0 | 2014-12-05 15:37:39 -0800 | [diff] [blame] | 737 | request.set_message("hello"); |
| 738 | EXPECT_TRUE(stream->Write(request)); |
| 739 | stream->WritesDone(); |
Craig Tiller | f8ac5d8 | 2015-02-09 16:24:20 -0800 | [diff] [blame] | 740 | Status s = stream->Finish(); |
nnoble | 0c475f0 | 2014-12-05 15:37:39 -0800 | [diff] [blame] | 741 | EXPECT_EQ(response.message(), request.message()); |
Yang Gao | c1a2c31 | 2015-06-16 10:59:46 -0700 | [diff] [blame] | 742 | EXPECT_TRUE(s.ok()); |
ncteisen | 6193c63 | 2017-12-08 10:49:31 -0800 | [diff] [blame] | 743 | EXPECT_TRUE(context.debug_error_string().empty()); |
nnoble | 0c475f0 | 2014-12-05 15:37:39 -0800 | [diff] [blame] | 744 | } |
| 745 | |
Yuxuan Li | 34894e4 | 2017-02-08 17:57:24 -0800 | [diff] [blame] | 746 | TEST_P(End2endTest, RequestStreamOneRequestWithCoalescingApi) { |
| 747 | ResetStub(); |
| 748 | EchoRequest request; |
| 749 | EchoResponse response; |
| 750 | ClientContext context; |
| 751 | |
Yuxuan Li | bdc76ab | 2017-03-03 13:59:30 -0800 | [diff] [blame] | 752 | context.set_initial_metadata_corked(true); |
Yuxuan Li | 34894e4 | 2017-02-08 17:57:24 -0800 | [diff] [blame] | 753 | auto stream = stub_->RequestStream(&context, &response); |
| 754 | request.set_message("hello"); |
| 755 | stream->WriteLast(request, WriteOptions()); |
| 756 | Status s = stream->Finish(); |
| 757 | EXPECT_EQ(response.message(), request.message()); |
| 758 | EXPECT_TRUE(s.ok()); |
| 759 | } |
| 760 | |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 761 | TEST_P(End2endTest, RequestStreamTwoRequests) { |
| 762 | ResetStub(); |
nnoble | 0c475f0 | 2014-12-05 15:37:39 -0800 | [diff] [blame] | 763 | EchoRequest request; |
| 764 | EchoResponse response; |
| 765 | ClientContext context; |
| 766 | |
Craig Tiller | fd1b49b | 2015-02-23 12:53:39 -0800 | [diff] [blame] | 767 | auto stream = stub_->RequestStream(&context, &response); |
nnoble | 0c475f0 | 2014-12-05 15:37:39 -0800 | [diff] [blame] | 768 | request.set_message("hello"); |
| 769 | EXPECT_TRUE(stream->Write(request)); |
| 770 | EXPECT_TRUE(stream->Write(request)); |
| 771 | stream->WritesDone(); |
Craig Tiller | f8ac5d8 | 2015-02-09 16:24:20 -0800 | [diff] [blame] | 772 | Status s = stream->Finish(); |
nnoble | 0c475f0 | 2014-12-05 15:37:39 -0800 | [diff] [blame] | 773 | EXPECT_EQ(response.message(), "hellohello"); |
Yang Gao | c1a2c31 | 2015-06-16 10:59:46 -0700 | [diff] [blame] | 774 | EXPECT_TRUE(s.ok()); |
nnoble | 0c475f0 | 2014-12-05 15:37:39 -0800 | [diff] [blame] | 775 | } |
| 776 | |
Craig Tiller | 9bebf8b | 2017-09-01 10:20:13 -0700 | [diff] [blame] | 777 | TEST_P(End2endTest, RequestStreamTwoRequestsWithWriteThrough) { |
| 778 | ResetStub(); |
| 779 | EchoRequest request; |
| 780 | EchoResponse response; |
| 781 | ClientContext context; |
| 782 | |
| 783 | auto stream = stub_->RequestStream(&context, &response); |
| 784 | request.set_message("hello"); |
| 785 | EXPECT_TRUE(stream->Write(request, WriteOptions().set_write_through())); |
| 786 | EXPECT_TRUE(stream->Write(request, WriteOptions().set_write_through())); |
| 787 | stream->WritesDone(); |
| 788 | Status s = stream->Finish(); |
| 789 | EXPECT_EQ(response.message(), "hellohello"); |
| 790 | EXPECT_TRUE(s.ok()); |
| 791 | } |
| 792 | |
Yuxuan Li | 34894e4 | 2017-02-08 17:57:24 -0800 | [diff] [blame] | 793 | TEST_P(End2endTest, RequestStreamTwoRequestsWithCoalescingApi) { |
| 794 | ResetStub(); |
| 795 | EchoRequest request; |
| 796 | EchoResponse response; |
| 797 | ClientContext context; |
| 798 | |
Yuxuan Li | bdc76ab | 2017-03-03 13:59:30 -0800 | [diff] [blame] | 799 | context.set_initial_metadata_corked(true); |
Yuxuan Li | 34894e4 | 2017-02-08 17:57:24 -0800 | [diff] [blame] | 800 | auto stream = stub_->RequestStream(&context, &response); |
| 801 | request.set_message("hello"); |
| 802 | EXPECT_TRUE(stream->Write(request)); |
| 803 | stream->WriteLast(request, WriteOptions()); |
| 804 | Status s = stream->Finish(); |
| 805 | EXPECT_EQ(response.message(), "hellohello"); |
| 806 | EXPECT_TRUE(s.ok()); |
| 807 | } |
| 808 | |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 809 | TEST_P(End2endTest, ResponseStream) { |
| 810 | ResetStub(); |
nnoble | 0c475f0 | 2014-12-05 15:37:39 -0800 | [diff] [blame] | 811 | EchoRequest request; |
| 812 | EchoResponse response; |
| 813 | ClientContext context; |
| 814 | request.set_message("hello"); |
| 815 | |
Craig Tiller | fd1b49b | 2015-02-23 12:53:39 -0800 | [diff] [blame] | 816 | auto stream = stub_->ResponseStream(&context, request); |
ncteisen | 9bee308 | 2017-06-20 12:30:24 -0700 | [diff] [blame] | 817 | for (int i = 0; i < kServerDefaultResponseStreamsToSend; ++i) { |
| 818 | EXPECT_TRUE(stream->Read(&response)); |
| 819 | EXPECT_EQ(response.message(), request.message() + grpc::to_string(i)); |
| 820 | } |
nnoble | 0c475f0 | 2014-12-05 15:37:39 -0800 | [diff] [blame] | 821 | EXPECT_FALSE(stream->Read(&response)); |
| 822 | |
Craig Tiller | 4d0fb5f | 2015-02-09 16:27:22 -0800 | [diff] [blame] | 823 | Status s = stream->Finish(); |
Yang Gao | c1a2c31 | 2015-06-16 10:59:46 -0700 | [diff] [blame] | 824 | EXPECT_TRUE(s.ok()); |
nnoble | 0c475f0 | 2014-12-05 15:37:39 -0800 | [diff] [blame] | 825 | } |
| 826 | |
Yuxuan Li | 34894e4 | 2017-02-08 17:57:24 -0800 | [diff] [blame] | 827 | TEST_P(End2endTest, ResponseStreamWithCoalescingApi) { |
| 828 | ResetStub(); |
| 829 | EchoRequest request; |
| 830 | EchoResponse response; |
| 831 | ClientContext context; |
| 832 | request.set_message("hello"); |
| 833 | context.AddMetadata(kServerUseCoalescingApi, "1"); |
| 834 | |
| 835 | auto stream = stub_->ResponseStream(&context, request); |
ncteisen | 9bee308 | 2017-06-20 12:30:24 -0700 | [diff] [blame] | 836 | for (int i = 0; i < kServerDefaultResponseStreamsToSend; ++i) { |
| 837 | EXPECT_TRUE(stream->Read(&response)); |
| 838 | EXPECT_EQ(response.message(), request.message() + grpc::to_string(i)); |
| 839 | } |
Yuxuan Li | 34894e4 | 2017-02-08 17:57:24 -0800 | [diff] [blame] | 840 | EXPECT_FALSE(stream->Read(&response)); |
| 841 | |
| 842 | Status s = stream->Finish(); |
| 843 | EXPECT_TRUE(s.ok()); |
| 844 | } |
| 845 | |
ncteisen | be7b82b | 2017-06-20 12:31:04 -0700 | [diff] [blame] | 846 | // This was added to prevent regression from issue: |
| 847 | // https://github.com/grpc/grpc/issues/11546 |
| 848 | TEST_P(End2endTest, ResponseStreamWithEverythingCoalesced) { |
| 849 | ResetStub(); |
| 850 | EchoRequest request; |
| 851 | EchoResponse response; |
| 852 | ClientContext context; |
| 853 | request.set_message("hello"); |
| 854 | context.AddMetadata(kServerUseCoalescingApi, "1"); |
| 855 | // We will only send one message, forcing everything (init metadata, message, |
| 856 | // trailing) to be coalesced together. |
| 857 | context.AddMetadata(kServerResponseStreamsToSend, "1"); |
| 858 | |
| 859 | auto stream = stub_->ResponseStream(&context, request); |
| 860 | EXPECT_TRUE(stream->Read(&response)); |
| 861 | EXPECT_EQ(response.message(), request.message() + "0"); |
| 862 | |
| 863 | EXPECT_FALSE(stream->Read(&response)); |
| 864 | |
| 865 | Status s = stream->Finish(); |
| 866 | EXPECT_TRUE(s.ok()); |
| 867 | } |
| 868 | |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 869 | TEST_P(End2endTest, BidiStream) { |
| 870 | ResetStub(); |
nnoble | 0c475f0 | 2014-12-05 15:37:39 -0800 | [diff] [blame] | 871 | EchoRequest request; |
| 872 | EchoResponse response; |
| 873 | ClientContext context; |
| 874 | grpc::string msg("hello"); |
| 875 | |
Craig Tiller | fd1b49b | 2015-02-23 12:53:39 -0800 | [diff] [blame] | 876 | auto stream = stub_->BidiStream(&context); |
nnoble | 0c475f0 | 2014-12-05 15:37:39 -0800 | [diff] [blame] | 877 | |
ncteisen | 9bee308 | 2017-06-20 12:30:24 -0700 | [diff] [blame] | 878 | for (int i = 0; i < kServerDefaultResponseStreamsToSend; ++i) { |
| 879 | request.set_message(msg + grpc::to_string(i)); |
| 880 | EXPECT_TRUE(stream->Write(request)); |
| 881 | EXPECT_TRUE(stream->Read(&response)); |
| 882 | EXPECT_EQ(response.message(), request.message()); |
| 883 | } |
nnoble | 0c475f0 | 2014-12-05 15:37:39 -0800 | [diff] [blame] | 884 | |
| 885 | stream->WritesDone(); |
| 886 | EXPECT_FALSE(stream->Read(&response)); |
Craig Tiller | ca9a637 | 2015-12-15 18:16:28 -0800 | [diff] [blame] | 887 | EXPECT_FALSE(stream->Read(&response)); |
nnoble | 0c475f0 | 2014-12-05 15:37:39 -0800 | [diff] [blame] | 888 | |
Craig Tiller | 4d0fb5f | 2015-02-09 16:27:22 -0800 | [diff] [blame] | 889 | Status s = stream->Finish(); |
Yang Gao | c1a2c31 | 2015-06-16 10:59:46 -0700 | [diff] [blame] | 890 | EXPECT_TRUE(s.ok()); |
yangg | 1456d15 | 2015-01-08 15:39:58 -0800 | [diff] [blame] | 891 | } |
| 892 | |
Yuxuan Li | 34894e4 | 2017-02-08 17:57:24 -0800 | [diff] [blame] | 893 | TEST_P(End2endTest, BidiStreamWithCoalescingApi) { |
| 894 | ResetStub(); |
| 895 | EchoRequest request; |
| 896 | EchoResponse response; |
| 897 | ClientContext context; |
| 898 | context.AddMetadata(kServerFinishAfterNReads, "3"); |
Yuxuan Li | bdc76ab | 2017-03-03 13:59:30 -0800 | [diff] [blame] | 899 | context.set_initial_metadata_corked(true); |
Yuxuan Li | 34894e4 | 2017-02-08 17:57:24 -0800 | [diff] [blame] | 900 | grpc::string msg("hello"); |
| 901 | |
| 902 | auto stream = stub_->BidiStream(&context); |
| 903 | |
| 904 | request.set_message(msg + "0"); |
| 905 | EXPECT_TRUE(stream->Write(request)); |
| 906 | EXPECT_TRUE(stream->Read(&response)); |
| 907 | EXPECT_EQ(response.message(), request.message()); |
| 908 | |
| 909 | request.set_message(msg + "1"); |
| 910 | EXPECT_TRUE(stream->Write(request)); |
| 911 | EXPECT_TRUE(stream->Read(&response)); |
| 912 | EXPECT_EQ(response.message(), request.message()); |
| 913 | |
| 914 | request.set_message(msg + "2"); |
| 915 | stream->WriteLast(request, WriteOptions()); |
| 916 | EXPECT_TRUE(stream->Read(&response)); |
| 917 | EXPECT_EQ(response.message(), request.message()); |
| 918 | |
| 919 | EXPECT_FALSE(stream->Read(&response)); |
| 920 | EXPECT_FALSE(stream->Read(&response)); |
| 921 | |
| 922 | Status s = stream->Finish(); |
| 923 | EXPECT_TRUE(s.ok()); |
| 924 | } |
| 925 | |
ncteisen | 43f2b55 | 2017-06-26 17:00:10 -0700 | [diff] [blame] | 926 | // This was added to prevent regression from issue: |
| 927 | // https://github.com/grpc/grpc/issues/11546 |
| 928 | TEST_P(End2endTest, BidiStreamWithEverythingCoalesced) { |
| 929 | ResetStub(); |
| 930 | EchoRequest request; |
| 931 | EchoResponse response; |
| 932 | ClientContext context; |
| 933 | context.AddMetadata(kServerFinishAfterNReads, "1"); |
| 934 | context.set_initial_metadata_corked(true); |
| 935 | grpc::string msg("hello"); |
| 936 | |
| 937 | auto stream = stub_->BidiStream(&context); |
| 938 | |
| 939 | request.set_message(msg + "0"); |
| 940 | stream->WriteLast(request, WriteOptions()); |
| 941 | EXPECT_TRUE(stream->Read(&response)); |
| 942 | EXPECT_EQ(response.message(), request.message()); |
| 943 | |
| 944 | EXPECT_FALSE(stream->Read(&response)); |
| 945 | EXPECT_FALSE(stream->Read(&response)); |
| 946 | |
| 947 | Status s = stream->Finish(); |
| 948 | EXPECT_TRUE(s.ok()); |
| 949 | } |
| 950 | |
yangg | 1456d15 | 2015-01-08 15:39:58 -0800 | [diff] [blame] | 951 | // Talk to the two services with the same name but different package names. |
| 952 | // The two stubs are created on the same channel. |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 953 | TEST_P(End2endTest, DiffPackageServices) { |
| 954 | ResetStub(); |
yangg | 1456d15 | 2015-01-08 15:39:58 -0800 | [diff] [blame] | 955 | EchoRequest request; |
| 956 | EchoResponse response; |
| 957 | request.set_message("Hello"); |
| 958 | |
yangg | 1456d15 | 2015-01-08 15:39:58 -0800 | [diff] [blame] | 959 | ClientContext context; |
yang-g | 8b25f2a | 2015-07-21 23:54:36 -0700 | [diff] [blame] | 960 | Status s = stub_->Echo(&context, request, &response); |
yangg | 1456d15 | 2015-01-08 15:39:58 -0800 | [diff] [blame] | 961 | EXPECT_EQ(response.message(), request.message()); |
Yang Gao | c1a2c31 | 2015-06-16 10:59:46 -0700 | [diff] [blame] | 962 | EXPECT_TRUE(s.ok()); |
yangg | 1456d15 | 2015-01-08 15:39:58 -0800 | [diff] [blame] | 963 | |
Sree Kuchibhotla | 5a05f51 | 2016-01-13 22:43:20 -0800 | [diff] [blame] | 964 | std::unique_ptr<grpc::testing::duplicate::EchoTestService::Stub> dup_pkg_stub( |
| 965 | grpc::testing::duplicate::EchoTestService::NewStub(channel_)); |
yangg | 1456d15 | 2015-01-08 15:39:58 -0800 | [diff] [blame] | 966 | ClientContext context2; |
| 967 | s = dup_pkg_stub->Echo(&context2, request, &response); |
| 968 | EXPECT_EQ("no package", response.message()); |
Yang Gao | c1a2c31 | 2015-06-16 10:59:46 -0700 | [diff] [blame] | 969 | EXPECT_TRUE(s.ok()); |
nnoble | 0c475f0 | 2014-12-05 15:37:39 -0800 | [diff] [blame] | 970 | } |
| 971 | |
Yang Gao | 0c4b0dd | 2015-03-30 13:08:34 -0700 | [diff] [blame] | 972 | void CancelRpc(ClientContext* context, int delay_us, TestServiceImpl* service) { |
Craig Tiller | 20b5fe9 | 2015-07-06 10:43:50 -0700 | [diff] [blame] | 973 | gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), |
Craig Tiller | 677c50c | 2015-07-13 10:49:06 -0700 | [diff] [blame] | 974 | gpr_time_from_micros(delay_us, GPR_TIMESPAN))); |
Yang Gao | 0c4b0dd | 2015-03-30 13:08:34 -0700 | [diff] [blame] | 975 | while (!service->signal_client()) { |
| 976 | } |
| 977 | context->TryCancel(); |
| 978 | } |
| 979 | |
yang-g | a89bf50 | 2015-11-17 14:19:17 -0800 | [diff] [blame] | 980 | TEST_P(End2endTest, CancelRpcBeforeStart) { |
| 981 | ResetStub(); |
| 982 | EchoRequest request; |
| 983 | EchoResponse response; |
| 984 | ClientContext context; |
| 985 | request.set_message("hello"); |
| 986 | context.TryCancel(); |
| 987 | Status s = stub_->Echo(&context, request, &response); |
| 988 | EXPECT_EQ("", response.message()); |
| 989 | EXPECT_EQ(grpc::StatusCode::CANCELLED, s.error_code()); |
| 990 | } |
| 991 | |
Abhishek Kumar | d774c5c | 2015-04-23 14:59:49 -0700 | [diff] [blame] | 992 | // Client cancels request stream after sending two messages |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 993 | TEST_P(End2endTest, ClientCancelsRequestStream) { |
| 994 | ResetStub(); |
Abhishek Kumar | d774c5c | 2015-04-23 14:59:49 -0700 | [diff] [blame] | 995 | EchoRequest request; |
| 996 | EchoResponse response; |
| 997 | ClientContext context; |
| 998 | request.set_message("hello"); |
| 999 | |
| 1000 | auto stream = stub_->RequestStream(&context, &response); |
| 1001 | EXPECT_TRUE(stream->Write(request)); |
| 1002 | EXPECT_TRUE(stream->Write(request)); |
Yang Gao | c71a9d2 | 2015-05-04 00:22:12 -0700 | [diff] [blame] | 1003 | |
Abhishek Kumar | d774c5c | 2015-04-23 14:59:49 -0700 | [diff] [blame] | 1004 | context.TryCancel(); |
| 1005 | |
| 1006 | Status s = stream->Finish(); |
Yang Gao | c1a2c31 | 2015-06-16 10:59:46 -0700 | [diff] [blame] | 1007 | EXPECT_EQ(grpc::StatusCode::CANCELLED, s.error_code()); |
Abhishek Kumar | d774c5c | 2015-04-23 14:59:49 -0700 | [diff] [blame] | 1008 | |
Yang Gao | c71a9d2 | 2015-05-04 00:22:12 -0700 | [diff] [blame] | 1009 | EXPECT_EQ(response.message(), ""); |
Abhishek Kumar | d774c5c | 2015-04-23 14:59:49 -0700 | [diff] [blame] | 1010 | } |
| 1011 | |
Abhishek Kumar | e41d040 | 2015-04-17 14:12:33 -0700 | [diff] [blame] | 1012 | // Client cancels server stream after sending some messages |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 1013 | TEST_P(End2endTest, ClientCancelsResponseStream) { |
| 1014 | ResetStub(); |
Abhishek Kumar | e41d040 | 2015-04-17 14:12:33 -0700 | [diff] [blame] | 1015 | EchoRequest request; |
| 1016 | EchoResponse response; |
| 1017 | ClientContext context; |
| 1018 | request.set_message("hello"); |
| 1019 | |
| 1020 | auto stream = stub_->ResponseStream(&context, request); |
| 1021 | |
| 1022 | EXPECT_TRUE(stream->Read(&response)); |
| 1023 | EXPECT_EQ(response.message(), request.message() + "0"); |
| 1024 | EXPECT_TRUE(stream->Read(&response)); |
| 1025 | EXPECT_EQ(response.message(), request.message() + "1"); |
| 1026 | |
| 1027 | context.TryCancel(); |
| 1028 | |
| 1029 | // The cancellation races with responses, so there might be zero or |
| 1030 | // one responses pending, read till failure |
| 1031 | |
| 1032 | if (stream->Read(&response)) { |
| 1033 | EXPECT_EQ(response.message(), request.message() + "2"); |
| 1034 | // Since we have cancelled, we expect the next attempt to read to fail |
| 1035 | EXPECT_FALSE(stream->Read(&response)); |
| 1036 | } |
| 1037 | |
| 1038 | Status s = stream->Finish(); |
Abhishek Kumar | 18298a7 | 2015-04-17 15:00:25 -0700 | [diff] [blame] | 1039 | // The final status could be either of CANCELLED or OK depending on |
| 1040 | // who won the race. |
Yang Gao | c1a2c31 | 2015-06-16 10:59:46 -0700 | [diff] [blame] | 1041 | EXPECT_GE(grpc::StatusCode::CANCELLED, s.error_code()); |
Abhishek Kumar | e41d040 | 2015-04-17 14:12:33 -0700 | [diff] [blame] | 1042 | } |
| 1043 | |
Abhishek Kumar | 82a8331 | 2015-04-17 13:30:51 -0700 | [diff] [blame] | 1044 | // Client cancels bidi stream after sending some messages |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 1045 | TEST_P(End2endTest, ClientCancelsBidi) { |
| 1046 | ResetStub(); |
Abhishek Kumar | 82a8331 | 2015-04-17 13:30:51 -0700 | [diff] [blame] | 1047 | EchoRequest request; |
| 1048 | EchoResponse response; |
| 1049 | ClientContext context; |
| 1050 | grpc::string msg("hello"); |
| 1051 | |
| 1052 | auto stream = stub_->BidiStream(&context); |
| 1053 | |
| 1054 | request.set_message(msg + "0"); |
| 1055 | EXPECT_TRUE(stream->Write(request)); |
| 1056 | EXPECT_TRUE(stream->Read(&response)); |
| 1057 | EXPECT_EQ(response.message(), request.message()); |
| 1058 | |
| 1059 | request.set_message(msg + "1"); |
| 1060 | EXPECT_TRUE(stream->Write(request)); |
| 1061 | |
| 1062 | context.TryCancel(); |
| 1063 | |
| 1064 | // The cancellation races with responses, so there might be zero or |
| 1065 | // one responses pending, read till failure |
| 1066 | |
| 1067 | if (stream->Read(&response)) { |
| 1068 | EXPECT_EQ(response.message(), request.message()); |
| 1069 | // Since we have cancelled, we expect the next attempt to read to fail |
| 1070 | EXPECT_FALSE(stream->Read(&response)); |
| 1071 | } |
| 1072 | |
| 1073 | Status s = stream->Finish(); |
Yang Gao | c1a2c31 | 2015-06-16 10:59:46 -0700 | [diff] [blame] | 1074 | EXPECT_EQ(grpc::StatusCode::CANCELLED, s.error_code()); |
Abhishek Kumar | 82a8331 | 2015-04-17 13:30:51 -0700 | [diff] [blame] | 1075 | } |
| 1076 | |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 1077 | TEST_P(End2endTest, RpcMaxMessageSize) { |
| 1078 | ResetStub(); |
Yang Gao | 3921c56 | 2015-04-30 16:07:06 -0700 | [diff] [blame] | 1079 | EchoRequest request; |
| 1080 | EchoResponse response; |
Yang Gao | c71a9d2 | 2015-05-04 00:22:12 -0700 | [diff] [blame] | 1081 | request.set_message(string(kMaxMessageSize_ * 2, 'a')); |
yang-g | 23f777d | 2017-02-22 23:32:26 -0800 | [diff] [blame] | 1082 | request.mutable_param()->set_server_die(true); |
Yang Gao | 3921c56 | 2015-04-30 16:07:06 -0700 | [diff] [blame] | 1083 | |
| 1084 | ClientContext context; |
| 1085 | Status s = stub_->Echo(&context, request, &response); |
Yang Gao | c1a2c31 | 2015-06-16 10:59:46 -0700 | [diff] [blame] | 1086 | EXPECT_FALSE(s.ok()); |
Yang Gao | 3921c56 | 2015-04-30 16:07:06 -0700 | [diff] [blame] | 1087 | } |
Abhishek Kumar | 82a8331 | 2015-04-17 13:30:51 -0700 | [diff] [blame] | 1088 | |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 1089 | void ReaderThreadFunc(ClientReaderWriter<EchoRequest, EchoResponse>* stream, |
| 1090 | gpr_event* ev) { |
| 1091 | EchoResponse resp; |
| 1092 | gpr_event_set(ev, (void*)1); |
| 1093 | while (stream->Read(&resp)) { |
| 1094 | gpr_log(GPR_INFO, "Read message"); |
| 1095 | } |
| 1096 | } |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 1097 | |
| 1098 | // Run a Read and a WritesDone simultaneously. |
| 1099 | TEST_P(End2endTest, SimultaneousReadWritesDone) { |
| 1100 | ResetStub(); |
| 1101 | ClientContext context; |
| 1102 | gpr_event ev; |
| 1103 | gpr_event_init(&ev); |
| 1104 | auto stream = stub_->BidiStream(&context); |
| 1105 | std::thread reader_thread(ReaderThreadFunc, stream.get(), &ev); |
| 1106 | gpr_event_wait(&ev, gpr_inf_future(GPR_CLOCK_REALTIME)); |
| 1107 | stream->WritesDone(); |
Vijay Pai | bdfec2c | 2016-02-25 11:51:21 -0800 | [diff] [blame] | 1108 | reader_thread.join(); |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 1109 | Status s = stream->Finish(); |
| 1110 | EXPECT_TRUE(s.ok()); |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 1111 | } |
| 1112 | |
| 1113 | TEST_P(End2endTest, ChannelState) { |
Vijay Pai | 3d7d5f4 | 2017-05-04 10:02:24 -0700 | [diff] [blame] | 1114 | if (GetParam().inproc) { |
| 1115 | return; |
| 1116 | } |
| 1117 | |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 1118 | ResetStub(); |
| 1119 | // Start IDLE |
| 1120 | EXPECT_EQ(GRPC_CHANNEL_IDLE, channel_->GetState(false)); |
| 1121 | |
| 1122 | // Did not ask to connect, no state change. |
| 1123 | CompletionQueue cq; |
| 1124 | std::chrono::system_clock::time_point deadline = |
| 1125 | std::chrono::system_clock::now() + std::chrono::milliseconds(10); |
Craig Tiller | 4ac2b8e | 2017-11-10 14:14:17 -0800 | [diff] [blame] | 1126 | channel_->NotifyOnStateChange(GRPC_CHANNEL_IDLE, deadline, &cq, nullptr); |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 1127 | void* tag; |
| 1128 | bool ok = true; |
| 1129 | cq.Next(&tag, &ok); |
| 1130 | EXPECT_FALSE(ok); |
| 1131 | |
| 1132 | EXPECT_EQ(GRPC_CHANNEL_IDLE, channel_->GetState(true)); |
| 1133 | EXPECT_TRUE(channel_->WaitForStateChange(GRPC_CHANNEL_IDLE, |
| 1134 | gpr_inf_future(GPR_CLOCK_REALTIME))); |
yang-g | 0d55750 | 2015-10-01 11:30:12 -0700 | [diff] [blame] | 1135 | auto state = channel_->GetState(false); |
| 1136 | EXPECT_TRUE(state == GRPC_CHANNEL_CONNECTING || state == GRPC_CHANNEL_READY); |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 1137 | } |
| 1138 | |
| 1139 | // Takes 10s. |
| 1140 | TEST_P(End2endTest, ChannelStateTimeout) { |
Vijay Pai | 3d7d5f4 | 2017-05-04 10:02:24 -0700 | [diff] [blame] | 1141 | if ((GetParam().credentials_type != kInsecureCredentialsType) || |
| 1142 | GetParam().inproc) { |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 1143 | return; |
| 1144 | } |
| 1145 | int port = grpc_pick_unused_port_or_die(); |
| 1146 | std::ostringstream server_address; |
| 1147 | server_address << "127.0.0.1:" << port; |
| 1148 | // Channel to non-existing server |
Julien Boeuf | e5adc0e | 2015-10-12 14:08:10 -0700 | [diff] [blame] | 1149 | auto channel = |
| 1150 | CreateChannel(server_address.str(), InsecureChannelCredentials()); |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 1151 | // Start IDLE |
| 1152 | EXPECT_EQ(GRPC_CHANNEL_IDLE, channel->GetState(true)); |
| 1153 | |
| 1154 | auto state = GRPC_CHANNEL_IDLE; |
| 1155 | for (int i = 0; i < 10; i++) { |
| 1156 | channel->WaitForStateChange( |
| 1157 | state, std::chrono::system_clock::now() + std::chrono::seconds(1)); |
| 1158 | state = channel->GetState(false); |
| 1159 | } |
| 1160 | } |
| 1161 | |
| 1162 | // Talking to a non-existing service. |
| 1163 | TEST_P(End2endTest, NonExistingService) { |
| 1164 | ResetChannel(); |
murgatroid99 | 7c5befd | 2016-09-01 17:09:47 -0700 | [diff] [blame] | 1165 | std::unique_ptr<grpc::testing::UnimplementedEchoService::Stub> stub; |
| 1166 | stub = grpc::testing::UnimplementedEchoService::NewStub(channel_); |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 1167 | |
| 1168 | EchoRequest request; |
| 1169 | EchoResponse response; |
| 1170 | request.set_message("Hello"); |
| 1171 | |
| 1172 | ClientContext context; |
| 1173 | Status s = stub->Unimplemented(&context, request, &response); |
| 1174 | EXPECT_EQ(StatusCode::UNIMPLEMENTED, s.error_code()); |
| 1175 | EXPECT_EQ("", s.error_message()); |
| 1176 | } |
| 1177 | |
yang-g | 4c07008 | 2016-05-05 23:27:13 -0700 | [diff] [blame] | 1178 | // Ask the server to send back a serialized proto in trailer. |
| 1179 | // This is an example of setting error details. |
| 1180 | TEST_P(End2endTest, BinaryTrailerTest) { |
| 1181 | ResetStub(); |
| 1182 | EchoRequest request; |
| 1183 | EchoResponse response; |
| 1184 | ClientContext context; |
| 1185 | |
| 1186 | request.mutable_param()->set_echo_metadata(true); |
| 1187 | DebugInfo* info = request.mutable_param()->mutable_debug_info(); |
| 1188 | info->add_stack_entries("stack_entry_1"); |
| 1189 | info->add_stack_entries("stack_entry_2"); |
| 1190 | info->add_stack_entries("stack_entry_3"); |
| 1191 | info->set_detail("detailed debug info"); |
| 1192 | grpc::string expected_string = info->SerializeAsString(); |
| 1193 | request.set_message("Hello"); |
| 1194 | |
| 1195 | Status s = stub_->Echo(&context, request, &response); |
| 1196 | EXPECT_FALSE(s.ok()); |
| 1197 | auto trailers = context.GetServerTrailingMetadata(); |
yang-g | 39e71c3 | 2016-05-10 10:21:41 -0700 | [diff] [blame] | 1198 | EXPECT_EQ(1u, trailers.count(kDebugInfoTrailerKey)); |
yang-g | 4c07008 | 2016-05-05 23:27:13 -0700 | [diff] [blame] | 1199 | auto iter = trailers.find(kDebugInfoTrailerKey); |
| 1200 | EXPECT_EQ(expected_string, iter->second); |
yang-g | 080528a | 2016-05-06 13:12:00 -0700 | [diff] [blame] | 1201 | // Parse the returned trailer into a DebugInfo proto. |
| 1202 | DebugInfo returned_info; |
| 1203 | EXPECT_TRUE(returned_info.ParseFromString(ToString(iter->second))); |
yang-g | 4c07008 | 2016-05-05 23:27:13 -0700 | [diff] [blame] | 1204 | } |
| 1205 | |
yang-g | f4c8add | 2017-04-07 14:17:41 -0700 | [diff] [blame] | 1206 | TEST_P(End2endTest, ExpectErrorTest) { |
| 1207 | ResetStub(); |
| 1208 | |
| 1209 | std::vector<ErrorStatus> expected_status; |
| 1210 | expected_status.emplace_back(); |
| 1211 | expected_status.back().set_code(13); // INTERNAL |
| 1212 | expected_status.back().set_error_message("text error message"); |
| 1213 | expected_status.back().set_binary_error_details("text error details"); |
| 1214 | expected_status.emplace_back(); |
| 1215 | expected_status.back().set_code(13); // INTERNAL |
| 1216 | expected_status.back().set_error_message("text error message"); |
| 1217 | expected_status.back().set_binary_error_details( |
| 1218 | "\x0\x1\x2\x3\x4\x5\x6\x8\x9\xA\xB"); |
| 1219 | |
| 1220 | for (auto iter = expected_status.begin(); iter != expected_status.end(); |
| 1221 | ++iter) { |
| 1222 | EchoRequest request; |
| 1223 | EchoResponse response; |
| 1224 | ClientContext context; |
| 1225 | request.set_message("Hello"); |
| 1226 | auto* error = request.mutable_param()->mutable_expected_error(); |
| 1227 | error->set_code(iter->code()); |
| 1228 | error->set_error_message(iter->error_message()); |
| 1229 | error->set_binary_error_details(iter->binary_error_details()); |
| 1230 | |
| 1231 | Status s = stub_->Echo(&context, request, &response); |
| 1232 | EXPECT_FALSE(s.ok()); |
| 1233 | EXPECT_EQ(iter->code(), s.error_code()); |
| 1234 | EXPECT_EQ(iter->error_message(), s.error_message()); |
| 1235 | EXPECT_EQ(iter->binary_error_details(), s.error_details()); |
ncteisen | 18bc278 | 2017-12-04 13:25:14 -0800 | [diff] [blame] | 1236 | EXPECT_TRUE(context.debug_error_string().find("created") != |
| 1237 | std::string::npos); |
| 1238 | EXPECT_TRUE(context.debug_error_string().find("file") != std::string::npos); |
| 1239 | EXPECT_TRUE(context.debug_error_string().find("line") != std::string::npos); |
| 1240 | EXPECT_TRUE(context.debug_error_string().find("status") != |
| 1241 | std::string::npos); |
| 1242 | EXPECT_TRUE(context.debug_error_string().find("13") != std::string::npos); |
yang-g | f4c8add | 2017-04-07 14:17:41 -0700 | [diff] [blame] | 1243 | } |
| 1244 | } |
| 1245 | |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 1246 | ////////////////////////////////////////////////////////////////////////// |
| 1247 | // Test with and without a proxy. |
| 1248 | class ProxyEnd2endTest : public End2endTest { |
| 1249 | protected: |
| 1250 | }; |
| 1251 | |
| 1252 | TEST_P(ProxyEnd2endTest, SimpleRpc) { |
| 1253 | ResetStub(); |
yang-g | f8174ea | 2016-02-01 00:09:13 -0800 | [diff] [blame] | 1254 | SendRpc(stub_.get(), 1, false); |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 1255 | } |
| 1256 | |
yang-g | 000aa45 | 2016-06-07 13:08:39 -0700 | [diff] [blame] | 1257 | TEST_P(ProxyEnd2endTest, SimpleRpcWithEmptyMessages) { |
| 1258 | ResetStub(); |
| 1259 | EchoRequest request; |
| 1260 | EchoResponse response; |
| 1261 | |
| 1262 | ClientContext context; |
| 1263 | Status s = stub_->Echo(&context, request, &response); |
| 1264 | EXPECT_TRUE(s.ok()); |
| 1265 | } |
| 1266 | |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 1267 | TEST_P(ProxyEnd2endTest, MultipleRpcs) { |
| 1268 | ResetStub(); |
Vijay Pai | b0a6be2 | 2016-11-03 12:45:02 -0700 | [diff] [blame] | 1269 | std::vector<std::thread> threads; |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 1270 | for (int i = 0; i < 10; ++i) { |
Vijay Pai | b0a6be2 | 2016-11-03 12:45:02 -0700 | [diff] [blame] | 1271 | threads.emplace_back(SendRpc, stub_.get(), 10, false); |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 1272 | } |
| 1273 | for (int i = 0; i < 10; ++i) { |
Vijay Pai | b0a6be2 | 2016-11-03 12:45:02 -0700 | [diff] [blame] | 1274 | threads[i].join(); |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 1275 | } |
| 1276 | } |
| 1277 | |
| 1278 | // Set a 10us deadline and make sure proper error is returned. |
| 1279 | TEST_P(ProxyEnd2endTest, RpcDeadlineExpires) { |
| 1280 | ResetStub(); |
| 1281 | EchoRequest request; |
| 1282 | EchoResponse response; |
| 1283 | request.set_message("Hello"); |
Craig Tiller | b0f275e | 2016-01-27 10:45:50 -0800 | [diff] [blame] | 1284 | request.mutable_param()->set_skip_cancelled_check(true); |
Sree Kuchibhotla | cc6601e | 2017-12-07 11:23:40 -0800 | [diff] [blame] | 1285 | // Let server sleep for 40 ms first to guarantee expiry. |
| 1286 | // 40 ms might seem a bit extreme but the timer manager would have been just |
| 1287 | // initialized (when ResetStub() was called) and there are some warmup costs |
| 1288 | // i.e the timer thread many not have even started. There might also be other |
| 1289 | // delays in the timer manager thread (in acquiring locks, timer data |
| 1290 | // structure manipulations, starting backup timer threads) that add to the |
| 1291 | // delays. 40ms is still not enough in some cases but this significantly |
| 1292 | // reduces the test flakes |
| 1293 | request.mutable_param()->set_server_sleep_us(40 * 1000); |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 1294 | |
| 1295 | ClientContext context; |
| 1296 | std::chrono::system_clock::time_point deadline = |
Sree Kuchibhotla | cc6601e | 2017-12-07 11:23:40 -0800 | [diff] [blame] | 1297 | std::chrono::system_clock::now() + std::chrono::milliseconds(1); |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 1298 | context.set_deadline(deadline); |
| 1299 | Status s = stub_->Echo(&context, request, &response); |
| 1300 | EXPECT_EQ(StatusCode::DEADLINE_EXCEEDED, s.error_code()); |
| 1301 | } |
| 1302 | |
| 1303 | // Set a long but finite deadline. |
| 1304 | TEST_P(ProxyEnd2endTest, RpcLongDeadline) { |
| 1305 | ResetStub(); |
| 1306 | EchoRequest request; |
| 1307 | EchoResponse response; |
| 1308 | request.set_message("Hello"); |
| 1309 | |
| 1310 | ClientContext context; |
| 1311 | std::chrono::system_clock::time_point deadline = |
| 1312 | std::chrono::system_clock::now() + std::chrono::hours(1); |
| 1313 | context.set_deadline(deadline); |
| 1314 | Status s = stub_->Echo(&context, request, &response); |
| 1315 | EXPECT_EQ(response.message(), request.message()); |
| 1316 | EXPECT_TRUE(s.ok()); |
| 1317 | } |
| 1318 | |
| 1319 | // Ask server to echo back the deadline it sees. |
| 1320 | TEST_P(ProxyEnd2endTest, EchoDeadline) { |
| 1321 | ResetStub(); |
| 1322 | EchoRequest request; |
| 1323 | EchoResponse response; |
| 1324 | request.set_message("Hello"); |
| 1325 | request.mutable_param()->set_echo_deadline(true); |
| 1326 | |
| 1327 | ClientContext context; |
| 1328 | std::chrono::system_clock::time_point deadline = |
| 1329 | std::chrono::system_clock::now() + std::chrono::seconds(100); |
| 1330 | context.set_deadline(deadline); |
| 1331 | Status s = stub_->Echo(&context, request, &response); |
| 1332 | EXPECT_EQ(response.message(), request.message()); |
| 1333 | EXPECT_TRUE(s.ok()); |
| 1334 | gpr_timespec sent_deadline; |
| 1335 | Timepoint2Timespec(deadline, &sent_deadline); |
Jan Tattermusch | a3088a6 | 2018-01-30 23:38:26 +0100 | [diff] [blame^] | 1336 | // We want to allow some reasonable error given: |
| 1337 | // - request_deadline() only has 1sec resolution so the best we can do is +-1 |
| 1338 | // - if sent_deadline.tv_nsec is very close to the next second's boundary we |
| 1339 | // can end up being off by 2 in one direction. |
| 1340 | EXPECT_LE(response.param().request_deadline() - sent_deadline.tv_sec, 2); |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 1341 | EXPECT_GE(response.param().request_deadline() - sent_deadline.tv_sec, -1); |
| 1342 | } |
| 1343 | |
| 1344 | // Ask server to echo back the deadline it sees. The rpc has no deadline. |
| 1345 | TEST_P(ProxyEnd2endTest, EchoDeadlineForNoDeadlineRpc) { |
| 1346 | ResetStub(); |
| 1347 | EchoRequest request; |
| 1348 | EchoResponse response; |
| 1349 | request.set_message("Hello"); |
| 1350 | request.mutable_param()->set_echo_deadline(true); |
| 1351 | |
| 1352 | ClientContext context; |
| 1353 | Status s = stub_->Echo(&context, request, &response); |
| 1354 | EXPECT_EQ(response.message(), request.message()); |
| 1355 | EXPECT_TRUE(s.ok()); |
| 1356 | EXPECT_EQ(response.param().request_deadline(), |
| 1357 | gpr_inf_future(GPR_CLOCK_REALTIME).tv_sec); |
| 1358 | } |
| 1359 | |
| 1360 | TEST_P(ProxyEnd2endTest, UnimplementedRpc) { |
| 1361 | ResetStub(); |
| 1362 | EchoRequest request; |
| 1363 | EchoResponse response; |
| 1364 | request.set_message("Hello"); |
| 1365 | |
| 1366 | ClientContext context; |
| 1367 | Status s = stub_->Unimplemented(&context, request, &response); |
| 1368 | EXPECT_FALSE(s.ok()); |
| 1369 | EXPECT_EQ(s.error_code(), grpc::StatusCode::UNIMPLEMENTED); |
| 1370 | EXPECT_EQ(s.error_message(), ""); |
| 1371 | EXPECT_EQ(response.message(), ""); |
| 1372 | } |
| 1373 | |
| 1374 | // Client cancels rpc after 10ms |
| 1375 | TEST_P(ProxyEnd2endTest, ClientCancelsRpc) { |
| 1376 | ResetStub(); |
| 1377 | EchoRequest request; |
| 1378 | EchoResponse response; |
| 1379 | request.set_message("Hello"); |
| 1380 | const int kCancelDelayUs = 10 * 1000; |
| 1381 | request.mutable_param()->set_client_cancel_after_us(kCancelDelayUs); |
| 1382 | |
| 1383 | ClientContext context; |
| 1384 | std::thread cancel_thread(CancelRpc, &context, kCancelDelayUs, &service_); |
| 1385 | Status s = stub_->Echo(&context, request, &response); |
| 1386 | cancel_thread.join(); |
| 1387 | EXPECT_EQ(StatusCode::CANCELLED, s.error_code()); |
| 1388 | EXPECT_EQ(s.error_message(), "Cancelled"); |
| 1389 | } |
| 1390 | |
| 1391 | // Server cancels rpc after 1ms |
| 1392 | TEST_P(ProxyEnd2endTest, ServerCancelsRpc) { |
| 1393 | ResetStub(); |
| 1394 | EchoRequest request; |
| 1395 | EchoResponse response; |
| 1396 | request.set_message("Hello"); |
| 1397 | request.mutable_param()->set_server_cancel_after_us(1000); |
| 1398 | |
| 1399 | ClientContext context; |
| 1400 | Status s = stub_->Echo(&context, request, &response); |
| 1401 | EXPECT_EQ(StatusCode::CANCELLED, s.error_code()); |
| 1402 | EXPECT_TRUE(s.error_message().empty()); |
| 1403 | } |
| 1404 | |
| 1405 | // Make the response larger than the flow control window. |
| 1406 | TEST_P(ProxyEnd2endTest, HugeResponse) { |
| 1407 | ResetStub(); |
| 1408 | EchoRequest request; |
| 1409 | EchoResponse response; |
| 1410 | request.set_message("huge response"); |
| 1411 | const size_t kResponseSize = 1024 * (1024 + 10); |
| 1412 | request.mutable_param()->set_response_message_length(kResponseSize); |
| 1413 | |
| 1414 | ClientContext context; |
Craig Tiller | 6c8619b | 2016-07-07 10:41:48 -0700 | [diff] [blame] | 1415 | std::chrono::system_clock::time_point deadline = |
| 1416 | std::chrono::system_clock::now() + std::chrono::seconds(20); |
| 1417 | context.set_deadline(deadline); |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 1418 | Status s = stub_->Echo(&context, request, &response); |
| 1419 | EXPECT_EQ(kResponseSize, response.message().size()); |
| 1420 | EXPECT_TRUE(s.ok()); |
| 1421 | } |
| 1422 | |
| 1423 | TEST_P(ProxyEnd2endTest, Peer) { |
Vijay Pai | a629405 | 2017-10-10 20:47:54 -0700 | [diff] [blame] | 1424 | // Peer is not meaningful for inproc |
| 1425 | if (GetParam().inproc) { |
| 1426 | return; |
| 1427 | } |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 1428 | ResetStub(); |
| 1429 | EchoRequest request; |
| 1430 | EchoResponse response; |
| 1431 | request.set_message("hello"); |
| 1432 | request.mutable_param()->set_echo_peer(true); |
| 1433 | |
| 1434 | ClientContext context; |
| 1435 | Status s = stub_->Echo(&context, request, &response); |
| 1436 | EXPECT_EQ(response.message(), request.message()); |
| 1437 | EXPECT_TRUE(s.ok()); |
| 1438 | EXPECT_TRUE(CheckIsLocalhost(response.param().peer())); |
| 1439 | EXPECT_TRUE(CheckIsLocalhost(context.peer())); |
| 1440 | } |
| 1441 | |
| 1442 | ////////////////////////////////////////////////////////////////////////// |
| 1443 | class SecureEnd2endTest : public End2endTest { |
| 1444 | protected: |
| 1445 | SecureEnd2endTest() { |
| 1446 | GPR_ASSERT(!GetParam().use_proxy); |
yang-g | 17197dd | 2016-02-19 00:04:22 -0800 | [diff] [blame] | 1447 | GPR_ASSERT(GetParam().credentials_type != kInsecureCredentialsType); |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 1448 | } |
| 1449 | }; |
| 1450 | |
| 1451 | TEST_P(SecureEnd2endTest, SimpleRpcWithHost) { |
| 1452 | ResetStub(); |
| 1453 | |
| 1454 | EchoRequest request; |
| 1455 | EchoResponse response; |
| 1456 | request.set_message("Hello"); |
| 1457 | |
| 1458 | ClientContext context; |
| 1459 | context.set_authority("foo.test.youtube.com"); |
| 1460 | Status s = stub_->Echo(&context, request, &response); |
| 1461 | EXPECT_EQ(response.message(), request.message()); |
| 1462 | EXPECT_TRUE(response.has_param()); |
| 1463 | EXPECT_EQ("special", response.param().host()); |
| 1464 | EXPECT_TRUE(s.ok()); |
| 1465 | } |
| 1466 | |
yang-g | e21908f | 2015-08-25 13:47:51 -0700 | [diff] [blame] | 1467 | bool MetadataContains( |
| 1468 | const std::multimap<grpc::string_ref, grpc::string_ref>& metadata, |
| 1469 | const grpc::string& key, const grpc::string& value) { |
Yang Gao | 26a4912 | 2015-05-15 17:02:56 -0700 | [diff] [blame] | 1470 | int count = 0; |
| 1471 | |
yang-g | e21908f | 2015-08-25 13:47:51 -0700 | [diff] [blame] | 1472 | for (std::multimap<grpc::string_ref, grpc::string_ref>::const_iterator iter = |
Yang Gao | 26a4912 | 2015-05-15 17:02:56 -0700 | [diff] [blame] | 1473 | metadata.begin(); |
| 1474 | iter != metadata.end(); ++iter) { |
yang-g | e21908f | 2015-08-25 13:47:51 -0700 | [diff] [blame] | 1475 | if (ToString(iter->first) == key && ToString(iter->second) == value) { |
Yang Gao | 26a4912 | 2015-05-15 17:02:56 -0700 | [diff] [blame] | 1476 | count++; |
| 1477 | } |
| 1478 | } |
| 1479 | return count == 1; |
| 1480 | } |
| 1481 | |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 1482 | TEST_P(SecureEnd2endTest, BlockingAuthMetadataPluginAndProcessorSuccess) { |
| 1483 | auto* processor = new TestAuthMetadataProcessor(true); |
| 1484 | StartServer(std::shared_ptr<AuthMetadataProcessor>(processor)); |
| 1485 | ResetStub(); |
| 1486 | EchoRequest request; |
| 1487 | EchoResponse response; |
| 1488 | ClientContext context; |
| 1489 | context.set_credentials(processor->GetCompatibleClientCreds()); |
| 1490 | request.set_message("Hello"); |
| 1491 | request.mutable_param()->set_echo_metadata(true); |
| 1492 | request.mutable_param()->set_expected_client_identity( |
| 1493 | TestAuthMetadataProcessor::kGoodGuy); |
Dan Born | f2f7d57 | 2016-03-03 17:26:12 -0800 | [diff] [blame] | 1494 | request.mutable_param()->set_expected_transport_security_type( |
| 1495 | GetParam().credentials_type); |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 1496 | |
| 1497 | Status s = stub_->Echo(&context, request, &response); |
| 1498 | EXPECT_EQ(request.message(), response.message()); |
| 1499 | EXPECT_TRUE(s.ok()); |
| 1500 | |
| 1501 | // Metadata should have been consumed by the processor. |
| 1502 | EXPECT_FALSE(MetadataContains( |
| 1503 | context.GetServerTrailingMetadata(), GRPC_AUTHORIZATION_METADATA_KEY, |
| 1504 | grpc::string("Bearer ") + TestAuthMetadataProcessor::kGoodGuy)); |
| 1505 | } |
| 1506 | |
| 1507 | TEST_P(SecureEnd2endTest, BlockingAuthMetadataPluginAndProcessorFailure) { |
| 1508 | auto* processor = new TestAuthMetadataProcessor(true); |
| 1509 | StartServer(std::shared_ptr<AuthMetadataProcessor>(processor)); |
| 1510 | ResetStub(); |
| 1511 | EchoRequest request; |
| 1512 | EchoResponse response; |
| 1513 | ClientContext context; |
| 1514 | context.set_credentials(processor->GetIncompatibleClientCreds()); |
| 1515 | request.set_message("Hello"); |
| 1516 | |
| 1517 | Status s = stub_->Echo(&context, request, &response); |
| 1518 | EXPECT_FALSE(s.ok()); |
| 1519 | EXPECT_EQ(s.error_code(), StatusCode::UNAUTHENTICATED); |
| 1520 | } |
Craig Tiller | 7c70b6c | 2017-01-23 07:48:42 -0800 | [diff] [blame] | 1521 | |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 1522 | TEST_P(SecureEnd2endTest, SetPerCallCredentials) { |
| 1523 | ResetStub(); |
Yang Gao | a893892 | 2015-05-14 11:51:07 -0700 | [diff] [blame] | 1524 | EchoRequest request; |
| 1525 | EchoResponse response; |
| 1526 | ClientContext context; |
Julien Boeuf | e5adc0e | 2015-10-12 14:08:10 -0700 | [diff] [blame] | 1527 | std::shared_ptr<CallCredentials> creds = |
Julien Boeuf | 510a920 | 2015-08-25 21:51:07 -0700 | [diff] [blame] | 1528 | GoogleIAMCredentials("fake_token", "fake_selector"); |
Yang Gao | a893892 | 2015-05-14 11:51:07 -0700 | [diff] [blame] | 1529 | context.set_credentials(creds); |
Yang Gao | 26a4912 | 2015-05-15 17:02:56 -0700 | [diff] [blame] | 1530 | request.set_message("Hello"); |
| 1531 | request.mutable_param()->set_echo_metadata(true); |
Yang Gao | a893892 | 2015-05-14 11:51:07 -0700 | [diff] [blame] | 1532 | |
| 1533 | Status s = stub_->Echo(&context, request, &response); |
Yang Gao | a893892 | 2015-05-14 11:51:07 -0700 | [diff] [blame] | 1534 | EXPECT_EQ(request.message(), response.message()); |
Yang Gao | c1a2c31 | 2015-06-16 10:59:46 -0700 | [diff] [blame] | 1535 | EXPECT_TRUE(s.ok()); |
Yang Gao | 26a4912 | 2015-05-15 17:02:56 -0700 | [diff] [blame] | 1536 | EXPECT_TRUE(MetadataContains(context.GetServerTrailingMetadata(), |
| 1537 | GRPC_IAM_AUTHORIZATION_TOKEN_METADATA_KEY, |
| 1538 | "fake_token")); |
| 1539 | EXPECT_TRUE(MetadataContains(context.GetServerTrailingMetadata(), |
| 1540 | GRPC_IAM_AUTHORITY_SELECTOR_METADATA_KEY, |
| 1541 | "fake_selector")); |
Yang Gao | a893892 | 2015-05-14 11:51:07 -0700 | [diff] [blame] | 1542 | } |
| 1543 | |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 1544 | TEST_P(SecureEnd2endTest, OverridePerCallCredentials) { |
| 1545 | ResetStub(); |
Yang Gao | a893892 | 2015-05-14 11:51:07 -0700 | [diff] [blame] | 1546 | EchoRequest request; |
| 1547 | EchoResponse response; |
| 1548 | ClientContext context; |
Julien Boeuf | e5adc0e | 2015-10-12 14:08:10 -0700 | [diff] [blame] | 1549 | std::shared_ptr<CallCredentials> creds1 = |
Julien Boeuf | 510a920 | 2015-08-25 21:51:07 -0700 | [diff] [blame] | 1550 | GoogleIAMCredentials("fake_token1", "fake_selector1"); |
Yang Gao | a893892 | 2015-05-14 11:51:07 -0700 | [diff] [blame] | 1551 | context.set_credentials(creds1); |
Julien Boeuf | e5adc0e | 2015-10-12 14:08:10 -0700 | [diff] [blame] | 1552 | std::shared_ptr<CallCredentials> creds2 = |
Julien Boeuf | 510a920 | 2015-08-25 21:51:07 -0700 | [diff] [blame] | 1553 | GoogleIAMCredentials("fake_token2", "fake_selector2"); |
Yang Gao | a893892 | 2015-05-14 11:51:07 -0700 | [diff] [blame] | 1554 | context.set_credentials(creds2); |
Yang Gao | 26a4912 | 2015-05-15 17:02:56 -0700 | [diff] [blame] | 1555 | request.set_message("Hello"); |
| 1556 | request.mutable_param()->set_echo_metadata(true); |
Yang Gao | a893892 | 2015-05-14 11:51:07 -0700 | [diff] [blame] | 1557 | |
| 1558 | Status s = stub_->Echo(&context, request, &response); |
Yang Gao | 26a4912 | 2015-05-15 17:02:56 -0700 | [diff] [blame] | 1559 | EXPECT_TRUE(MetadataContains(context.GetServerTrailingMetadata(), |
| 1560 | GRPC_IAM_AUTHORIZATION_TOKEN_METADATA_KEY, |
| 1561 | "fake_token2")); |
| 1562 | EXPECT_TRUE(MetadataContains(context.GetServerTrailingMetadata(), |
| 1563 | GRPC_IAM_AUTHORITY_SELECTOR_METADATA_KEY, |
| 1564 | "fake_selector2")); |
Yang Gao | b57f72d | 2015-05-17 21:54:54 -0700 | [diff] [blame] | 1565 | EXPECT_FALSE(MetadataContains(context.GetServerTrailingMetadata(), |
| 1566 | GRPC_IAM_AUTHORIZATION_TOKEN_METADATA_KEY, |
| 1567 | "fake_token1")); |
| 1568 | EXPECT_FALSE(MetadataContains(context.GetServerTrailingMetadata(), |
| 1569 | GRPC_IAM_AUTHORITY_SELECTOR_METADATA_KEY, |
| 1570 | "fake_selector1")); |
Yang Gao | a893892 | 2015-05-14 11:51:07 -0700 | [diff] [blame] | 1571 | EXPECT_EQ(request.message(), response.message()); |
Yang Gao | c1a2c31 | 2015-06-16 10:59:46 -0700 | [diff] [blame] | 1572 | EXPECT_TRUE(s.ok()); |
Yang Gao | a893892 | 2015-05-14 11:51:07 -0700 | [diff] [blame] | 1573 | } |
| 1574 | |
yang-g | c580af3 | 2016-09-15 15:28:38 -0700 | [diff] [blame] | 1575 | TEST_P(SecureEnd2endTest, AuthMetadataPluginKeyFailure) { |
| 1576 | ResetStub(); |
| 1577 | EchoRequest request; |
| 1578 | EchoResponse response; |
| 1579 | ClientContext context; |
| 1580 | context.set_credentials( |
| 1581 | MetadataCredentialsFromPlugin(std::unique_ptr<MetadataCredentialsPlugin>( |
| 1582 | new TestMetadataCredentialsPlugin( |
| 1583 | TestMetadataCredentialsPlugin::kBadMetadataKey, |
| 1584 | "Does not matter, will fail the key is invalid.", false, true)))); |
| 1585 | request.set_message("Hello"); |
| 1586 | |
| 1587 | Status s = stub_->Echo(&context, request, &response); |
| 1588 | EXPECT_FALSE(s.ok()); |
Jan Tattermusch | ef0e64c | 2017-11-13 07:50:37 +0100 | [diff] [blame] | 1589 | EXPECT_EQ(s.error_code(), StatusCode::UNAVAILABLE); |
yang-g | c580af3 | 2016-09-15 15:28:38 -0700 | [diff] [blame] | 1590 | } |
| 1591 | |
yang-g | 4b4571a | 2016-09-15 23:01:09 -0700 | [diff] [blame] | 1592 | TEST_P(SecureEnd2endTest, AuthMetadataPluginValueFailure) { |
| 1593 | ResetStub(); |
| 1594 | EchoRequest request; |
| 1595 | EchoResponse response; |
| 1596 | ClientContext context; |
| 1597 | context.set_credentials( |
| 1598 | MetadataCredentialsFromPlugin(std::unique_ptr<MetadataCredentialsPlugin>( |
| 1599 | new TestMetadataCredentialsPlugin( |
| 1600 | TestMetadataCredentialsPlugin::kGoodMetadataKey, |
yang-g | d5fba28 | 2016-09-16 10:29:16 -0700 | [diff] [blame] | 1601 | "With illegal \n value.", false, true)))); |
yang-g | 4b4571a | 2016-09-15 23:01:09 -0700 | [diff] [blame] | 1602 | request.set_message("Hello"); |
| 1603 | |
| 1604 | Status s = stub_->Echo(&context, request, &response); |
| 1605 | EXPECT_FALSE(s.ok()); |
Jan Tattermusch | ef0e64c | 2017-11-13 07:50:37 +0100 | [diff] [blame] | 1606 | EXPECT_EQ(s.error_code(), StatusCode::UNAVAILABLE); |
yang-g | 4b4571a | 2016-09-15 23:01:09 -0700 | [diff] [blame] | 1607 | } |
| 1608 | |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 1609 | TEST_P(SecureEnd2endTest, NonBlockingAuthMetadataPluginFailure) { |
| 1610 | ResetStub(); |
Julien Boeuf | 1928d49 | 2015-09-15 15:20:11 -0700 | [diff] [blame] | 1611 | EchoRequest request; |
| 1612 | EchoResponse response; |
| 1613 | ClientContext context; |
| 1614 | context.set_credentials( |
| 1615 | MetadataCredentialsFromPlugin(std::unique_ptr<MetadataCredentialsPlugin>( |
| 1616 | new TestMetadataCredentialsPlugin( |
yang-g | c580af3 | 2016-09-15 15:28:38 -0700 | [diff] [blame] | 1617 | TestMetadataCredentialsPlugin::kGoodMetadataKey, |
Julien Boeuf | 1928d49 | 2015-09-15 15:20:11 -0700 | [diff] [blame] | 1618 | "Does not matter, will fail anyway (see 3rd param)", false, |
| 1619 | false)))); |
| 1620 | request.set_message("Hello"); |
| 1621 | |
| 1622 | Status s = stub_->Echo(&context, request, &response); |
| 1623 | EXPECT_FALSE(s.ok()); |
Jan Tattermusch | ef0e64c | 2017-11-13 07:50:37 +0100 | [diff] [blame] | 1624 | EXPECT_EQ(s.error_code(), StatusCode::UNAVAILABLE); |
Mark D. Roth | e0778b2 | 2017-07-21 15:42:00 -0700 | [diff] [blame] | 1625 | EXPECT_EQ(s.error_message(), |
| 1626 | grpc::string("Getting metadata from plugin failed with error: ") + |
| 1627 | kTestCredsPluginErrorMsg); |
Julien Boeuf | 1928d49 | 2015-09-15 15:20:11 -0700 | [diff] [blame] | 1628 | } |
| 1629 | |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 1630 | TEST_P(SecureEnd2endTest, NonBlockingAuthMetadataPluginAndProcessorSuccess) { |
Julien Boeuf | 0c711ad | 2015-08-28 14:10:58 -0700 | [diff] [blame] | 1631 | auto* processor = new TestAuthMetadataProcessor(false); |
| 1632 | StartServer(std::shared_ptr<AuthMetadataProcessor>(processor)); |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 1633 | ResetStub(); |
Julien Boeuf | 0c711ad | 2015-08-28 14:10:58 -0700 | [diff] [blame] | 1634 | EchoRequest request; |
| 1635 | EchoResponse response; |
| 1636 | ClientContext context; |
| 1637 | context.set_credentials(processor->GetCompatibleClientCreds()); |
| 1638 | request.set_message("Hello"); |
| 1639 | request.mutable_param()->set_echo_metadata(true); |
| 1640 | request.mutable_param()->set_expected_client_identity( |
| 1641 | TestAuthMetadataProcessor::kGoodGuy); |
Dan Born | f2f7d57 | 2016-03-03 17:26:12 -0800 | [diff] [blame] | 1642 | request.mutable_param()->set_expected_transport_security_type( |
| 1643 | GetParam().credentials_type); |
Julien Boeuf | 0c711ad | 2015-08-28 14:10:58 -0700 | [diff] [blame] | 1644 | |
| 1645 | Status s = stub_->Echo(&context, request, &response); |
| 1646 | EXPECT_EQ(request.message(), response.message()); |
| 1647 | EXPECT_TRUE(s.ok()); |
| 1648 | |
| 1649 | // Metadata should have been consumed by the processor. |
| 1650 | EXPECT_FALSE(MetadataContains( |
| 1651 | context.GetServerTrailingMetadata(), GRPC_AUTHORIZATION_METADATA_KEY, |
| 1652 | grpc::string("Bearer ") + TestAuthMetadataProcessor::kGoodGuy)); |
| 1653 | } |
| 1654 | |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 1655 | TEST_P(SecureEnd2endTest, NonBlockingAuthMetadataPluginAndProcessorFailure) { |
Julien Boeuf | 0c711ad | 2015-08-28 14:10:58 -0700 | [diff] [blame] | 1656 | auto* processor = new TestAuthMetadataProcessor(false); |
| 1657 | StartServer(std::shared_ptr<AuthMetadataProcessor>(processor)); |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 1658 | ResetStub(); |
Julien Boeuf | 0c711ad | 2015-08-28 14:10:58 -0700 | [diff] [blame] | 1659 | EchoRequest request; |
| 1660 | EchoResponse response; |
| 1661 | ClientContext context; |
| 1662 | context.set_credentials(processor->GetIncompatibleClientCreds()); |
| 1663 | request.set_message("Hello"); |
| 1664 | |
| 1665 | Status s = stub_->Echo(&context, request, &response); |
| 1666 | EXPECT_FALSE(s.ok()); |
| 1667 | EXPECT_EQ(s.error_code(), StatusCode::UNAUTHENTICATED); |
| 1668 | } |
| 1669 | |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 1670 | TEST_P(SecureEnd2endTest, BlockingAuthMetadataPluginFailure) { |
| 1671 | ResetStub(); |
Julien Boeuf | 1928d49 | 2015-09-15 15:20:11 -0700 | [diff] [blame] | 1672 | EchoRequest request; |
| 1673 | EchoResponse response; |
| 1674 | ClientContext context; |
| 1675 | context.set_credentials( |
| 1676 | MetadataCredentialsFromPlugin(std::unique_ptr<MetadataCredentialsPlugin>( |
| 1677 | new TestMetadataCredentialsPlugin( |
yang-g | c580af3 | 2016-09-15 15:28:38 -0700 | [diff] [blame] | 1678 | TestMetadataCredentialsPlugin::kGoodMetadataKey, |
Julien Boeuf | 1928d49 | 2015-09-15 15:20:11 -0700 | [diff] [blame] | 1679 | "Does not matter, will fail anyway (see 3rd param)", true, |
| 1680 | false)))); |
| 1681 | request.set_message("Hello"); |
| 1682 | |
| 1683 | Status s = stub_->Echo(&context, request, &response); |
| 1684 | EXPECT_FALSE(s.ok()); |
Jan Tattermusch | ef0e64c | 2017-11-13 07:50:37 +0100 | [diff] [blame] | 1685 | EXPECT_EQ(s.error_code(), StatusCode::UNAVAILABLE); |
Mark D. Roth | e0778b2 | 2017-07-21 15:42:00 -0700 | [diff] [blame] | 1686 | EXPECT_EQ(s.error_message(), |
| 1687 | grpc::string("Getting metadata from plugin failed with error: ") + |
| 1688 | kTestCredsPluginErrorMsg); |
Julien Boeuf | 1928d49 | 2015-09-15 15:20:11 -0700 | [diff] [blame] | 1689 | } |
| 1690 | |
yang-g | 3c00328 | 2017-09-20 13:58:13 -0700 | [diff] [blame] | 1691 | TEST_P(SecureEnd2endTest, CompositeCallCreds) { |
| 1692 | ResetStub(); |
| 1693 | EchoRequest request; |
| 1694 | EchoResponse response; |
| 1695 | ClientContext context; |
| 1696 | const char kMetadataKey1[] = "call-creds-key1"; |
| 1697 | const char kMetadataKey2[] = "call-creds-key2"; |
| 1698 | const char kMetadataVal1[] = "call-creds-val1"; |
| 1699 | const char kMetadataVal2[] = "call-creds-val2"; |
| 1700 | |
| 1701 | context.set_credentials(CompositeCallCredentials( |
| 1702 | MetadataCredentialsFromPlugin(std::unique_ptr<MetadataCredentialsPlugin>( |
| 1703 | new TestMetadataCredentialsPlugin(kMetadataKey1, kMetadataVal1, true, |
| 1704 | true))), |
| 1705 | MetadataCredentialsFromPlugin(std::unique_ptr<MetadataCredentialsPlugin>( |
| 1706 | new TestMetadataCredentialsPlugin(kMetadataKey2, kMetadataVal2, true, |
| 1707 | true))))); |
| 1708 | request.set_message("Hello"); |
| 1709 | request.mutable_param()->set_echo_metadata(true); |
| 1710 | |
| 1711 | Status s = stub_->Echo(&context, request, &response); |
| 1712 | EXPECT_TRUE(s.ok()); |
| 1713 | EXPECT_TRUE(MetadataContains(context.GetServerTrailingMetadata(), |
| 1714 | kMetadataKey1, kMetadataVal1)); |
| 1715 | EXPECT_TRUE(MetadataContains(context.GetServerTrailingMetadata(), |
| 1716 | kMetadataKey2, kMetadataVal2)); |
| 1717 | } |
| 1718 | |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 1719 | TEST_P(SecureEnd2endTest, ClientAuthContext) { |
| 1720 | ResetStub(); |
yang-g | c4eef2e | 2015-07-06 23:26:58 -0700 | [diff] [blame] | 1721 | EchoRequest request; |
| 1722 | EchoResponse response; |
| 1723 | request.set_message("Hello"); |
Dan Born | f2f7d57 | 2016-03-03 17:26:12 -0800 | [diff] [blame] | 1724 | request.mutable_param()->set_check_auth_context(GetParam().credentials_type == |
| 1725 | kTlsCredentialsType); |
| 1726 | request.mutable_param()->set_expected_transport_security_type( |
| 1727 | GetParam().credentials_type); |
yang-g | c4eef2e | 2015-07-06 23:26:58 -0700 | [diff] [blame] | 1728 | ClientContext context; |
| 1729 | Status s = stub_->Echo(&context, request, &response); |
| 1730 | EXPECT_EQ(response.message(), request.message()); |
| 1731 | EXPECT_TRUE(s.ok()); |
| 1732 | |
yang-g | 8b25f2a | 2015-07-21 23:54:36 -0700 | [diff] [blame] | 1733 | std::shared_ptr<const AuthContext> auth_ctx = context.auth_context(); |
Dan Born | f2f7d57 | 2016-03-03 17:26:12 -0800 | [diff] [blame] | 1734 | std::vector<grpc::string_ref> tst = |
yang-g | 8b25f2a | 2015-07-21 23:54:36 -0700 | [diff] [blame] | 1735 | auth_ctx->FindPropertyValues("transport_security_type"); |
Robbie Shade | 820c1f3 | 2016-06-23 14:31:28 -0400 | [diff] [blame] | 1736 | ASSERT_EQ(1u, tst.size()); |
Dan Born | f2f7d57 | 2016-03-03 17:26:12 -0800 | [diff] [blame] | 1737 | EXPECT_EQ(GetParam().credentials_type, ToString(tst[0])); |
| 1738 | if (GetParam().credentials_type == kTlsCredentialsType) { |
| 1739 | EXPECT_EQ("x509_subject_alternative_name", |
| 1740 | auth_ctx->GetPeerIdentityPropertyName()); |
Paul Querna | 47d841d | 2016-03-10 11:19:17 -0800 | [diff] [blame] | 1741 | EXPECT_EQ(4u, auth_ctx->GetPeerIdentity().size()); |
Dan Born | f2f7d57 | 2016-03-03 17:26:12 -0800 | [diff] [blame] | 1742 | EXPECT_EQ("*.test.google.fr", ToString(auth_ctx->GetPeerIdentity()[0])); |
| 1743 | EXPECT_EQ("waterzooi.test.google.be", |
| 1744 | ToString(auth_ctx->GetPeerIdentity()[1])); |
| 1745 | EXPECT_EQ("*.test.youtube.com", ToString(auth_ctx->GetPeerIdentity()[2])); |
Paul Querna | 47d841d | 2016-03-10 11:19:17 -0800 | [diff] [blame] | 1746 | EXPECT_EQ("192.168.1.3", ToString(auth_ctx->GetPeerIdentity()[3])); |
Dan Born | f2f7d57 | 2016-03-03 17:26:12 -0800 | [diff] [blame] | 1747 | } |
yang-g | c4eef2e | 2015-07-06 23:26:58 -0700 | [diff] [blame] | 1748 | } |
| 1749 | |
Craig Tiller | 20afa3d | 2016-10-17 14:52:14 -0700 | [diff] [blame] | 1750 | class ResourceQuotaEnd2endTest : public End2endTest { |
Craig Tiller | db1a5cc | 2016-09-28 14:22:12 -0700 | [diff] [blame] | 1751 | public: |
Craig Tiller | 20afa3d | 2016-10-17 14:52:14 -0700 | [diff] [blame] | 1752 | ResourceQuotaEnd2endTest() |
| 1753 | : server_resource_quota_("server_resource_quota") {} |
Craig Tiller | db1a5cc | 2016-09-28 14:22:12 -0700 | [diff] [blame] | 1754 | |
Vijay Pai | c0b2acb | 2016-11-01 16:31:56 -0700 | [diff] [blame] | 1755 | virtual void ConfigureServerBuilder(ServerBuilder* builder) override { |
Craig Tiller | 20afa3d | 2016-10-17 14:52:14 -0700 | [diff] [blame] | 1756 | builder->SetResourceQuota(server_resource_quota_); |
Craig Tiller | db1a5cc | 2016-09-28 14:22:12 -0700 | [diff] [blame] | 1757 | } |
| 1758 | |
| 1759 | private: |
Craig Tiller | 20afa3d | 2016-10-17 14:52:14 -0700 | [diff] [blame] | 1760 | ResourceQuota server_resource_quota_; |
Craig Tiller | db1a5cc | 2016-09-28 14:22:12 -0700 | [diff] [blame] | 1761 | }; |
| 1762 | |
Craig Tiller | 20afa3d | 2016-10-17 14:52:14 -0700 | [diff] [blame] | 1763 | TEST_P(ResourceQuotaEnd2endTest, SimpleRequest) { |
Craig Tiller | db1a5cc | 2016-09-28 14:22:12 -0700 | [diff] [blame] | 1764 | ResetStub(); |
| 1765 | |
| 1766 | EchoRequest request; |
| 1767 | EchoResponse response; |
| 1768 | request.set_message("Hello"); |
| 1769 | |
| 1770 | ClientContext context; |
| 1771 | Status s = stub_->Echo(&context, request, &response); |
| 1772 | EXPECT_EQ(response.message(), request.message()); |
| 1773 | EXPECT_TRUE(s.ok()); |
| 1774 | } |
| 1775 | |
yang-g | 4c8aed3 | 2016-02-19 00:19:39 -0800 | [diff] [blame] | 1776 | std::vector<TestScenario> CreateTestScenarios(bool use_proxy, |
| 1777 | bool test_insecure, |
Vijay Pai | 3d7d5f4 | 2017-05-04 10:02:24 -0700 | [diff] [blame] | 1778 | bool test_secure, |
| 1779 | bool test_inproc) { |
yang-g | 4c8aed3 | 2016-02-19 00:19:39 -0800 | [diff] [blame] | 1780 | std::vector<TestScenario> scenarios; |
| 1781 | std::vector<grpc::string> credentials_types; |
| 1782 | if (test_secure) { |
yang-g | cc59102 | 2017-01-11 11:10:43 -0800 | [diff] [blame] | 1783 | credentials_types = |
| 1784 | GetCredentialsProvider()->GetSecureCredentialsTypeList(); |
yang-g | 4c8aed3 | 2016-02-19 00:19:39 -0800 | [diff] [blame] | 1785 | } |
Vijay Pai | 3d7d5f4 | 2017-05-04 10:02:24 -0700 | [diff] [blame] | 1786 | auto insec_ok = [] { |
| 1787 | // Only allow insecure credentials type when it is registered with the |
yang-g | cc59102 | 2017-01-11 11:10:43 -0800 | [diff] [blame] | 1788 | // provider. User may create providers that do not have insecure. |
Vijay Pai | 3d7d5f4 | 2017-05-04 10:02:24 -0700 | [diff] [blame] | 1789 | return GetCredentialsProvider()->GetChannelCredentials( |
| 1790 | kInsecureCredentialsType, nullptr) != nullptr; |
| 1791 | }; |
| 1792 | if (test_insecure && insec_ok()) { |
| 1793 | credentials_types.push_back(kInsecureCredentialsType); |
yang-g | 4c8aed3 | 2016-02-19 00:19:39 -0800 | [diff] [blame] | 1794 | } |
yang-g | cc59102 | 2017-01-11 11:10:43 -0800 | [diff] [blame] | 1795 | GPR_ASSERT(!credentials_types.empty()); |
Vijay Pai | a629405 | 2017-10-10 20:47:54 -0700 | [diff] [blame] | 1796 | for (const auto& cred : credentials_types) { |
| 1797 | scenarios.emplace_back(false, false, cred); |
yang-g | 4c8aed3 | 2016-02-19 00:19:39 -0800 | [diff] [blame] | 1798 | if (use_proxy) { |
Vijay Pai | a629405 | 2017-10-10 20:47:54 -0700 | [diff] [blame] | 1799 | scenarios.emplace_back(true, false, cred); |
yang-g | 4c8aed3 | 2016-02-19 00:19:39 -0800 | [diff] [blame] | 1800 | } |
| 1801 | } |
Vijay Pai | 3d7d5f4 | 2017-05-04 10:02:24 -0700 | [diff] [blame] | 1802 | if (test_inproc && insec_ok()) { |
| 1803 | scenarios.emplace_back(false, true, kInsecureCredentialsType); |
| 1804 | } |
yang-g | 4c8aed3 | 2016-02-19 00:19:39 -0800 | [diff] [blame] | 1805 | return scenarios; |
| 1806 | } |
yang-g | 6f30dec | 2015-07-22 23:11:56 -0700 | [diff] [blame] | 1807 | |
yang-g | 4c8aed3 | 2016-02-19 00:19:39 -0800 | [diff] [blame] | 1808 | INSTANTIATE_TEST_CASE_P(End2end, End2endTest, |
| 1809 | ::testing::ValuesIn(CreateTestScenarios(false, true, |
Vijay Pai | 3d7d5f4 | 2017-05-04 10:02:24 -0700 | [diff] [blame] | 1810 | true, true))); |
Sree Kuchibhotla | 944f4cf | 2016-01-27 14:37:26 -0800 | [diff] [blame] | 1811 | |
yang-g | 4c8aed3 | 2016-02-19 00:19:39 -0800 | [diff] [blame] | 1812 | INSTANTIATE_TEST_CASE_P(End2endServerTryCancel, End2endServerTryCancelTest, |
| 1813 | ::testing::ValuesIn(CreateTestScenarios(false, true, |
Vijay Pai | 3d7d5f4 | 2017-05-04 10:02:24 -0700 | [diff] [blame] | 1814 | true, true))); |
yang-g | 4c8aed3 | 2016-02-19 00:19:39 -0800 | [diff] [blame] | 1815 | |
| 1816 | INSTANTIATE_TEST_CASE_P(ProxyEnd2end, ProxyEnd2endTest, |
| 1817 | ::testing::ValuesIn(CreateTestScenarios(true, true, |
Vijay Pai | a629405 | 2017-10-10 20:47:54 -0700 | [diff] [blame] | 1818 | true, true))); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 1819 | |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 1820 | INSTANTIATE_TEST_CASE_P(SecureEnd2end, SecureEnd2endTest, |
yang-g | 4c8aed3 | 2016-02-19 00:19:39 -0800 | [diff] [blame] | 1821 | ::testing::ValuesIn(CreateTestScenarios(false, false, |
Vijay Pai | 3d7d5f4 | 2017-05-04 10:02:24 -0700 | [diff] [blame] | 1822 | true, false))); |
yang-g | 88d5d52 | 2015-09-29 12:46:54 -0700 | [diff] [blame] | 1823 | |
Craig Tiller | 20afa3d | 2016-10-17 14:52:14 -0700 | [diff] [blame] | 1824 | INSTANTIATE_TEST_CASE_P(ResourceQuotaEnd2end, ResourceQuotaEnd2endTest, |
Craig Tiller | db1a5cc | 2016-09-28 14:22:12 -0700 | [diff] [blame] | 1825 | ::testing::ValuesIn(CreateTestScenarios(false, true, |
Vijay Pai | 3d7d5f4 | 2017-05-04 10:02:24 -0700 | [diff] [blame] | 1826 | true, true))); |
Craig Tiller | db1a5cc | 2016-09-28 14:22:12 -0700 | [diff] [blame] | 1827 | |
yang-g | 8ab3836 | 2015-07-31 14:05:33 -0700 | [diff] [blame] | 1828 | } // namespace |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 1829 | } // namespace testing |
| 1830 | } // namespace grpc |
| 1831 | |
| 1832 | int main(int argc, char** argv) { |
Sree Kuchibhotla | de5f6bf | 2018-01-25 17:23:42 -0800 | [diff] [blame] | 1833 | gpr_setenv("GRPC_CLIENT_CHANNEL_BACKUP_POLL_INTERVAL_MS", "200"); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 1834 | grpc_test_init(argc, argv); |
| 1835 | ::testing::InitGoogleTest(&argc, argv); |
| 1836 | return RUN_ALL_TESTS(); |
David Garcia Quintas | 2bf574f | 2016-01-14 15:27:08 -0800 | [diff] [blame] | 1837 | } |