From a3400a8fcb8b5b8d4559e6466623ba69c4d2320b Mon Sep 17 00:00:00 2001 From: ncteisen Date: Fri, 19 Oct 2018 13:26:42 -0700 Subject: Add a test with more edge cases --- test/core/channel/channelz_test.cc | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'test/core/channel') diff --git a/test/core/channel/channelz_test.cc b/test/core/channel/channelz_test.cc index 4a1f53b924..5f27320512 100644 --- a/test/core/channel/channelz_test.cc +++ b/test/core/channel/channelz_test.cc @@ -423,6 +423,33 @@ TEST_F(ChannelzRegistryBasedTest, GetTopChannelsNoHitUuid) { gpr_free(json_str); } +TEST_F(ChannelzRegistryBasedTest, GetTopChannelsMoreGaps) { + grpc_core::ExecCtx exec_ctx; + ChannelFixture channel_with_uuid1; + { ServerFixture channel_with_uuid2; } + ChannelFixture channel_with_uuid3; + { ServerFixture server_with_uuid4; } + ChannelFixture channel_with_uuid5; + // Current state of list: [1, NULL, 3, NULL, 5] + char* json_str = ChannelzRegistry::GetTopChannels(2); + grpc_json* parsed_json = grpc_json_parse_string(json_str); + ValidateJsonArraySize(parsed_json, "channel", 2); + grpc_json* json_channels = GetJsonChild(parsed_json, "channel"); + std::vector uuids = GetUuidListFromArray(json_channels); + EXPECT_EQ(static_cast(3), uuids[0]); + EXPECT_EQ(static_cast(5), uuids[1]); + grpc_json_destroy(parsed_json); + gpr_free(json_str); + json_str = ChannelzRegistry::GetTopChannels(4); + parsed_json = grpc_json_parse_string(json_str); + ValidateJsonArraySize(parsed_json, "channel", 1); + json_channels = GetJsonChild(parsed_json, "channel"); + uuids = GetUuidListFromArray(json_channels); + EXPECT_EQ(static_cast(5), uuids[0]); + grpc_json_destroy(parsed_json); + gpr_free(json_str); +} + TEST_F(ChannelzRegistryBasedTest, GetTopChannelsUuidAfterCompaction) { const intptr_t kLoopIterations = 50; grpc_core::ExecCtx exec_ctx; -- cgit v1.2.3