Merge pull request #19984 from veblush/virtual-enforce

Enforce abstract class rule
pull/20025/head
Esun Kim 5 years ago committed by GitHub
commit 1e64ed1c7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 31
      test/core/channel/channelz_registry_test.cc
  2. 18
      test/core/client_channel/resolvers/dns_resolver_test.cc
  3. 5
      test/core/util/test_lb_policies.cc

@ -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);

@ -24,11 +24,23 @@
#include "src/core/ext/filters/client_channel/resolver/dns/dns_resolver_selection.h"
#include "src/core/ext/filters/client_channel/resolver_registry.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/iomgr/combiner.h"
#include "test/core/util/test_config.h"
static grpc_combiner* g_combiner;
class TestResultHandler : public grpc_core::Resolver::ResultHandler {
void ReturnResult(grpc_core::Resolver::Result result) override {}
void ReturnError(grpc_error* error) override {}
};
static grpc_core::UniquePtr<grpc_core::Resolver::ResultHandler>
create_test_result_handler() {
return grpc_core::UniquePtr<grpc_core::Resolver::ResultHandler>(
grpc_core::New<TestResultHandler>());
}
static void test_succeeds(grpc_core::ResolverFactory* factory,
const char* string) {
gpr_log(GPR_DEBUG, "test: '%s' should be valid for '%s'", string,
@ -39,8 +51,7 @@ static void test_succeeds(grpc_core::ResolverFactory* factory,
grpc_core::ResolverArgs args;
args.uri = uri;
args.combiner = g_combiner;
args.result_handler =
grpc_core::MakeUnique<grpc_core::Resolver::ResultHandler>();
args.result_handler = create_test_result_handler();
grpc_core::OrphanablePtr<grpc_core::Resolver> resolver =
factory->CreateResolver(std::move(args));
GPR_ASSERT(resolver != nullptr);
@ -57,8 +68,7 @@ static void test_fails(grpc_core::ResolverFactory* factory,
grpc_core::ResolverArgs args;
args.uri = uri;
args.combiner = g_combiner;
args.result_handler =
grpc_core::MakeUnique<grpc_core::Resolver::ResultHandler>();
args.result_handler = create_test_result_handler();
grpc_core::OrphanablePtr<grpc_core::Resolver> resolver =
factory->CreateResolver(std::move(args));
GPR_ASSERT(resolver == nullptr);

@ -233,6 +233,11 @@ class InterceptTrailingFactory : public LoadBalancingPolicyFactory {
return kInterceptRecvTrailingMetadataLbPolicyName;
}
RefCountedPtr<LoadBalancingPolicy::Config> ParseLoadBalancingConfig(
const grpc_json* json, grpc_error** error) const override {
return nullptr;
}
private:
InterceptRecvTrailingMetadataCallback cb_;
void* user_data_;

Loading…
Cancel
Save