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