When seeing an error in interop test, also log the debug error string.

pull/13837/head
yang-g 7 years ago
parent 0dd982cf4c
commit 19d1eb2228
  1. 69
      test/cpp/interop/interop_client.cc
  2. 6
      test/cpp/interop/interop_client.h

@ -122,7 +122,8 @@ InteropClient::InteropClient(std::shared_ptr<Channel> channel,
: serviceStub_(channel, new_stub_every_test_case), : serviceStub_(channel, new_stub_every_test_case),
do_not_abort_on_transient_failures_(do_not_abort_on_transient_failures) {} do_not_abort_on_transient_failures_(do_not_abort_on_transient_failures) {}
bool InteropClient::AssertStatusOk(const Status& s) { bool InteropClient::AssertStatusOk(const Status& s,
const grpc::string& optional_debug_string) {
if (s.ok()) { if (s.ok()) {
return true; return true;
} }
@ -131,17 +132,21 @@ bool InteropClient::AssertStatusOk(const Status& s) {
// already checked for s.ok() above). So, the following will call abort() // already checked for s.ok() above). So, the following will call abort()
// (unless s.error_code() corresponds to a transient failure and // (unless s.error_code() corresponds to a transient failure and
// 'do_not_abort_on_transient_failures' is true) // 'do_not_abort_on_transient_failures' is true)
return AssertStatusCode(s, StatusCode::OK); return AssertStatusCode(s, StatusCode::OK, optional_debug_string);
} }
bool InteropClient::AssertStatusCode(const Status& s, bool InteropClient::AssertStatusCode(
StatusCode expected_code) { const Status& s, StatusCode expected_code,
const grpc::string& optional_debug_string) {
if (s.error_code() == expected_code) { if (s.error_code() == expected_code) {
return true; return true;
} }
gpr_log(GPR_ERROR, "Error status code: %d (expected: %d), message: %s", gpr_log(GPR_ERROR,
s.error_code(), expected_code, s.error_message().c_str()); "Error status code: %d (expected: %d), message: %s,"
" debug string: %s",
s.error_code(), expected_code, s.error_message().c_str(),
optional_debug_string.c_str());
// In case of transient transient/retryable failures (like a broken // In case of transient transient/retryable failures (like a broken
// connection) we may or may not abort (see TransientFailureOrAbort()) // connection) we may or may not abort (see TransientFailureOrAbort())
@ -161,7 +166,7 @@ bool InteropClient::DoEmpty() {
Status s = serviceStub_.Get()->EmptyCall(&context, request, &response); Status s = serviceStub_.Get()->EmptyCall(&context, request, &response);
if (!AssertStatusOk(s)) { if (!AssertStatusOk(s, context.debug_error_string())) {
return false; return false;
} }
@ -191,7 +196,7 @@ bool InteropClient::PerformLargeUnary(SimpleRequest* request,
} }
Status s = serviceStub_.Get()->UnaryCall(&context, *request, response); Status s = serviceStub_.Get()->UnaryCall(&context, *request, response);
if (!AssertStatusOk(s)) { if (!AssertStatusOk(s, context.debug_error_string())) {
return false; return false;
} }
@ -241,7 +246,7 @@ bool InteropClient::DoOauth2AuthToken(const grpc::string& username,
Status s = serviceStub_.Get()->UnaryCall(&context, request, &response); Status s = serviceStub_.Get()->UnaryCall(&context, request, &response);
if (!AssertStatusOk(s)) { if (!AssertStatusOk(s, context.debug_error_string())) {
return false; return false;
} }
@ -269,7 +274,7 @@ bool InteropClient::DoPerRpcCreds(const grpc::string& json_key) {
Status s = serviceStub_.Get()->UnaryCall(&context, request, &response); Status s = serviceStub_.Get()->UnaryCall(&context, request, &response);
if (!AssertStatusOk(s)) { if (!AssertStatusOk(s, context.debug_error_string())) {
return false; return false;
} }
@ -412,7 +417,7 @@ bool InteropClient::DoRequestStreaming() {
GPR_ASSERT(stream->WritesDone()); GPR_ASSERT(stream->WritesDone());
Status s = stream->Finish(); Status s = stream->Finish();
if (!AssertStatusOk(s)) { if (!AssertStatusOk(s, context.debug_error_string())) {
return false; return false;
} }
@ -451,7 +456,7 @@ bool InteropClient::DoResponseStreaming() {
} }
Status s = stream->Finish(); Status s = stream->Finish();
if (!AssertStatusOk(s)) { if (!AssertStatusOk(s, context.debug_error_string())) {
return false; return false;
} }
@ -516,7 +521,7 @@ bool InteropClient::DoClientCompressedStreaming() {
GPR_ASSERT(stream->WritesDone()); GPR_ASSERT(stream->WritesDone());
s = stream->Finish(); s = stream->Finish();
if (!AssertStatusOk(s)) { if (!AssertStatusOk(s, context.debug_error_string())) {
return false; return false;
} }
@ -578,7 +583,7 @@ bool InteropClient::DoServerCompressedStreaming() {
} }
Status s = stream->Finish(); Status s = stream->Finish();
if (!AssertStatusOk(s)) { if (!AssertStatusOk(s, context.debug_error_string())) {
return false; return false;
} }
return true; return true;
@ -619,7 +624,7 @@ bool InteropClient::DoResponseStreamingWithSlowConsumer() {
} }
Status s = stream->Finish(); Status s = stream->Finish();
if (!AssertStatusOk(s)) { if (!AssertStatusOk(s, context.debug_error_string())) {
return false; return false;
} }
@ -666,7 +671,7 @@ bool InteropClient::DoHalfDuplex() {
} }
Status s = stream->Finish(); Status s = stream->Finish();
if (!AssertStatusOk(s)) { if (!AssertStatusOk(s, context.debug_error_string())) {
return false; return false;
} }
@ -710,7 +715,7 @@ bool InteropClient::DoPingPong() {
GPR_ASSERT(!stream->Read(&response)); GPR_ASSERT(!stream->Read(&response));
Status s = stream->Finish(); Status s = stream->Finish();
if (!AssertStatusOk(s)) { if (!AssertStatusOk(s, context.debug_error_string())) {
return false; return false;
} }
@ -732,7 +737,8 @@ bool InteropClient::DoCancelAfterBegin() {
context.TryCancel(); context.TryCancel();
Status s = stream->Finish(); Status s = stream->Finish();
if (!AssertStatusCode(s, StatusCode::CANCELLED)) { if (!AssertStatusCode(s, StatusCode::CANCELLED,
context.debug_error_string())) {
return false; return false;
} }
@ -790,7 +796,8 @@ bool InteropClient::DoTimeoutOnSleepingServer() {
stream->Write(request); stream->Write(request);
Status s = stream->Finish(); Status s = stream->Finish();
if (!AssertStatusCode(s, StatusCode::DEADLINE_EXCEEDED)) { if (!AssertStatusCode(s, StatusCode::DEADLINE_EXCEEDED,
context.debug_error_string())) {
return false; return false;
} }
@ -810,7 +817,7 @@ bool InteropClient::DoEmptyStream() {
GPR_ASSERT(stream->Read(&response) == false); GPR_ASSERT(stream->Read(&response) == false);
Status s = stream->Finish(); Status s = stream->Finish();
if (!AssertStatusOk(s)) { if (!AssertStatusOk(s, context.debug_error_string())) {
return false; return false;
} }
@ -833,7 +840,8 @@ bool InteropClient::DoStatusWithMessage() {
requested_status->set_code(test_code); requested_status->set_code(test_code);
requested_status->set_message(test_msg); requested_status->set_message(test_msg);
Status s = serviceStub_.Get()->UnaryCall(&context, request, &response); Status s = serviceStub_.Get()->UnaryCall(&context, request, &response);
if (!AssertStatusCode(s, grpc::StatusCode::UNKNOWN)) { if (!AssertStatusCode(s, grpc::StatusCode::UNKNOWN,
context.debug_error_string())) {
return false; return false;
} }
GPR_ASSERT(s.error_message() == test_msg); GPR_ASSERT(s.error_message() == test_msg);
@ -853,7 +861,8 @@ bool InteropClient::DoStatusWithMessage() {
while (stream->Read(&streaming_response)) while (stream->Read(&streaming_response))
; ;
s = stream->Finish(); s = stream->Finish();
if (!AssertStatusCode(s, grpc::StatusCode::UNKNOWN)) { if (!AssertStatusCode(s, grpc::StatusCode::UNKNOWN,
context.debug_error_string())) {
return false; return false;
} }
GPR_ASSERT(s.error_message() == test_msg); GPR_ASSERT(s.error_message() == test_msg);
@ -880,7 +889,7 @@ bool InteropClient::DoCacheableUnary() {
context1.AddMetadata("x-user-ip", "1.2.3.4"); context1.AddMetadata("x-user-ip", "1.2.3.4");
Status s1 = Status s1 =
serviceStub_.Get()->CacheableUnaryCall(&context1, request, &response1); serviceStub_.Get()->CacheableUnaryCall(&context1, request, &response1);
if (!AssertStatusOk(s1)) { if (!AssertStatusOk(s1, context1.debug_error_string())) {
return false; return false;
} }
gpr_log(GPR_DEBUG, "response 1 payload: %s", gpr_log(GPR_DEBUG, "response 1 payload: %s",
@ -893,7 +902,7 @@ bool InteropClient::DoCacheableUnary() {
context2.AddMetadata("x-user-ip", "1.2.3.4"); context2.AddMetadata("x-user-ip", "1.2.3.4");
Status s2 = Status s2 =
serviceStub_.Get()->CacheableUnaryCall(&context2, request, &response2); serviceStub_.Get()->CacheableUnaryCall(&context2, request, &response2);
if (!AssertStatusOk(s2)) { if (!AssertStatusOk(s2, context2.debug_error_string())) {
return false; return false;
} }
gpr_log(GPR_DEBUG, "response 2 payload: %s", gpr_log(GPR_DEBUG, "response 2 payload: %s",
@ -915,7 +924,7 @@ bool InteropClient::DoCacheableUnary() {
context3.AddMetadata("x-user-ip", "1.2.3.4"); context3.AddMetadata("x-user-ip", "1.2.3.4");
Status s3 = Status s3 =
serviceStub_.Get()->CacheableUnaryCall(&context3, request1, &response3); serviceStub_.Get()->CacheableUnaryCall(&context3, request1, &response3);
if (!AssertStatusOk(s3)) { if (!AssertStatusOk(s3, context3.debug_error_string())) {
return false; return false;
} }
gpr_log(GPR_DEBUG, "response 3 payload: %s", gpr_log(GPR_DEBUG, "response 3 payload: %s",
@ -946,7 +955,7 @@ bool InteropClient::DoCustomMetadata() {
request.mutable_payload()->set_body(payload.c_str(), kLargeRequestSize); request.mutable_payload()->set_body(payload.c_str(), kLargeRequestSize);
Status s = serviceStub_.Get()->UnaryCall(&context, request, &response); Status s = serviceStub_.Get()->UnaryCall(&context, request, &response);
if (!AssertStatusOk(s)) { if (!AssertStatusOk(s, context.debug_error_string())) {
return false; return false;
} }
@ -997,7 +1006,7 @@ bool InteropClient::DoCustomMetadata() {
GPR_ASSERT(!stream->Read(&response)); GPR_ASSERT(!stream->Read(&response));
Status s = stream->Finish(); Status s = stream->Finish();
if (!AssertStatusOk(s)) { if (!AssertStatusOk(s, context.debug_error_string())) {
return false; return false;
} }
@ -1028,7 +1037,8 @@ bool InteropClient::DoUnimplementedService() {
Status s = stub->UnimplementedCall(&context, request, &response); Status s = stub->UnimplementedCall(&context, request, &response);
if (!AssertStatusCode(s, StatusCode::UNIMPLEMENTED)) { if (!AssertStatusCode(s, StatusCode::UNIMPLEMENTED,
context.debug_error_string())) {
return false; return false;
} }
@ -1046,7 +1056,8 @@ bool InteropClient::DoUnimplementedMethod() {
Status s = Status s =
serviceStub_.Get()->UnimplementedCall(&context, request, &response); serviceStub_.Get()->UnimplementedCall(&context, request, &response);
if (!AssertStatusCode(s, StatusCode::UNIMPLEMENTED)) { if (!AssertStatusCode(s, StatusCode::UNIMPLEMENTED,
context.debug_error_string())) {
return false; return false;
} }

@ -103,8 +103,10 @@ class InteropClient {
/// Run \a custom_check_fn as an additional check. /// Run \a custom_check_fn as an additional check.
bool PerformLargeUnary(SimpleRequest* request, SimpleResponse* response, bool PerformLargeUnary(SimpleRequest* request, SimpleResponse* response,
CheckerFn custom_checks_fn); CheckerFn custom_checks_fn);
bool AssertStatusOk(const Status& s); bool AssertStatusOk(const Status& s,
bool AssertStatusCode(const Status& s, StatusCode expected_code); const grpc::string& optional_debug_string);
bool AssertStatusCode(const Status& s, StatusCode expected_code,
const grpc::string& optional_debug_string);
bool TransientFailureOrAbort(); bool TransientFailureOrAbort();
ServiceStub serviceStub_; ServiceStub serviceStub_;

Loading…
Cancel
Save