Debian Codegraph @

test/cpp/end2end/service_config_end2end_test.cc

raw
1 /*
2 *
3 * Copyright 2016 gRPC authors.
4 *
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
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
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.
16 *
17 */
18
19 #include <algorithm>
20 #include <memory>
21 #include <mutex>
22 #include <random>
23 #include <set>
24 #include <string>
25 #include <thread>
26
27 #include <gmock/gmock.h>
28 #include <gtest/gtest.h>
29
30 #include "absl/memory/memory.h"
31 #include "absl/strings/str_cat.h"
32
33 #include <grpc/grpc.h>
34 #include <grpc/support/alloc.h>
35 #include <grpc/support/atm.h>
36 #include <grpc/support/log.h>
37 #include <grpc/support/time.h>
38 #include <grpcpp/channel.h>
39 #include <grpcpp/client_context.h>
40 #include <grpcpp/create_channel.h>
41 #include <grpcpp/health_check_service_interface.h>
42 #include <grpcpp/impl/codegen/sync.h>
43 #include <grpcpp/server.h>
44 #include <grpcpp/server_builder.h>
45 #include <grpcpp/support/validate_service_config.h>
46
47 #include "src/core/ext/filters/client_channel/backup_poller.h"
48 #include "src/core/ext/filters/client_channel/global_subchannel_pool.h"
49 #include "src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h"
50 #include "src/core/lib/address_utils/parse_address.h"
51 #include "src/core/lib/backoff/backoff.h"
52 #include "src/core/lib/channel/channel_args.h"
53 #include "src/core/lib/gprpp/debug_location.h"
54 #include "src/core/lib/gprpp/ref_counted_ptr.h"
55 #include "src/core/lib/iomgr/tcp_client.h"
56 #include "src/core/lib/resolver/server_address.h"
57 #include "src/core/lib/security/credentials/fake/fake_credentials.h"
58 #include "src/core/lib/service_config/service_config_impl.h"
59 #include "src/core/lib/transport/error_utils.h"
60 #include "src/cpp/client/secure_credentials.h"
61 #include "src/cpp/server/secure_server_credentials.h"
62 #include "src/proto/grpc/testing/echo.grpc.pb.h"
63 #include "test/core/util/port.h"
64 #include "test/core/util/resolve_localhost_ip46.h"
65 #include "test/core/util/test_config.h"
66 #include "test/cpp/end2end/test_service_impl.h"
67
68 namespace grpc {
69 namespace testing {
70 namespace {
71
72 // Subclass of TestServiceImpl that increments a request counter for
73 // every call to the Echo RPC.
74 class MyTestServiceImpl : public TestServiceImpl {
75 public:
76 MyTestServiceImpl() : request_count_(0) {}
77
78 Status Echo(ServerContext* context, const EchoRequest* request,
79 EchoResponse* response) override {
80 {
81 grpc::internal::MutexLock lock(&mu_);
82 ++request_count_;
83 }
84 AddClient(context->peer());
85 return TestServiceImpl::Echo(context, request, response);
86 }
87
88 int request_count() {
89 grpc::internal::MutexLock lock(&mu_);
90 return request_count_;
91 }
92
93 void ResetCounters() {
94 grpc::internal::MutexLock lock(&mu_);
95 request_count_ = 0;
96 }
97
98 std::set<std::string> clients() {
99 grpc::internal::MutexLock lock(&clients_mu_);
100 return clients_;
101 }
102
103 private:
104 void AddClient(const std::string& client) {
105 grpc::internal::MutexLock lock(&clients_mu_);
106 clients_.insert(client);
107 }
108
109 grpc::internal::Mutex mu_;
110 int request_count_;
111 grpc::internal::Mutex clients_mu_;
112 std::set<std::string> clients_;
113 };
114
115 class ServiceConfigEnd2endTest : public ::testing::Test {
116 protected:
117 ServiceConfigEnd2endTest()
118 : server_host_("localhost"),
119 kRequestMessage_("Live long and prosper."),
120 creds_(new SecureChannelCredentials(
121 grpc_fake_transport_security_credentials_create())) {}
122
123 static void SetUpTestCase() {
124 // Make the backup poller poll very frequently in order to pick up
125 // updates from all the subchannels's FDs.
126 GPR_GLOBAL_CONFIG_SET(grpc_client_channel_backup_poll_interval_ms, 1);
127 }
128
129 void SetUp() override {
130 grpc_init();
131 response_generator_ =
132 grpc_core::MakeRefCounted<grpc_core::FakeResolverResponseGenerator>();
133 bool localhost_resolves_to_ipv4 = false;
134 bool localhost_resolves_to_ipv6 = false;
135 grpc_core::LocalhostResolves(&localhost_resolves_to_ipv4,
136 &localhost_resolves_to_ipv6);
137 ipv6_only_ = !localhost_resolves_to_ipv4 && localhost_resolves_to_ipv6;
138 }
139
140 void TearDown() override {
141 for (size_t i = 0; i < servers_.size(); ++i) {
142 servers_[i]->Shutdown();
143 }
144 // Explicitly destroy all the members so that we can make sure grpc_shutdown
145 // has finished by the end of this function, and thus all the registered
146 // LB policy factories are removed.
147 stub_.reset();
148 servers_.clear();
149 creds_.reset();
150 grpc_shutdown();
151 }
152
153 void CreateServers(size_t num_servers,
154 std::vector<int> ports = std::vector<int>()) {
155 servers_.clear();
156 for (size_t i = 0; i < num_servers; ++i) {
157 int port = 0;
158 if (ports.size() == num_servers) port = ports[i];
159 servers_.emplace_back(new ServerData(port));
160 }
161 }
162
163 void StartServer(size_t index) { servers_[index]->Start(server_host_); }
164
165 void StartServers(size_t num_servers,
166 std::vector<int> ports = std::vector<int>()) {
167 CreateServers(num_servers, std::move(ports));
168 for (size_t i = 0; i < num_servers; ++i) {
169 StartServer(i);
170 }
171 }
172
173 grpc_core::Resolver::Result BuildFakeResults(const std::vector<int>& ports) {
174 grpc_core::Resolver::Result result;
175 result.addresses = grpc_core::ServerAddressList();
176 for (const int& port : ports) {
177 std::string lb_uri_str =
178 absl::StrCat(ipv6_only_ ? "ipv6:[::1]:" : "ipv4:127.0.0.1:", port);
179 absl::StatusOr<grpc_core::URI> lb_uri = grpc_core::URI::Parse(lb_uri_str);
180 GPR_ASSERT(lb_uri.ok());
181 grpc_resolved_address address;
182 GPR_ASSERT(grpc_parse_uri(*lb_uri, &address));
183 result.addresses->emplace_back(address.addr, address.len,
184 grpc_core::ChannelArgs());
185 }
186 return result;
187 }
188
189 void SetNextResolutionNoServiceConfig(const std::vector<int>& ports) {
190 grpc_core::ExecCtx exec_ctx;
191 grpc_core::Resolver::Result result = BuildFakeResults(ports);
192 response_generator_->SetResponse(result);
193 }
194
195 void SetNextResolutionValidServiceConfig(const std::vector<int>& ports) {
196 grpc_core::ExecCtx exec_ctx;
197 grpc_core::Resolver::Result result = BuildFakeResults(ports);
198 result.service_config =
199 grpc_core::ServiceConfigImpl::Create(grpc_core::ChannelArgs(), "{}");
200 ASSERT_TRUE(result.service_config.ok()) << result.service_config.status();
201 response_generator_->SetResponse(result);
202 }
203
204 void SetNextResolutionInvalidServiceConfig(const std::vector<int>& ports) {
205 grpc_core::ExecCtx exec_ctx;
206 grpc_core::Resolver::Result result = BuildFakeResults(ports);
207 result.service_config =
208 absl::InvalidArgumentError("error parsing service config");
209 response_generator_->SetResponse(result);
210 }
211
212 void SetNextResolutionWithServiceConfig(const std::vector<int>& ports,
213 const char* svc_cfg) {
214 grpc_core::ExecCtx exec_ctx;
215 grpc_core::Resolver::Result result = BuildFakeResults(ports);
216 result.service_config =
217 grpc_core::ServiceConfigImpl::Create(grpc_core::ChannelArgs(), svc_cfg);
218 response_generator_->SetResponse(result);
219 }
220
221 std::vector<int> GetServersPorts(size_t start_index = 0) {
222 std::vector<int> ports;
223 for (size_t i = start_index; i < servers_.size(); ++i) {
224 ports.push_back(servers_[i]->port_);
225 }
226 return ports;
227 }
228
229 std::unique_ptr<grpc::testing::EchoTestService::Stub> BuildStub(
230 const std::shared_ptr<Channel>& channel) {
231 return grpc::testing::EchoTestService::NewStub(channel);
232 }
233
234 std::shared_ptr<Channel> BuildChannel() {
235 ChannelArguments args;
236 args.SetPointer(GRPC_ARG_FAKE_RESOLVER_RESPONSE_GENERATOR,
237 response_generator_.get());
238 return grpc::CreateCustomChannel("fake:///", creds_, args);
239 }
240
241 std::shared_ptr<Channel> BuildChannelWithDefaultServiceConfig() {
242 ChannelArguments args;
243 EXPECT_THAT(grpc::experimental::ValidateServiceConfigJSON(
244 ValidDefaultServiceConfig()),
245 ::testing::StrEq(""));
246 args.SetServiceConfigJSON(ValidDefaultServiceConfig());
247 args.SetPointer(GRPC_ARG_FAKE_RESOLVER_RESPONSE_GENERATOR,
248 response_generator_.get());
249 return grpc::CreateCustomChannel("fake:///", creds_, args);
250 }
251
252 std::shared_ptr<Channel> BuildChannelWithInvalidDefaultServiceConfig() {
253 ChannelArguments args;
254 EXPECT_THAT(grpc::experimental::ValidateServiceConfigJSON(
255 InvalidDefaultServiceConfig()),
256 ::testing::HasSubstr("JSON parse error"));
257 args.SetServiceConfigJSON(InvalidDefaultServiceConfig());
258 args.SetPointer(GRPC_ARG_FAKE_RESOLVER_RESPONSE_GENERATOR,
259 response_generator_.get());
260 return grpc::CreateCustomChannel("fake:///", creds_, args);
261 }
262
263 bool SendRpc(
264 const std::unique_ptr<grpc::testing::EchoTestService::Stub>& stub,
265 EchoResponse* response = nullptr, int timeout_ms = 1000,
266 Status* result = nullptr, bool wait_for_ready = false) {
267 const bool local_response = (response == nullptr);
268 if (local_response) response = new EchoResponse;
269 EchoRequest request;
270 request.set_message(kRequestMessage_);
271 ClientContext context;
272 context.set_deadline(grpc_timeout_milliseconds_to_deadline(timeout_ms));
273 if (wait_for_ready) context.set_wait_for_ready(true);
274 Status status = stub->Echo(&context, request, response);
275 if (result != nullptr) *result = status;
276 if (local_response) delete response;
277 return status.ok();
278 }
279
280 void CheckRpcSendOk(
281 const std::unique_ptr<grpc::testing::EchoTestService::Stub>& stub,
282 const grpc_core::DebugLocation& location, bool wait_for_ready = false) {
283 EchoResponse response;
284 Status status;
285 const bool success =
286 SendRpc(stub, &response, 2000, &status, wait_for_ready);
287 ASSERT_TRUE(success) << "From " << location.file() << ":" << location.line()
288 << "\n"
289 << "Error: " << status.error_message() << " "
290 << status.error_details();
291 ASSERT_EQ(response.message(), kRequestMessage_)
292 << "From " << location.file() << ":" << location.line();
293 if (!success) abort();
294 }
295
296 void CheckRpcSendFailure(
297 const std::unique_ptr<grpc::testing::EchoTestService::Stub>& stub) {
298 const bool success = SendRpc(stub);
299 EXPECT_FALSE(success);
300 }
301
302 struct ServerData {
303 const int port_;
304 std::unique_ptr<Server> server_;
305 MyTestServiceImpl service_;
306 std::unique_ptr<std::thread> thread_;
307
308 grpc::internal::Mutex mu_;
309 grpc::internal::CondVar cond_;
310 bool server_ready_ ABSL_GUARDED_BY(mu_) = false;
311 bool started_ ABSL_GUARDED_BY(mu_) = false;
312
313 explicit ServerData(int port = 0)
314 : port_(port > 0 ? port : grpc_pick_unused_port_or_die()) {}
315
316 void Start(const std::string& server_host) {
317 gpr_log(GPR_INFO, "starting server on port %d", port_);
318 grpc::internal::MutexLock lock(&mu_);
319 started_ = true;
320 thread_ = std::make_unique<std::thread>(
321 std::bind(&ServerData::Serve, this, server_host));
322 while (!server_ready_) {
323 cond_.Wait(&mu_);
324 }
325 server_ready_ = false;
326 gpr_log(GPR_INFO, "server startup complete");
327 }
328
329 void Serve(const std::string& server_host) {
330 std::ostringstream server_address;
331 server_address << server_host << ":" << port_;
332 ServerBuilder builder;
333 std::shared_ptr<ServerCredentials> creds(new SecureServerCredentials(
334 grpc_fake_transport_security_server_credentials_create()));
335 builder.AddListeningPort(server_address.str(), std::move(creds));
336 builder.RegisterService(&service_);
337 server_ = builder.BuildAndStart();
338 grpc::internal::MutexLock lock(&mu_);
339 server_ready_ = true;
340 cond_.Signal();
341 }
342
343 void Shutdown() {
344 grpc::internal::MutexLock lock(&mu_);
345 if (!started_) return;
346 server_->Shutdown(grpc_timeout_milliseconds_to_deadline(0));
347 thread_->join();
348 started_ = false;
349 }
350
351 void SetServingStatus(const std::string& service, bool serving) {
352 server_->GetHealthCheckService()->SetServingStatus(service, serving);
353 }
354 };
355
356 void ResetCounters() {
357 for (const auto& server : servers_) server->service_.ResetCounters();
358 }
359
360 void WaitForServer(
361 const std::unique_ptr<grpc::testing::EchoTestService::Stub>& stub,
362 size_t server_idx, const grpc_core::DebugLocation& location,
363 bool ignore_failure = false) {
364 do {
365 if (ignore_failure) {
366 SendRpc(stub);
367 } else {
368 CheckRpcSendOk(stub, location, true);
369 }
370 } while (servers_[server_idx]->service_.request_count() == 0);
371 ResetCounters();
372 }
373
374 bool WaitForChannelNotReady(Channel* channel, int timeout_seconds = 5) {
375 const gpr_timespec deadline =
376 grpc_timeout_seconds_to_deadline(timeout_seconds);
377 grpc_connectivity_state state;
378 while ((state = channel->GetState(false /* try_to_connect */)) ==
379 GRPC_CHANNEL_READY) {
380 if (!channel->WaitForStateChange(state, deadline)) return false;
381 }
382 return true;
383 }
384
385 bool WaitForChannelReady(Channel* channel, int timeout_seconds = 5) {
386 const gpr_timespec deadline =
387 grpc_timeout_seconds_to_deadline(timeout_seconds);
388 grpc_connectivity_state state;
389 while ((state = channel->GetState(true /* try_to_connect */)) !=
390 GRPC_CHANNEL_READY) {
391 if (!channel->WaitForStateChange(state, deadline)) return false;
392 }
393 return true;
394 }
395
396 bool SeenAllServers() {
397 for (const auto& server : servers_) {
398 if (server->service_.request_count() == 0) return false;
399 }
400 return true;
401 }
402
403 // Updates \a connection_order by appending to it the index of the newly
404 // connected server. Must be called after every single RPC.
405 void UpdateConnectionOrder(
406 const std::vector<std::unique_ptr<ServerData>>& servers,
407 std::vector<int>* connection_order) {
408 for (size_t i = 0; i < servers.size(); ++i) {
409 if (servers[i]->service_.request_count() == 1) {
410 // Was the server index known? If not, update connection_order.
411 const auto it =
412 std::find(connection_order->begin(), connection_order->end(), i);
413 if (it == connection_order->end()) {
414 connection_order->push_back(i);
415 return;
416 }
417 }
418 }
419 }
420
421 const char* ValidServiceConfigV1() { return "{\"version\": \"1\"}"; }
422
423 const char* ValidServiceConfigV2() { return "{\"version\": \"2\"}"; }
424
425 const char* ValidDefaultServiceConfig() {
426 return "{\"version\": \"valid_default\"}";
427 }
428
429 const char* InvalidDefaultServiceConfig() {
430 return "{\"version\": \"invalid_default\"";
431 }
432
433 bool ipv6_only_ = false;
434 const std::string server_host_;
435 std::unique_ptr<grpc::testing::EchoTestService::Stub> stub_;
436 std::vector<std::unique_ptr<ServerData>> servers_;
437 grpc_core::RefCountedPtr<grpc_core::FakeResolverResponseGenerator>
438 response_generator_;
439 const std::string kRequestMessage_;
440 std::shared_ptr<ChannelCredentials> creds_;
441 };
442
443 TEST_F(ServiceConfigEnd2endTest, NoServiceConfigTest) {
444 StartServers(1);
445 auto channel = BuildChannel();
446 auto stub = BuildStub(channel);
447 SetNextResolutionNoServiceConfig(GetServersPorts());
448 CheckRpcSendOk(stub, DEBUG_LOCATION);
449 EXPECT_STREQ("{}", channel->GetServiceConfigJSON().c_str());
450 }
451
452 TEST_F(ServiceConfigEnd2endTest, NoServiceConfigWithDefaultConfigTest) {
453 StartServers(1);
454 auto channel = BuildChannelWithDefaultServiceConfig();
455 auto stub = BuildStub(channel);
456 SetNextResolutionNoServiceConfig(GetServersPorts());
457 CheckRpcSendOk(stub, DEBUG_LOCATION);
458 EXPECT_STREQ(ValidDefaultServiceConfig(),
459 channel->GetServiceConfigJSON().c_str());
460 }
461
462 TEST_F(ServiceConfigEnd2endTest, InvalidServiceConfigTest) {
463 StartServers(1);
464 auto channel = BuildChannel();
465 auto stub = BuildStub(channel);
466 SetNextResolutionInvalidServiceConfig(GetServersPorts());
467 CheckRpcSendFailure(stub);
468 }
469
470 TEST_F(ServiceConfigEnd2endTest, ValidServiceConfigUpdatesTest) {
471 StartServers(1);
472 auto channel = BuildChannel();
473 auto stub = BuildStub(channel);
474 SetNextResolutionWithServiceConfig(GetServersPorts(), ValidServiceConfigV1());
475 CheckRpcSendOk(stub, DEBUG_LOCATION);
476 EXPECT_STREQ(ValidServiceConfigV1(), channel->GetServiceConfigJSON().c_str());
477 SetNextResolutionWithServiceConfig(GetServersPorts(), ValidServiceConfigV2());
478 CheckRpcSendOk(stub, DEBUG_LOCATION);
479 EXPECT_STREQ(ValidServiceConfigV2(), channel->GetServiceConfigJSON().c_str());
480 }
481
482 TEST_F(ServiceConfigEnd2endTest,
483 NoServiceConfigUpdateAfterValidServiceConfigTest) {
484 StartServers(1);
485 auto channel = BuildChannel();
486 auto stub = BuildStub(channel);
487 SetNextResolutionWithServiceConfig(GetServersPorts(), ValidServiceConfigV1());
488 CheckRpcSendOk(stub, DEBUG_LOCATION);
489 EXPECT_STREQ(ValidServiceConfigV1(), channel->GetServiceConfigJSON().c_str());
490 SetNextResolutionNoServiceConfig(GetServersPorts());
491 CheckRpcSendOk(stub, DEBUG_LOCATION);
492 EXPECT_STREQ("{}", channel->GetServiceConfigJSON().c_str());
493 }
494
495 TEST_F(ServiceConfigEnd2endTest,
496 NoServiceConfigUpdateAfterValidServiceConfigWithDefaultConfigTest) {
497 StartServers(1);
498 auto channel = BuildChannelWithDefaultServiceConfig();
499 auto stub = BuildStub(channel);
500 SetNextResolutionWithServiceConfig(GetServersPorts(), ValidServiceConfigV1());
501 CheckRpcSendOk(stub, DEBUG_LOCATION);
502 EXPECT_STREQ(ValidServiceConfigV1(), channel->GetServiceConfigJSON().c_str());
503 SetNextResolutionNoServiceConfig(GetServersPorts());
504 CheckRpcSendOk(stub, DEBUG_LOCATION);
505 EXPECT_STREQ(ValidDefaultServiceConfig(),
506 channel->GetServiceConfigJSON().c_str());
507 }
508
509 TEST_F(ServiceConfigEnd2endTest,
510 InvalidServiceConfigUpdateAfterValidServiceConfigTest) {
511 StartServers(1);
512 auto channel = BuildChannel();
513 auto stub = BuildStub(channel);
514 SetNextResolutionWithServiceConfig(GetServersPorts(), ValidServiceConfigV1());
515 CheckRpcSendOk(stub, DEBUG_LOCATION);
516 EXPECT_STREQ(ValidServiceConfigV1(), channel->GetServiceConfigJSON().c_str());
517 SetNextResolutionInvalidServiceConfig(GetServersPorts());
518 CheckRpcSendOk(stub, DEBUG_LOCATION);
519 EXPECT_STREQ(ValidServiceConfigV1(), channel->GetServiceConfigJSON().c_str());
520 }
521
522 TEST_F(ServiceConfigEnd2endTest,
523 InvalidServiceConfigUpdateAfterValidServiceConfigWithDefaultConfigTest) {
524 StartServers(1);
525 auto channel = BuildChannelWithDefaultServiceConfig();
526 auto stub = BuildStub(channel);
527 SetNextResolutionWithServiceConfig(GetServersPorts(), ValidServiceConfigV1());
528 CheckRpcSendOk(stub, DEBUG_LOCATION);
529 EXPECT_STREQ(ValidServiceConfigV1(), channel->GetServiceConfigJSON().c_str());
530 SetNextResolutionInvalidServiceConfig(GetServersPorts());
531 CheckRpcSendOk(stub, DEBUG_LOCATION);
532 EXPECT_STREQ(ValidServiceConfigV1(), channel->GetServiceConfigJSON().c_str());
533 }
534
535 TEST_F(ServiceConfigEnd2endTest,
536 ValidServiceConfigAfterInvalidServiceConfigTest) {
537 StartServers(1);
538 auto channel = BuildChannel();
539 auto stub = BuildStub(channel);
540 SetNextResolutionInvalidServiceConfig(GetServersPorts());
541 CheckRpcSendFailure(stub);
542 SetNextResolutionValidServiceConfig(GetServersPorts());
543 CheckRpcSendOk(stub, DEBUG_LOCATION);
544 }
545
546 TEST_F(ServiceConfigEnd2endTest, NoServiceConfigAfterInvalidServiceConfigTest) {
547 StartServers(1);
548 auto channel = BuildChannel();
549 auto stub = BuildStub(channel);
550 SetNextResolutionInvalidServiceConfig(GetServersPorts());
551 CheckRpcSendFailure(stub);
552 SetNextResolutionNoServiceConfig(GetServersPorts());
553 CheckRpcSendOk(stub, DEBUG_LOCATION);
554 EXPECT_STREQ("{}", channel->GetServiceConfigJSON().c_str());
555 }
556
557 TEST_F(ServiceConfigEnd2endTest,
558 AnotherInvalidServiceConfigAfterInvalidServiceConfigTest) {
559 StartServers(1);
560 auto channel = BuildChannel();
561 auto stub = BuildStub(channel);
562 SetNextResolutionInvalidServiceConfig(GetServersPorts());
563 CheckRpcSendFailure(stub);
564 SetNextResolutionInvalidServiceConfig(GetServersPorts());
565 CheckRpcSendFailure(stub);
566 }
567
568 TEST_F(ServiceConfigEnd2endTest, InvalidDefaultServiceConfigTest) {
569 StartServers(1);
570 auto channel = BuildChannelWithInvalidDefaultServiceConfig();
571 auto stub = BuildStub(channel);
572 // An invalid default service config results in a lame channel which fails all
573 // RPCs
574 CheckRpcSendFailure(stub);
575 }
576
577 TEST_F(ServiceConfigEnd2endTest,
578 InvalidDefaultServiceConfigTestWithValidServiceConfig) {
579 StartServers(1);
580 auto channel = BuildChannelWithInvalidDefaultServiceConfig();
581 auto stub = BuildStub(channel);
582 CheckRpcSendFailure(stub);
583 // An invalid default service config results in a lame channel which fails all
584 // RPCs
585 SetNextResolutionValidServiceConfig(GetServersPorts());
586 CheckRpcSendFailure(stub);
587 }
588
589 TEST_F(ServiceConfigEnd2endTest,
590 InvalidDefaultServiceConfigTestWithInvalidServiceConfig) {
591 StartServers(1);
592 auto channel = BuildChannelWithInvalidDefaultServiceConfig();
593 auto stub = BuildStub(channel);
594 CheckRpcSendFailure(stub);
595 // An invalid default service config results in a lame channel which fails all
596 // RPCs
597 SetNextResolutionInvalidServiceConfig(GetServersPorts());
598 CheckRpcSendFailure(stub);
599 }
600
601 TEST_F(ServiceConfigEnd2endTest,
602 InvalidDefaultServiceConfigTestWithNoServiceConfig) {
603 StartServers(1);
604 auto channel = BuildChannelWithInvalidDefaultServiceConfig();
605 auto stub = BuildStub(channel);
606 CheckRpcSendFailure(stub);
607 // An invalid default service config results in a lame channel which fails all
608 // RPCs
609 SetNextResolutionNoServiceConfig(GetServersPorts());
610 CheckRpcSendFailure(stub);
611 }
612
613 } // namespace
614 } // namespace testing
615 } // namespace grpc
616
617 int main(int argc, char** argv) {
618 ::testing::InitGoogleTest(&argc, argv);
619 grpc::testing::TestEnvironment env(&argc, argv);
620 const auto result = RUN_ALL_TESTS();
621 return result;
622 }