diff options
author | Noah Eisen <ncteisen@gmail.com> | 2017-11-29 15:18:24 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-29 15:18:24 -0800 |
commit | c49b24a7c03a262e242b18066f252415cd4afc8a (patch) | |
tree | 30a8303aa46df040cf8d6ed05ff61bf7dbeab153 | |
parent | bf51c97fd67c0cefc49791b698b1baa0b5020bed (diff) | |
parent | 9b6283a95223546805ea794d3b7b4126b104f0eb (diff) |
Merge pull request #13549 from ncteisen/test-error-string-api
Add test for RecvStatus error_string API
-rw-r--r-- | include/grpc/impl/codegen/grpc_types.h | 2 | ||||
-rw-r--r-- | test/core/end2end/tests/simple_request.cc | 12 |
2 files changed, 13 insertions, 1 deletions
diff --git a/include/grpc/impl/codegen/grpc_types.h b/include/grpc/impl/codegen/grpc_types.h index c8c1437c91..ad668b4f11 100644 --- a/include/grpc/impl/codegen/grpc_types.h +++ b/include/grpc/impl/codegen/grpc_types.h @@ -560,7 +560,7 @@ typedef struct grpc_op { grpc_slice* status_details; /** If this is not nullptr, it will be populated with the full fidelity * error string for debugging purposes. The application is responsible - * for freeing the data. */ + * for freeing the data by using gpr_free(). */ const char** error_string; } recv_status_on_client; struct grpc_op_recv_close_on_server { diff --git a/test/core/end2end/tests/simple_request.cc b/test/core/end2end/tests/simple_request.cc index ec7425aa09..7eb7467981 100644 --- a/test/core/end2end/tests/simple_request.cc +++ b/test/core/end2end/tests/simple_request.cc @@ -99,6 +99,7 @@ static void simple_request_body(grpc_end2end_test_config config, grpc_metadata_array request_metadata_recv; grpc_call_details call_details; grpc_status_code status; + const char* error_string; grpc_call_error error; grpc_slice details; int was_cancelled = 2; @@ -148,6 +149,7 @@ static void simple_request_body(grpc_end2end_test_config config, op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.error_string = &error_string; op->flags = 0; op->reserved = nullptr; op++; @@ -199,6 +201,15 @@ static void simple_request_body(grpc_end2end_test_config config, GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED); GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); + // the following sanity check makes sure that the requested error string is + // correctly populated by the core. It looks for certain substrings that are + // not likely to change much. Some parts of the error, like time created, + // obviously are not checked. + GPR_ASSERT(nullptr != strstr(error_string, "xyz")); + GPR_ASSERT(nullptr != strstr(error_string, "description")); + GPR_ASSERT(nullptr != strstr(error_string, "Error received from peer")); + GPR_ASSERT(nullptr != strstr(error_string, "grpc_message")); + GPR_ASSERT(nullptr != strstr(error_string, "grpc_status")); GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); @@ -206,6 +217,7 @@ static void simple_request_body(grpc_end2end_test_config config, GPR_ASSERT(was_cancelled == 1); grpc_slice_unref(details); + gpr_free((void*)error_string); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); |