aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/channel
diff options
context:
space:
mode:
authorGravatar ncteisen <ncteisen@gmail.com>2018-10-12 12:25:57 -0400
committerGravatar ncteisen <ncteisen@gmail.com>2018-10-12 12:25:57 -0400
commit4377cbadaf6465660058304bca0f502f92d06a1e (patch)
treeb2f5c5bbd777f8e41cd2c50ae7ddc853d5908b9a /test/core/channel
parent8510e7f7d2410fa7e1d6abbfca7bfe320bc7a46d (diff)
Support channelz pagination
Diffstat (limited to 'test/core/channel')
-rw-r--r--test/core/channel/channelz_test.cc40
1 files changed, 39 insertions, 1 deletions
diff --git a/test/core/channel/channelz_test.cc b/test/core/channel/channelz_test.cc
index aed1fba47c..c9abc4465c 100644
--- a/test/core/channel/channelz_test.cc
+++ b/test/core/channel/channelz_test.cc
@@ -226,7 +226,19 @@ void ChannelzSleep(int64_t sleep_us) {
} // anonymous namespace
-class ChannelzChannelTest : public ::testing::TestWithParam<size_t> {};
+class ChannelzChannelTest : public ::testing::TestWithParam<size_t> {
+ protected:
+ // ensure we always have a fresh registry for tests.
+ void SetUp() override {
+ ChannelzRegistry::Shutdown();
+ ChannelzRegistry::Init();
+ }
+
+ void TearDown() override {
+ ChannelzRegistry::Shutdown();
+ ChannelzRegistry::Init();
+ }
+};
TEST_P(ChannelzChannelTest, BasicChannel) {
grpc_core::ExecCtx exec_ctx;
@@ -305,6 +317,32 @@ TEST(ChannelzGetTopChannelsTest, ManyChannelsTest) {
ValidateGetTopChannels(10);
}
+TEST(ChannelzGetTopChannelsTest, GetTopChannelsPagination) {
+ grpc_core::ExecCtx exec_ctx;
+ // this is over the pagination limit.
+ ChannelFixture channels[150];
+ (void)channels; // suppress unused variable error
+ char* json_str = ChannelzRegistry::GetTopChannels(0);
+ grpc::testing::ValidateGetTopChannelsResponseProtoJsonTranslation(json_str);
+ grpc_json* parsed_json = grpc_json_parse_string(json_str);
+ // 100 is the pagination limit.
+ ValidateJsonArraySize(parsed_json, "channel", 100);
+ grpc_json* end = GetJsonChild(parsed_json, "end");
+ EXPECT_EQ(end, nullptr);
+ grpc_json_destroy(parsed_json);
+ gpr_free(json_str);
+ // Now we get the rest
+ json_str = ChannelzRegistry::GetTopChannels(101);
+ grpc::testing::ValidateGetTopChannelsResponseProtoJsonTranslation(json_str);
+ parsed_json = grpc_json_parse_string(json_str);
+ ValidateJsonArraySize(parsed_json, "channel", 50);
+ end = GetJsonChild(parsed_json, "end");
+ ASSERT_NE(end, nullptr);
+ EXPECT_EQ(end->type, GRPC_JSON_TRUE);
+ grpc_json_destroy(parsed_json);
+ gpr_free(json_str);
+}
+
TEST(ChannelzGetTopChannelsTest, InternalChannelTest) {
grpc_core::ExecCtx exec_ctx;
ChannelFixture channels[10];