From ca5cdf454c246849991bc6561c9143ca0b270675 Mon Sep 17 00:00:00 2001
From: Noah Eisen <ncteisen@google.com>
Date: Thu, 27 Oct 2016 18:01:37 -0700
Subject: [PATCH] Add unimplemented_service test case for cpp interop client

---
 test/cpp/interop/client.cc         |  9 +++++++--
 test/cpp/interop/interop_client.cc | 26 ++++++++++++++++++++++++++
 test/cpp/interop/interop_client.h  |  2 ++
 3 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/test/cpp/interop/client.cc b/test/cpp/interop/client.cc
index 4197ba8bab..9e0e502d20 100644
--- a/test/cpp/interop/client.cc
+++ b/test/cpp/interop/client.cc
@@ -80,7 +80,8 @@ DEFINE_string(test_case, "large_unary",
               "slow client consumer;\n"
               "status_code_and_message: verify status code & message;\n"
               "timeout_on_sleeping_server: deadline exceeds on stream;\n"
-              "unimplemented_method: client calls an unimplemented method;\n");
+              "unimplemented_method: client calls an unimplemented method;\n"
+              "unimplemented_service: client calls an unimplemented service;\n");
 DEFINE_string(default_service_account, "",
               "Email of GCE default service account");
 DEFINE_string(service_account_key_file, "",
@@ -152,6 +153,8 @@ int main(int argc, char** argv) {
     client.DoCustomMetadata();
   } else if (FLAGS_test_case == "unimplemented_method") {
     client.DoUnimplementedMethod();
+  } else if (FLAGS_test_case == "unimplemented_service") {
+    client.DoUnimplementedService();
   } else if (FLAGS_test_case == "cacheable_unary") {
     client.DoCacheableUnary();
   } else if (FLAGS_test_case == "all") {
@@ -172,6 +175,7 @@ int main(int argc, char** argv) {
     client.DoStatusWithMessage();
     client.DoCustomMetadata();
     client.DoUnimplementedMethod();
+    client.DoUnimplementedService();
     client.DoCacheableUnary();
     // service_account_creds and jwt_token_creds can only run with ssl.
     if (FLAGS_use_tls) {
@@ -207,7 +211,8 @@ int main(int argc, char** argv) {
                                "server_streaming",
                                "status_code_and_message",
                                "timeout_on_sleeping_server",
-                               "unimplemented_method"};
+                               "unimplemented_method",
+                               "unimplemented_service"};
     char* joined_testcases =
         gpr_strjoin_sep(testcases, GPR_ARRAY_SIZE(testcases), "\n", NULL);
 
diff --git a/test/cpp/interop/interop_client.cc b/test/cpp/interop/interop_client.cc
index 1668589cc4..d0dd0718aa 100644
--- a/test/cpp/interop/interop_client.cc
+++ b/test/cpp/interop/interop_client.cc
@@ -107,6 +107,11 @@ TestService::Stub* InteropClient::ServiceStub::Get() {
   return stub_.get();
 }
 
+UnimplementedService::Stub*
+InteropClient::ServiceStub::GetUnimplementedServiceStub() {
+  return UnimplementedService::NewStub(channel_).get();
+}
+
 void InteropClient::ServiceStub::Reset(std::shared_ptr<Channel> channel) {
   channel_ = channel;
 
@@ -1002,6 +1007,27 @@ bool InteropClient::DoCustomMetadata() {
   return true;
 }
 
+bool InteropClient::DoUnimplementedService() {
+  gpr_log(GPR_DEBUG, "Sending a request for an unimplemented service...");
+
+  Empty request = Empty::default_instance();
+  Empty response = Empty::default_instance();
+  ClientContext context;
+
+  UnimplementedService::Stub* stub =
+      serviceStub_.GetUnimplementedServiceStub();
+
+  Status s =
+      stub->UnimplementedCall(&context, request, &response);
+
+  if (!AssertStatusCode(s, StatusCode::UNIMPLEMENTED)) {
+    return false;
+  }
+
+  gpr_log(GPR_DEBUG, "unimplemented service done.");
+  return true;
+}
+
 bool InteropClient::DoUnimplementedMethod() {
   gpr_log(GPR_DEBUG, "Sending a request for an unimplemented rpc...");
 
diff --git a/test/cpp/interop/interop_client.h b/test/cpp/interop/interop_client.h
index 0a96e7734d..7ec7ebee20 100644
--- a/test/cpp/interop/interop_client.h
+++ b/test/cpp/interop/interop_client.h
@@ -80,6 +80,7 @@ class InteropClient {
   bool DoStatusWithMessage();
   bool DoCustomMetadata();
   bool DoUnimplementedMethod();
+  bool DoUnimplementedService();
   bool DoCacheableUnary();
   // Auth tests.
   // username is a string containing the user email
@@ -100,6 +101,7 @@ class InteropClient {
     ServiceStub(std::shared_ptr<Channel> channel, bool new_stub_every_call);
 
     TestService::Stub* Get();
+    UnimplementedService::Stub* GetUnimplementedServiceStub();
 
     void Reset(std::shared_ptr<Channel> channel);
 
-- 
GitLab