Remove force_creation param from subchannel index

pull/17720/head
Juanli Shen 6 years ago
parent 6173fe1fcb
commit b3c0b91db1
  1. 8
      src/core/ext/filters/client_channel/subchannel_index.cc
  2. 9
      src/core/ext/filters/client_channel/subchannel_index.h
  3. 26
      test/cpp/end2end/client_lb_end2end_test.cc

@ -42,8 +42,6 @@ struct grpc_subchannel_key {
grpc_channel_args* args; grpc_channel_args* args;
}; };
static bool g_force_creation = false;
static grpc_subchannel_key* create_key( static grpc_subchannel_key* create_key(
const grpc_channel_args* args, const grpc_channel_args* args,
grpc_channel_args* (*copy_channel_args)(const grpc_channel_args* args)) { grpc_channel_args* (*copy_channel_args)(const grpc_channel_args* args)) {
@ -63,8 +61,6 @@ static grpc_subchannel_key* subchannel_key_copy(grpc_subchannel_key* k) {
int grpc_subchannel_key_compare(const grpc_subchannel_key* a, int grpc_subchannel_key_compare(const grpc_subchannel_key* a,
const grpc_subchannel_key* b) { const grpc_subchannel_key* b) {
// To pretend the keys are different, return a non-zero value.
if (GPR_UNLIKELY(g_force_creation)) return 1;
return grpc_channel_args_compare(a->args, b->args); return grpc_channel_args_compare(a->args, b->args);
} }
@ -224,7 +220,3 @@ void grpc_subchannel_index_unregister(grpc_subchannel_key* key,
grpc_avl_unref(index, nullptr); grpc_avl_unref(index, nullptr);
} }
} }
void grpc_subchannel_index_test_only_set_force_creation(bool force_creation) {
g_force_creation = force_creation;
}

@ -63,13 +63,4 @@ void grpc_subchannel_index_ref(void);
to zero, unref the subchannel index and destroy its mutex. */ to zero, unref the subchannel index and destroy its mutex. */
void grpc_subchannel_index_unref(void); void grpc_subchannel_index_unref(void);
/** \em TEST ONLY.
* If \a force_creation is true, all keys are regarded different, resulting in
* new subchannels always being created. Otherwise, the keys will be compared as
* usual.
*
* Tests using this function \em MUST run tests with and without \a
* force_creation set. */
void grpc_subchannel_index_test_only_set_force_creation(bool force_creation);
#endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_SUBCHANNEL_INDEX_H */ #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_SUBCHANNEL_INDEX_H */

@ -38,7 +38,6 @@
#include "src/core/ext/filters/client_channel/parse_address.h" #include "src/core/ext/filters/client_channel/parse_address.h"
#include "src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h" #include "src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h"
#include "src/core/ext/filters/client_channel/server_address.h" #include "src/core/ext/filters/client_channel/server_address.h"
#include "src/core/ext/filters/client_channel/subchannel_index.h"
#include "src/core/lib/backoff/backoff.h" #include "src/core/lib/backoff/backoff.h"
#include "src/core/lib/gpr/env.h" #include "src/core/lib/gpr/env.h"
#include "src/core/lib/gprpp/debug_location.h" #include "src/core/lib/gprpp/debug_location.h"
@ -662,30 +661,14 @@ TEST_F(ClientLbEnd2endTest, PickFirstUpdateSuperset) {
EXPECT_EQ("pick_first", channel->GetLoadBalancingPolicyName()); EXPECT_EQ("pick_first", channel->GetLoadBalancingPolicyName());
} }
class ClientLbEnd2endWithParamTest TEST_F(ClientLbEnd2endTest, PickFirstManyUpdates) {
: public ClientLbEnd2endTest, const int kNumUpdates = 1000;
public ::testing::WithParamInterface<bool> {
protected:
void SetUp() override {
grpc_subchannel_index_test_only_set_force_creation(GetParam());
ClientLbEnd2endTest::SetUp();
}
void TearDown() override {
ClientLbEnd2endTest::TearDown();
grpc_subchannel_index_test_only_set_force_creation(false);
}
};
TEST_P(ClientLbEnd2endWithParamTest, PickFirstManyUpdates) {
gpr_log(GPR_INFO, "subchannel force creation: %d", GetParam());
// Start servers and send one RPC per server.
const int kNumServers = 3; const int kNumServers = 3;
StartServers(kNumServers); StartServers(kNumServers);
auto channel = BuildChannel("pick_first"); auto channel = BuildChannel("pick_first");
auto stub = BuildStub(channel); auto stub = BuildStub(channel);
std::vector<int> ports = GetServersPorts(); std::vector<int> ports = GetServersPorts();
for (size_t i = 0; i < 1000; ++i) { for (size_t i = 0; i < kNumUpdates; ++i) {
std::shuffle(ports.begin(), ports.end(), std::shuffle(ports.begin(), ports.end(),
std::mt19937(std::random_device()())); std::mt19937(std::random_device()()));
SetNextResolution(ports); SetNextResolution(ports);
@ -697,9 +680,6 @@ TEST_P(ClientLbEnd2endWithParamTest, PickFirstManyUpdates) {
EXPECT_EQ("pick_first", channel->GetLoadBalancingPolicyName()); EXPECT_EQ("pick_first", channel->GetLoadBalancingPolicyName());
} }
INSTANTIATE_TEST_CASE_P(SubchannelForceCreation, ClientLbEnd2endWithParamTest,
::testing::Bool());
TEST_F(ClientLbEnd2endTest, PickFirstReresolutionNoSelected) { TEST_F(ClientLbEnd2endTest, PickFirstReresolutionNoSelected) {
// Prepare the ports for up servers and down servers. // Prepare the ports for up servers and down servers.
const int kNumServers = 3; const int kNumServers = 3;

Loading…
Cancel
Save