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