Merge pull request #2808 from a11r/status_interop

Added interop test for status_code_with_message
pull/2809/head
Yang Gao 10 years ago
commit 507bdb4c03
  1. 6
      test/cpp/interop/client.cc
  2. 19
      test/cpp/interop/interop_client.cc
  3. 1
      test/cpp/interop/interop_client.h
  4. 7
      test/cpp/interop/server.cc

@ -70,6 +70,7 @@ DEFINE_string(test_case, "large_unary",
"jwt_token_creds: large_unary with JWT token auth; "
"oauth2_auth_token: raw oauth2 access token auth; "
"per_rpc_creds: raw oauth2 access token on a single rpc; "
"status_code_and_message: verify status code & message; "
"all : all of above.");
DEFINE_string(default_service_account, "",
"Email of GCE default service account");
@ -82,7 +83,7 @@ using grpc::testing::GetServiceAccountJsonKey;
int main(int argc, char** argv) {
grpc::testing::InitTest(&argc, &argv, true);
gpr_log(GPR_INFO, "Testing these cases: %s", FLAGS_test_case.c_str());
int ret = 0;
grpc::testing::InteropClient client(
CreateChannelForTestCase(FLAGS_test_case));
@ -121,6 +122,8 @@ int main(int argc, char** argv) {
} else if (FLAGS_test_case == "per_rpc_creds") {
grpc::string json_key = GetServiceAccountJsonKey();
client.DoPerRpcCreds(json_key, FLAGS_oauth_scope);
} else if (FLAGS_test_case == "status_code_and_message") {
client.DoStatusWithMessage();
} else if (FLAGS_test_case == "all") {
client.DoEmpty();
client.DoLargeUnary();
@ -131,6 +134,7 @@ int main(int argc, char** argv) {
client.DoCancelAfterBegin();
client.DoCancelAfterFirstResponse();
client.DoTimeoutOnSleepingServer();
client.DoStatusWithMessage();
// service_account_creds and jwt_token_creds can only run with ssl.
if (FLAGS_enable_ssl) {
grpc::string json_key = GetServiceAccountJsonKey();

@ -423,5 +423,24 @@ void InteropClient::DoTimeoutOnSleepingServer() {
gpr_log(GPR_INFO, "Pingpong streaming timeout done.");
}
void InteropClient::DoStatusWithMessage() {
gpr_log(GPR_INFO, "Sending RPC with a request for status code 2 and message");
std::unique_ptr<TestService::Stub> stub(TestService::NewStub(channel_));
ClientContext context;
SimpleRequest request;
SimpleResponse response;
EchoStatus *requested_status = request.mutable_response_status();
requested_status->set_code(grpc::StatusCode::UNKNOWN);
grpc::string test_msg = "This is a test message";
requested_status->set_message(test_msg);
Status s = stub->UnaryCall(&context, request, &response);
GPR_ASSERT(s.error_code() == grpc::StatusCode::UNKNOWN);
GPR_ASSERT(s.error_message() == test_msg);
gpr_log(GPR_INFO, "Done testing Status and Message");
}
} // namespace testing
} // namespace grpc

@ -60,6 +60,7 @@ class InteropClient {
void DoCancelAfterBegin();
void DoCancelAfterFirstResponse();
void DoTimeoutOnSleepingServer();
void DoStatusWithMessage();
// Auth tests.
// username is a string containing the user email
void DoJwtTokenCreds(const grpc::string& username);

@ -105,6 +105,13 @@ class TestServiceImpl : public TestService::Service {
return Status(grpc::StatusCode::INTERNAL, "Error creating payload.");
}
}
if (request->has_response_status()) {
return Status(static_cast<grpc::StatusCode>
(request->response_status().code()),
request->response_status().message());
}
return Status::OK;
}

Loading…
Cancel
Save