aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/core/lib/channel/channelz_registry.cc2
-rw-r--r--test/core/channel/channelz_test.cc27
2 files changed, 28 insertions, 1 deletions
diff --git a/src/core/lib/channel/channelz_registry.cc b/src/core/lib/channel/channelz_registry.cc
index 89d0573280..1fe2fad3e1 100644
--- a/src/core/lib/channel/channelz_registry.cc
+++ b/src/core/lib/channel/channelz_registry.cc
@@ -103,7 +103,7 @@ int ChannelzRegistry::FindByUuidLocked(intptr_t target_uuid,
right = true_middle - 1;
}
}
- return direct_hit_needed ? -1 : right;
+ return direct_hit_needed ? -1 : left;
}
void ChannelzRegistry::InternalUnregister(intptr_t uuid) {
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<intptr_t> uuids = GetUuidListFromArray(json_channels);
+ EXPECT_EQ(static_cast<intptr_t>(3), uuids[0]);
+ EXPECT_EQ(static_cast<intptr_t>(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<intptr_t>(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;