Review feedback

reviewable/pr15343/r8
ncteisen 7 years ago
parent 7e7edc95b3
commit 9b488f788b
  1. 6
      src/core/lib/channel/channelz.cc
  2. 15
      test/core/channel/channelz_test.cc
  3. 4
      test/core/end2end/tests/simple_request.cc

@ -165,11 +165,11 @@ char* Channel::RenderJSON() {
// We use -1 as sentinel values since proto default value for integers is // We use -1 as sentinel values since proto default value for integers is
// zero, and the confuses the parser into thinking the value weren't present // zero, and the confuses the parser into thinking the value weren't present
json_iterator = add_num_str(json, json_iterator, "callsStarted", json_iterator = add_num_str(json, json_iterator, "callsStarted",
calls_started_ ? calls_started_ : -1); calls_started_);
json_iterator = add_num_str(json, json_iterator, "callsSucceeded", json_iterator = add_num_str(json, json_iterator, "callsSucceeded",
calls_succeeded_ ? calls_succeeded_ : -1); calls_succeeded_);
json_iterator = add_num_str(json, json_iterator, "callsFailed", json_iterator = add_num_str(json, json_iterator, "callsFailed",
calls_failed_ ? calls_failed_ : -1); calls_failed_);
gpr_timespec ts = gpr_timespec ts =
grpc_millis_to_timespec(last_call_started_millis_, GPR_CLOCK_REALTIME); grpc_millis_to_timespec(last_call_started_millis_, GPR_CLOCK_REALTIME);
json_iterator = json_iterator =

@ -101,9 +101,7 @@ void ValidateChildInteger(grpc_json* json, int64_t expect, const char* key) {
EXPECT_EQ(gotten_number, expect); EXPECT_EQ(gotten_number, expect);
} }
void ValidateChannel(Channel* channel, validate_channel_data_args args) { void ValidateCounters(char* json_str, validate_channel_data_args args) {
char* json_str = channel->RenderJSON();
grpc::testing::ValidateChannelProtoJsonTranslation(json_str);
grpc_json* json = grpc_json_parse_string(json_str); grpc_json* json = grpc_json_parse_string(json_str);
EXPECT_NE(json, nullptr); EXPECT_NE(json, nullptr);
grpc_json* data = GetJsonChild(json, "data"); grpc_json* data = GetJsonChild(json, "data");
@ -111,7 +109,14 @@ void ValidateChannel(Channel* channel, validate_channel_data_args args) {
ValidateChildInteger(data, args.calls_failed, "callsFailed"); ValidateChildInteger(data, args.calls_failed, "callsFailed");
ValidateChildInteger(data, args.calls_succeeded, "callsSucceeded"); ValidateChildInteger(data, args.calls_succeeded, "callsSucceeded");
grpc_json_destroy(json); grpc_json_destroy(json);
}
void ValidateChannel(Channel* channel, validate_channel_data_args args) {
char* json_str = channel->RenderJSON();
grpc::testing::ValidateChannelProtoJsonTranslation(json_str);
ValidateCounters(json_str, args);
gpr_free(json_str); gpr_free(json_str);
} }
grpc_millis GetLastCallStartedMillis(Channel* channel) { grpc_millis GetLastCallStartedMillis(Channel* channel) {
@ -134,7 +139,9 @@ TEST_P(ChannelzChannelTest, BasicChannel) {
ChannelFixture channel(GetParam()); ChannelFixture channel(GetParam());
intptr_t uuid = grpc_channel_get_uuid(channel.channel()); intptr_t uuid = grpc_channel_get_uuid(channel.channel());
Channel* channelz_channel = ChannelzRegistry::Get<Channel>(uuid); Channel* channelz_channel = ChannelzRegistry::Get<Channel>(uuid);
ValidateChannel(channelz_channel, {-1, -1, -1}); char* json_str = channelz_channel->RenderJSON();
ValidateCounters(json_str, {0, 0, 0});
gpr_free(json_str);
} }
TEST_P(ChannelzChannelTest, BasicChannelAPIFunctionality) { TEST_P(ChannelzChannelTest, BasicChannelAPIFunctionality) {

@ -263,7 +263,7 @@ static void test_invoke_simple_request(grpc_end2end_test_config config) {
char* json = channelz_channel->RenderJSON(); char* json = channelz_channel->RenderJSON();
GPR_ASSERT(nullptr != strstr(json, "\"callsStarted\":\"1\"")); GPR_ASSERT(nullptr != strstr(json, "\"callsStarted\":\"1\""));
GPR_ASSERT(nullptr != strstr(json, "\"callsFailed\":\"1\"")); GPR_ASSERT(nullptr != strstr(json, "\"callsFailed\":\"1\""));
GPR_ASSERT(nullptr != strstr(json, "\"callsSucceeded\":\"-1\"")); GPR_ASSERT(nullptr != strstr(json, "\"callsSucceeded\":\"0\""));
gpr_free(json); gpr_free(json);
end_test(&f); end_test(&f);
@ -286,7 +286,7 @@ static void test_invoke_10_simple_requests(grpc_end2end_test_config config) {
char* json = channelz_channel->RenderJSON(); char* json = channelz_channel->RenderJSON();
GPR_ASSERT(nullptr != strstr(json, "\"callsStarted\":\"10\"")); GPR_ASSERT(nullptr != strstr(json, "\"callsStarted\":\"10\""));
GPR_ASSERT(nullptr != strstr(json, "\"callsFailed\":\"10\"")); GPR_ASSERT(nullptr != strstr(json, "\"callsFailed\":\"10\""));
GPR_ASSERT(nullptr != strstr(json, "\"callsSucceeded\":\"-1\"")); GPR_ASSERT(nullptr != strstr(json, "\"callsSucceeded\":\"0\""));
gpr_free(json); gpr_free(json);
end_test(&f); end_test(&f);
config.tear_down_data(&f); config.tear_down_data(&f);

Loading…
Cancel
Save