Imported Upstream version 1.34.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/resolve_localhost_ip46.h"
61 #include "test/core/util/test_config.h"
62 #include "test/cpp/end2end/test_service_impl.h"
63
64 #include <gmock/gmock.h>
65 #include <gtest/gtest.h>
66
67 using grpc::testing::EchoRequest;
68 using grpc::testing::EchoResponse;
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     bool localhost_resolves_to_ipv4 = false;
136     bool localhost_resolves_to_ipv6 = false;
137     grpc_core::LocalhostResolves(&localhost_resolves_to_ipv4,
138                                  &localhost_resolves_to_ipv6);
139     ipv6_only_ = !localhost_resolves_to_ipv4 && localhost_resolves_to_ipv6;
140   }
141
142   void TearDown() override {
143     for (size_t i = 0; i < servers_.size(); ++i) {
144       servers_[i]->Shutdown();
145     }
146     // Explicitly destroy all the members so that we can make sure grpc_shutdown
147     // has finished by the end of this function, and thus all the registered
148     // LB policy factories are removed.
149     stub_.reset();
150     servers_.clear();
151     creds_.reset();
152     grpc_shutdown();
153   }
154
155   void CreateServers(size_t num_servers,
156                      std::vector<int> ports = std::vector<int>()) {
157     servers_.clear();
158     for (size_t i = 0; i < num_servers; ++i) {
159       int port = 0;
160       if (ports.size() == num_servers) port = ports[i];
161       servers_.emplace_back(new ServerData(port));
162     }
163   }
164
165   void StartServer(size_t index) { servers_[index]->Start(server_host_); }
166
167   void StartServers(size_t num_servers,
168                     std::vector<int> ports = std::vector<int>()) {
169     CreateServers(num_servers, std::move(ports));
170     for (size_t i = 0; i < num_servers; ++i) {
171       StartServer(i);
172     }
173   }
174
175   grpc_core::Resolver::Result BuildFakeResults(const std::vector<int>& ports) {
176     grpc_core::Resolver::Result result;
177     for (const int& port : ports) {
178       std::string lb_uri_str =
179           absl::StrCat(ipv6_only_ ? "ipv6:[::1]:" : "ipv4:127.0.0.1:", port);
180       grpc_uri* lb_uri = grpc_uri_parse(lb_uri_str.c_str(), true);
181       GPR_ASSERT(lb_uri != nullptr);
182       grpc_resolved_address address;
183       GPR_ASSERT(grpc_parse_uri(lb_uri, &address));
184       result.addresses.emplace_back(address.addr, address.len,
185                                     nullptr /* args */);
186       grpc_uri_destroy(lb_uri);
187     }
188     return result;
189   }
190
191   void SetNextResolutionNoServiceConfig(const std::vector<int>& ports) {
192     grpc_core::ExecCtx exec_ctx;
193     grpc_core::Resolver::Result result = BuildFakeResults(ports);
194     response_generator_->SetResponse(result);
195   }
196
197   void SetNextResolutionValidServiceConfig(const std::vector<int>& ports) {
198     grpc_core::ExecCtx exec_ctx;
199     grpc_core::Resolver::Result result = BuildFakeResults(ports);
200     result.service_config = grpc_core::ServiceConfig::Create(
201         nullptr, "{}", &result.service_config_error);
202     response_generator_->SetResponse(result);
203   }
204
205   void SetNextResolutionInvalidServiceConfig(const std::vector<int>& ports) {
206     grpc_core::ExecCtx exec_ctx;
207     grpc_core::Resolver::Result result = BuildFakeResults(ports);
208     result.service_config = grpc_core::ServiceConfig::Create(
209         nullptr, "{", &result.service_config_error);
210     response_generator_->SetResponse(result);
211   }
212
213   void SetNextResolutionWithServiceConfig(const std::vector<int>& ports,
214                                           const char* svc_cfg) {
215     grpc_core::ExecCtx exec_ctx;
216     grpc_core::Resolver::Result result = BuildFakeResults(ports);
217     result.service_config = grpc_core::ServiceConfig::Create(
218         nullptr, svc_cfg, &result.service_config_error);
219     response_generator_->SetResponse(result);
220   }
221
222   std::vector<int> GetServersPorts(size_t start_index = 0) {
223     std::vector<int> ports;
224     for (size_t i = start_index; i < servers_.size(); ++i) {
225       ports.push_back(servers_[i]->port_);
226     }
227     return ports;
228   }
229
230   std::unique_ptr<grpc::testing::EchoTestService::Stub> BuildStub(
231       const std::shared_ptr<Channel>& channel) {
232     return grpc::testing::EchoTestService::NewStub(channel);
233   }
234
235   std::shared_ptr<Channel> BuildChannel() {
236     ChannelArguments args;
237     args.SetPointer(GRPC_ARG_FAKE_RESOLVER_RESPONSE_GENERATOR,
238                     response_generator_.get());
239     return ::grpc::CreateCustomChannel("fake:///", creds_, args);
240   }
241
242   std::shared_ptr<Channel> BuildChannelWithDefaultServiceConfig() {
243     ChannelArguments args;
244     EXPECT_THAT(grpc::experimental::ValidateServiceConfigJSON(
245                     ValidDefaultServiceConfig()),
246                 ::testing::StrEq(""));
247     args.SetServiceConfigJSON(ValidDefaultServiceConfig());
248     args.SetPointer(GRPC_ARG_FAKE_RESOLVER_RESPONSE_GENERATOR,
249                     response_generator_.get());
250     return ::grpc::CreateCustomChannel("fake:///", creds_, args);
251   }
252
253   std::shared_ptr<Channel> BuildChannelWithInvalidDefaultServiceConfig() {
254     ChannelArguments args;
255     EXPECT_THAT(grpc::experimental::ValidateServiceConfigJSON(
256                     InvalidDefaultServiceConfig()),
257                 ::testing::HasSubstr("JSON parse error"));
258     args.SetServiceConfigJSON(InvalidDefaultServiceConfig());
259     args.SetPointer(GRPC_ARG_FAKE_RESOLVER_RESPONSE_GENERATOR,
260                     response_generator_.get());
261     return ::grpc::CreateCustomChannel("fake:///", creds_, args);
262   }
263
264   bool SendRpc(
265       const std::unique_ptr<grpc::testing::EchoTestService::Stub>& stub,
266       EchoResponse* response = nullptr, int timeout_ms = 1000,
267       Status* result = nullptr, bool wait_for_ready = false) {
268     const bool local_response = (response == nullptr);
269     if (local_response) response = new EchoResponse;
270     EchoRequest request;
271     request.set_message(kRequestMessage_);
272     ClientContext context;
273     context.set_deadline(grpc_timeout_milliseconds_to_deadline(timeout_ms));
274     if (wait_for_ready) context.set_wait_for_ready(true);
275     Status status = stub->Echo(&context, request, response);
276     if (result != nullptr) *result = status;
277     if (local_response) delete response;
278     return status.ok();
279   }
280
281   void CheckRpcSendOk(
282       const std::unique_ptr<grpc::testing::EchoTestService::Stub>& stub,
283       const grpc_core::DebugLocation& location, bool wait_for_ready = false) {
284     EchoResponse response;
285     Status status;
286     const bool success =
287         SendRpc(stub, &response, 2000, &status, wait_for_ready);
288     ASSERT_TRUE(success) << "From " << location.file() << ":" << location.line()
289                          << "\n"
290                          << "Error: " << status.error_message() << " "
291                          << status.error_details();
292     ASSERT_EQ(response.message(), kRequestMessage_)
293         << "From " << location.file() << ":" << location.line();
294     if (!success) abort();
295   }
296
297   void CheckRpcSendFailure(
298       const std::unique_ptr<grpc::testing::EchoTestService::Stub>& stub) {
299     const bool success = SendRpc(stub);
300     EXPECT_FALSE(success);
301   }
302
303   struct ServerData {
304     int port_;
305     std::unique_ptr<Server> server_;
306     MyTestServiceImpl service_;
307     std::unique_ptr<std::thread> thread_;
308     bool server_ready_ = false;
309     bool started_ = false;
310
311     explicit ServerData(int port = 0) {
312       port_ = port > 0 ? port : grpc_pick_unused_port_or_die();
313     }
314
315     void Start(const std::string& server_host) {
316       gpr_log(GPR_INFO, "starting server on port %d", port_);
317       started_ = true;
318       grpc::internal::Mutex mu;
319       grpc::internal::MutexLock lock(&mu);
320       grpc::internal::CondVar cond;
321       thread_ = absl::make_unique<std::thread>(
322           std::bind(&ServerData::Serve, this, server_host, &mu, &cond));
323       cond.WaitUntil(&mu, [this] { return server_ready_; });
324       server_ready_ = false;
325       gpr_log(GPR_INFO, "server startup complete");
326     }
327
328     void Serve(const std::string& server_host, grpc::internal::Mutex* mu,
329                grpc::internal::CondVar* cond) {
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       if (!started_) return;
345       server_->Shutdown(grpc_timeout_milliseconds_to_deadline(0));
346       thread_->join();
347       started_ = false;
348     }
349
350     void SetServingStatus(const std::string& service, bool serving) {
351       server_->GetHealthCheckService()->SetServingStatus(service, serving);
352     }
353   };
354
355   void ResetCounters() {
356     for (const auto& server : servers_) server->service_.ResetCounters();
357   }
358
359   void WaitForServer(
360       const std::unique_ptr<grpc::testing::EchoTestService::Stub>& stub,
361       size_t server_idx, const grpc_core::DebugLocation& location,
362       bool ignore_failure = false) {
363     do {
364       if (ignore_failure) {
365         SendRpc(stub);
366       } else {
367         CheckRpcSendOk(stub, location, true);
368       }
369     } while (servers_[server_idx]->service_.request_count() == 0);
370     ResetCounters();
371   }
372
373   bool WaitForChannelNotReady(Channel* channel, int timeout_seconds = 5) {
374     const gpr_timespec deadline =
375         grpc_timeout_seconds_to_deadline(timeout_seconds);
376     grpc_connectivity_state state;
377     while ((state = channel->GetState(false /* try_to_connect */)) ==
378            GRPC_CHANNEL_READY) {
379       if (!channel->WaitForStateChange(state, deadline)) return false;
380     }
381     return true;
382   }
383
384   bool WaitForChannelReady(Channel* channel, int timeout_seconds = 5) {
385     const gpr_timespec deadline =
386         grpc_timeout_seconds_to_deadline(timeout_seconds);
387     grpc_connectivity_state state;
388     while ((state = channel->GetState(true /* try_to_connect */)) !=
389            GRPC_CHANNEL_READY) {
390       if (!channel->WaitForStateChange(state, deadline)) return false;
391     }
392     return true;
393   }
394
395   bool SeenAllServers() {
396     for (const auto& server : servers_) {
397       if (server->service_.request_count() == 0) return false;
398     }
399     return true;
400   }
401
402   // Updates \a connection_order by appending to it the index of the newly
403   // connected server. Must be called after every single RPC.
404   void UpdateConnectionOrder(
405       const std::vector<std::unique_ptr<ServerData>>& servers,
406       std::vector<int>* connection_order) {
407     for (size_t i = 0; i < servers.size(); ++i) {
408       if (servers[i]->service_.request_count() == 1) {
409         // Was the server index known? If not, update connection_order.
410         const auto it =
411             std::find(connection_order->begin(), connection_order->end(), i);
412         if (it == connection_order->end()) {
413           connection_order->push_back(i);
414           return;
415         }
416       }
417     }
418   }
419
420   const char* ValidServiceConfigV1() { return "{\"version\": \"1\"}"; }
421
422   const char* ValidServiceConfigV2() { return "{\"version\": \"2\"}"; }
423
424   const char* ValidDefaultServiceConfig() {
425     return "{\"version\": \"valid_default\"}";
426   }
427
428   const char* InvalidDefaultServiceConfig() {
429     return "{\"version\": \"invalid_default\"";
430   }
431
432   bool ipv6_only_ = false;
433   const std::string server_host_;
434   std::unique_ptr<grpc::testing::EchoTestService::Stub> stub_;
435   std::vector<std::unique_ptr<ServerData>> servers_;
436   grpc_core::RefCountedPtr<grpc_core::FakeResolverResponseGenerator>
437       response_generator_;
438   const std::string kRequestMessage_;
439   std::shared_ptr<ChannelCredentials> creds_;
440 };
441
442 TEST_F(ServiceConfigEnd2endTest, NoServiceConfigTest) {
443   StartServers(1);
444   auto channel = BuildChannel();
445   auto stub = BuildStub(channel);
446   SetNextResolutionNoServiceConfig(GetServersPorts());
447   CheckRpcSendOk(stub, DEBUG_LOCATION);
448   EXPECT_STREQ("{}", channel->GetServiceConfigJSON().c_str());
449 }
450
451 TEST_F(ServiceConfigEnd2endTest, NoServiceConfigWithDefaultConfigTest) {
452   StartServers(1);
453   auto channel = BuildChannelWithDefaultServiceConfig();
454   auto stub = BuildStub(channel);
455   SetNextResolutionNoServiceConfig(GetServersPorts());
456   CheckRpcSendOk(stub, DEBUG_LOCATION);
457   EXPECT_STREQ(ValidDefaultServiceConfig(),
458                channel->GetServiceConfigJSON().c_str());
459 }
460
461 TEST_F(ServiceConfigEnd2endTest, InvalidServiceConfigTest) {
462   StartServers(1);
463   auto channel = BuildChannel();
464   auto stub = BuildStub(channel);
465   SetNextResolutionInvalidServiceConfig(GetServersPorts());
466   CheckRpcSendFailure(stub);
467 }
468
469 TEST_F(ServiceConfigEnd2endTest, ValidServiceConfigUpdatesTest) {
470   StartServers(1);
471   auto channel = BuildChannel();
472   auto stub = BuildStub(channel);
473   SetNextResolutionWithServiceConfig(GetServersPorts(), ValidServiceConfigV1());
474   CheckRpcSendOk(stub, DEBUG_LOCATION);
475   EXPECT_STREQ(ValidServiceConfigV1(), channel->GetServiceConfigJSON().c_str());
476   SetNextResolutionWithServiceConfig(GetServersPorts(), ValidServiceConfigV2());
477   CheckRpcSendOk(stub, DEBUG_LOCATION);
478   EXPECT_STREQ(ValidServiceConfigV2(), channel->GetServiceConfigJSON().c_str());
479 }
480
481 TEST_F(ServiceConfigEnd2endTest,
482        NoServiceConfigUpdateAfterValidServiceConfigTest) {
483   StartServers(1);
484   auto channel = BuildChannel();
485   auto stub = BuildStub(channel);
486   SetNextResolutionWithServiceConfig(GetServersPorts(), ValidServiceConfigV1());
487   CheckRpcSendOk(stub, DEBUG_LOCATION);
488   EXPECT_STREQ(ValidServiceConfigV1(), channel->GetServiceConfigJSON().c_str());
489   SetNextResolutionNoServiceConfig(GetServersPorts());
490   CheckRpcSendOk(stub, DEBUG_LOCATION);
491   EXPECT_STREQ("{}", channel->GetServiceConfigJSON().c_str());
492 }
493
494 TEST_F(ServiceConfigEnd2endTest,
495        NoServiceConfigUpdateAfterValidServiceConfigWithDefaultConfigTest) {
496   StartServers(1);
497   auto channel = BuildChannelWithDefaultServiceConfig();
498   auto stub = BuildStub(channel);
499   SetNextResolutionWithServiceConfig(GetServersPorts(), ValidServiceConfigV1());
500   CheckRpcSendOk(stub, DEBUG_LOCATION);
501   EXPECT_STREQ(ValidServiceConfigV1(), channel->GetServiceConfigJSON().c_str());
502   SetNextResolutionNoServiceConfig(GetServersPorts());
503   CheckRpcSendOk(stub, DEBUG_LOCATION);
504   EXPECT_STREQ(ValidDefaultServiceConfig(),
505                channel->GetServiceConfigJSON().c_str());
506 }
507
508 TEST_F(ServiceConfigEnd2endTest,
509        InvalidServiceConfigUpdateAfterValidServiceConfigTest) {
510   StartServers(1);
511   auto channel = BuildChannel();
512   auto stub = BuildStub(channel);
513   SetNextResolutionWithServiceConfig(GetServersPorts(), ValidServiceConfigV1());
514   CheckRpcSendOk(stub, DEBUG_LOCATION);
515   EXPECT_STREQ(ValidServiceConfigV1(), channel->GetServiceConfigJSON().c_str());
516   SetNextResolutionInvalidServiceConfig(GetServersPorts());
517   CheckRpcSendOk(stub, DEBUG_LOCATION);
518   EXPECT_STREQ(ValidServiceConfigV1(), channel->GetServiceConfigJSON().c_str());
519 }
520
521 TEST_F(ServiceConfigEnd2endTest,
522        InvalidServiceConfigUpdateAfterValidServiceConfigWithDefaultConfigTest) {
523   StartServers(1);
524   auto channel = BuildChannelWithDefaultServiceConfig();
525   auto stub = BuildStub(channel);
526   SetNextResolutionWithServiceConfig(GetServersPorts(), ValidServiceConfigV1());
527   CheckRpcSendOk(stub, DEBUG_LOCATION);
528   EXPECT_STREQ(ValidServiceConfigV1(), channel->GetServiceConfigJSON().c_str());
529   SetNextResolutionInvalidServiceConfig(GetServersPorts());
530   CheckRpcSendOk(stub, DEBUG_LOCATION);
531   EXPECT_STREQ(ValidServiceConfigV1(), channel->GetServiceConfigJSON().c_str());
532 }
533
534 TEST_F(ServiceConfigEnd2endTest,
535        ValidServiceConfigAfterInvalidServiceConfigTest) {
536   StartServers(1);
537   auto channel = BuildChannel();
538   auto stub = BuildStub(channel);
539   SetNextResolutionInvalidServiceConfig(GetServersPorts());
540   CheckRpcSendFailure(stub);
541   SetNextResolutionValidServiceConfig(GetServersPorts());
542   CheckRpcSendOk(stub, DEBUG_LOCATION);
543 }
544
545 TEST_F(ServiceConfigEnd2endTest, NoServiceConfigAfterInvalidServiceConfigTest) {
546   StartServers(1);
547   auto channel = BuildChannel();
548   auto stub = BuildStub(channel);
549   SetNextResolutionInvalidServiceConfig(GetServersPorts());
550   CheckRpcSendFailure(stub);
551   SetNextResolutionNoServiceConfig(GetServersPorts());
552   CheckRpcSendOk(stub, DEBUG_LOCATION);
553   EXPECT_STREQ("{}", channel->GetServiceConfigJSON().c_str());
554 }
555
556 TEST_F(ServiceConfigEnd2endTest,
557        AnotherInvalidServiceConfigAfterInvalidServiceConfigTest) {
558   StartServers(1);
559   auto channel = BuildChannel();
560   auto stub = BuildStub(channel);
561   SetNextResolutionInvalidServiceConfig(GetServersPorts());
562   CheckRpcSendFailure(stub);
563   SetNextResolutionInvalidServiceConfig(GetServersPorts());
564   CheckRpcSendFailure(stub);
565 }
566
567 TEST_F(ServiceConfigEnd2endTest, InvalidDefaultServiceConfigTest) {
568   StartServers(1);
569   auto channel = BuildChannelWithInvalidDefaultServiceConfig();
570   auto stub = BuildStub(channel);
571   // An invalid default service config results in a lame channel which fails all
572   // RPCs
573   CheckRpcSendFailure(stub);
574 }
575
576 TEST_F(ServiceConfigEnd2endTest,
577        InvalidDefaultServiceConfigTestWithValidServiceConfig) {
578   StartServers(1);
579   auto channel = BuildChannelWithInvalidDefaultServiceConfig();
580   auto stub = BuildStub(channel);
581   CheckRpcSendFailure(stub);
582   // An invalid default service config results in a lame channel which fails all
583   // RPCs
584   SetNextResolutionValidServiceConfig(GetServersPorts());
585   CheckRpcSendFailure(stub);
586 }
587
588 TEST_F(ServiceConfigEnd2endTest,
589        InvalidDefaultServiceConfigTestWithInvalidServiceConfig) {
590   StartServers(1);
591   auto channel = BuildChannelWithInvalidDefaultServiceConfig();
592   auto stub = BuildStub(channel);
593   CheckRpcSendFailure(stub);
594   // An invalid default service config results in a lame channel which fails all
595   // RPCs
596   SetNextResolutionInvalidServiceConfig(GetServersPorts());
597   CheckRpcSendFailure(stub);
598 }
599
600 TEST_F(ServiceConfigEnd2endTest,
601        InvalidDefaultServiceConfigTestWithNoServiceConfig) {
602   StartServers(1);
603   auto channel = BuildChannelWithInvalidDefaultServiceConfig();
604   auto stub = BuildStub(channel);
605   CheckRpcSendFailure(stub);
606   // An invalid default service config results in a lame channel which fails all
607   // RPCs
608   SetNextResolutionNoServiceConfig(GetServersPorts());
609   CheckRpcSendFailure(stub);
610 }
611
612 }  // namespace
613 }  // namespace testing
614 }  // namespace grpc
615
616 int main(int argc, char** argv) {
617   ::testing::InitGoogleTest(&argc, argv);
618   grpc::testing::TestEnvironment env(argc, argv);
619   const auto result = RUN_ALL_TESTS();
620   return result;
621 }