|
|
|
@ -24,6 +24,7 @@ |
|
|
|
|
|
|
|
|
|
#include <grpc/support/alloc.h> |
|
|
|
|
#include <grpc/support/log.h> |
|
|
|
|
#include <grpc/support/string_util.h> |
|
|
|
|
|
|
|
|
|
#include "src/core/lib/channel/channel_trace.h" |
|
|
|
|
#include "src/core/lib/channel/channelz.h" |
|
|
|
@ -33,7 +34,6 @@ |
|
|
|
|
#include "src/core/lib/iomgr/exec_ctx.h" |
|
|
|
|
#include "src/core/lib/json/json.h" |
|
|
|
|
#include "src/core/lib/surface/channel.h" |
|
|
|
|
|
|
|
|
|
#include "test/core/util/test_config.h" |
|
|
|
|
|
|
|
|
|
#include <stdlib.h> |
|
|
|
@ -51,9 +51,13 @@ class ChannelzRegistryTest : public ::testing::Test { |
|
|
|
|
void TearDown() override { ChannelzRegistry::Shutdown(); } |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
static RefCountedPtr<BaseNode> CreateTestNode() { |
|
|
|
|
return MakeRefCounted<ListenSocketNode>(UniquePtr<char>(gpr_strdup("test")), |
|
|
|
|
UniquePtr<char>(gpr_strdup("test"))); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(ChannelzRegistryTest, UuidStartsAboveZeroTest) { |
|
|
|
|
RefCountedPtr<BaseNode> channelz_channel = |
|
|
|
|
MakeRefCounted<BaseNode>(BaseNode::EntityType::kTopLevelChannel, nullptr); |
|
|
|
|
RefCountedPtr<BaseNode> channelz_channel = CreateTestNode(); |
|
|
|
|
intptr_t uuid = channelz_channel->uuid(); |
|
|
|
|
EXPECT_GT(uuid, 0) << "First uuid chose must be greater than zero. Zero if " |
|
|
|
|
"reserved according to " |
|
|
|
@ -65,8 +69,7 @@ TEST_F(ChannelzRegistryTest, UuidsAreIncreasing) { |
|
|
|
|
std::vector<RefCountedPtr<BaseNode>> channelz_channels; |
|
|
|
|
channelz_channels.reserve(10); |
|
|
|
|
for (int i = 0; i < 10; ++i) { |
|
|
|
|
channelz_channels.push_back(MakeRefCounted<BaseNode>( |
|
|
|
|
BaseNode::EntityType::kTopLevelChannel, nullptr)); |
|
|
|
|
channelz_channels.push_back(CreateTestNode()); |
|
|
|
|
} |
|
|
|
|
for (size_t i = 1; i < channelz_channels.size(); ++i) { |
|
|
|
|
EXPECT_LT(channelz_channels[i - 1]->uuid(), channelz_channels[i]->uuid()) |
|
|
|
@ -75,8 +78,7 @@ TEST_F(ChannelzRegistryTest, UuidsAreIncreasing) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(ChannelzRegistryTest, RegisterGetTest) { |
|
|
|
|
RefCountedPtr<BaseNode> channelz_channel = |
|
|
|
|
MakeRefCounted<BaseNode>(BaseNode::EntityType::kTopLevelChannel, nullptr); |
|
|
|
|
RefCountedPtr<BaseNode> channelz_channel = CreateTestNode(); |
|
|
|
|
RefCountedPtr<BaseNode> retrieved = |
|
|
|
|
ChannelzRegistry::Get(channelz_channel->uuid()); |
|
|
|
|
EXPECT_EQ(channelz_channel, retrieved); |
|
|
|
@ -85,8 +87,7 @@ TEST_F(ChannelzRegistryTest, RegisterGetTest) { |
|
|
|
|
TEST_F(ChannelzRegistryTest, RegisterManyItems) { |
|
|
|
|
std::vector<RefCountedPtr<BaseNode>> channelz_channels; |
|
|
|
|
for (int i = 0; i < 100; i++) { |
|
|
|
|
channelz_channels.push_back(MakeRefCounted<BaseNode>( |
|
|
|
|
BaseNode::EntityType::kTopLevelChannel, nullptr)); |
|
|
|
|
channelz_channels.push_back(CreateTestNode()); |
|
|
|
|
RefCountedPtr<BaseNode> retrieved = |
|
|
|
|
ChannelzRegistry::Get(channelz_channels[i]->uuid()); |
|
|
|
|
EXPECT_EQ(channelz_channels[i], retrieved); |
|
|
|
@ -94,8 +95,7 @@ TEST_F(ChannelzRegistryTest, RegisterManyItems) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(ChannelzRegistryTest, NullIfNotPresentTest) { |
|
|
|
|
RefCountedPtr<BaseNode> channelz_channel = |
|
|
|
|
MakeRefCounted<BaseNode>(BaseNode::EntityType::kTopLevelChannel, nullptr); |
|
|
|
|
RefCountedPtr<BaseNode> channelz_channel = CreateTestNode(); |
|
|
|
|
// try to pull out a uuid that does not exist.
|
|
|
|
|
RefCountedPtr<BaseNode> nonexistant = |
|
|
|
|
ChannelzRegistry::Get(channelz_channel->uuid() + 1); |
|
|
|
@ -117,10 +117,8 @@ TEST_F(ChannelzRegistryTest, TestUnregistration) { |
|
|
|
|
std::vector<RefCountedPtr<BaseNode>> odd_channels; |
|
|
|
|
odd_channels.reserve(kLoopIterations); |
|
|
|
|
for (int i = 0; i < kLoopIterations; i++) { |
|
|
|
|
even_channels.push_back(MakeRefCounted<BaseNode>( |
|
|
|
|
BaseNode::EntityType::kTopLevelChannel, nullptr)); |
|
|
|
|
odd_channels.push_back(MakeRefCounted<BaseNode>( |
|
|
|
|
BaseNode::EntityType::kTopLevelChannel, nullptr)); |
|
|
|
|
even_channels.push_back(CreateTestNode()); |
|
|
|
|
odd_channels.push_back(CreateTestNode()); |
|
|
|
|
odd_uuids.push_back(odd_channels[i]->uuid()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -137,8 +135,7 @@ TEST_F(ChannelzRegistryTest, TestUnregistration) { |
|
|
|
|
std::vector<RefCountedPtr<BaseNode>> more_channels; |
|
|
|
|
more_channels.reserve(kLoopIterations); |
|
|
|
|
for (int i = 0; i < kLoopIterations; i++) { |
|
|
|
|
more_channels.push_back(MakeRefCounted<BaseNode>( |
|
|
|
|
BaseNode::EntityType::kTopLevelChannel, nullptr)); |
|
|
|
|
more_channels.push_back(CreateTestNode()); |
|
|
|
|
RefCountedPtr<BaseNode> retrieved = |
|
|
|
|
ChannelzRegistry::Get(more_channels[i]->uuid()); |
|
|
|
|
EXPECT_EQ(more_channels[i], retrieved); |
|
|
|
|