Added basic tests for GetErrorGetStatus (#29918)

* Add test

* Fix ASAN errors

* Fix log string
pull/29929/head
Esun Kim 3 years ago committed by GitHub
parent 7a63bd5407
commit df3ce20913
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      src/core/lib/transport/transport_op_string.cc
  2. 41
      test/core/transport/error_utils_test.cc

@ -113,8 +113,8 @@ std::string grpc_transport_op_string(grpc_transport_op* op) {
}
if (op->goaway_error != GRPC_ERROR_NONE) {
out.push_back(absl::StrCat(" SEND_GOAWAY:%s",
grpc_error_std_string(op->goaway_error)));
out.push_back(
absl::StrCat(" SEND_GOAWAY:", grpc_error_std_string(op->goaway_error)));
}
if (op->set_accept_stream) {

@ -20,11 +20,52 @@
#include "absl/status/status.h"
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/slice/slice_internal.h"
#include "test/core/util/test_config.h"
namespace {
TEST(ErrorUtilsTest, GetErrorGetStatusNone) {
grpc_error_handle error = GRPC_ERROR_NONE;
grpc_status_code code;
std::string message;
grpc_error_get_status(error, grpc_core::Timestamp(), &code, &message, nullptr,
nullptr);
ASSERT_EQ(code, GRPC_STATUS_OK);
ASSERT_EQ(message, "");
}
TEST(ErrorUtilsTest, GetErrorGetStatusFlat) {
grpc_error_handle error =
grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING("Msg"),
GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_CANCELLED);
grpc_status_code code;
std::string message;
grpc_error_get_status(error, grpc_core::Timestamp(), &code, &message, nullptr,
nullptr);
ASSERT_EQ(code, GRPC_STATUS_CANCELLED);
ASSERT_EQ(message, "Msg");
GRPC_ERROR_UNREF(error);
}
TEST(ErrorUtilsTest, GetErrorGetStatusChild) {
std::vector<grpc_error_handle> children = {
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Child1"),
grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING("Child2"),
GRPC_ERROR_INT_GRPC_STATUS,
GRPC_STATUS_RESOURCE_EXHAUSTED),
};
grpc_error_handle error = GRPC_ERROR_CREATE_FROM_VECTOR("Parent", &children);
grpc_status_code code;
std::string message;
grpc_error_get_status(error, grpc_core::Timestamp(), &code, &message, nullptr,
nullptr);
ASSERT_EQ(code, GRPC_STATUS_RESOURCE_EXHAUSTED);
ASSERT_EQ(message, "Child2");
GRPC_ERROR_UNREF(error);
}
// ---- Ok Status ----
TEST(ErrorUtilsTest, AbslOkToGrpcError) {
grpc_error_handle error = absl_status_to_grpc_error(absl::OkStatus());

Loading…
Cancel
Save