From 315b1cac2d084b032497387253d527946800eb88 Mon Sep 17 00:00:00 2001 From: Roman Dzhabarov Date: Sun, 13 Nov 2016 11:19:16 -0800 Subject: [PATCH 1/2] Reduce test execution from 900ms to 9ms. --- test/common/upstream/load_balancer_impl_test.cc | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/test/common/upstream/load_balancer_impl_test.cc b/test/common/upstream/load_balancer_impl_test.cc index 369a11980e876..85dcbe6b66941 100644 --- a/test/common/upstream/load_balancer_impl_test.cc +++ b/test/common/upstream/load_balancer_impl_test.cc @@ -261,16 +261,19 @@ TEST_F(RoundRobinLoadBalancerTest, LowPrecisionForDistribution) { // The following host distribution with current precision should lead to the no_capacity_left // situation. + // Reuse the same host in all of the structures below to reduce time test takes and this does not + // impact load balancing logic. + HostPtr host = newTestHost(Upstream::MockCluster{}, "tcp://127.0.0.1:80"); std::vector current(45000); for (int i = 0; i < 45000; ++i) { - current[i] = newTestHost(cluster_, "tcp://127.0.0.1:0"); + current[i] = host; } local_hosts_per_zone->push_back(current); current.resize(55000); for (int i = 0; i < 55000; ++i) { - current[i] = newTestHost(cluster_, "tcp://127.0.0.1:0"); + current[i] = host; } local_hosts_per_zone->push_back(current); local_cluster_hosts_->updateHosts(local_hosts, local_hosts, local_hosts_per_zone, @@ -278,19 +281,19 @@ TEST_F(RoundRobinLoadBalancerTest, LowPrecisionForDistribution) { current.resize(44999); for (int i = 0; i < 44999; ++i) { - current[i] = newTestHost(cluster_, "tcp://127.0.0.1:0"); + current[i] = host; } upstream_hosts_per_zone->push_back(current); current.resize(55001); for (int i = 0; i < 55001; ++i) { - current[i] = newTestHost(cluster_, "tcp://127.0.0.1:0"); + current[i] = host; } upstream_hosts_per_zone->push_back(current); cluster_.healthy_hosts_per_zone_ = *upstream_hosts_per_zone; - // Force request out of small zone. + // Force request out of small zone and to randomly select zone. EXPECT_CALL(random_, random()).WillOnce(Return(9999)).WillOnce(Return(2)); lb_->chooseHost(); EXPECT_EQ(1U, stats_.lb_zone_no_capacity_left_.value()); From 9d14ad659951934484016a9326b34355c6519ad8 Mon Sep 17 00:00:00 2001 From: Roman Dzhabarov Date: Sun, 13 Nov 2016 11:45:25 -0800 Subject: [PATCH 2/2] using cluster_ --- test/common/upstream/load_balancer_impl_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/common/upstream/load_balancer_impl_test.cc b/test/common/upstream/load_balancer_impl_test.cc index 85dcbe6b66941..ee3a2b753c3a2 100644 --- a/test/common/upstream/load_balancer_impl_test.cc +++ b/test/common/upstream/load_balancer_impl_test.cc @@ -263,7 +263,7 @@ TEST_F(RoundRobinLoadBalancerTest, LowPrecisionForDistribution) { // situation. // Reuse the same host in all of the structures below to reduce time test takes and this does not // impact load balancing logic. - HostPtr host = newTestHost(Upstream::MockCluster{}, "tcp://127.0.0.1:80"); + HostPtr host = newTestHost(cluster_, "tcp://127.0.0.1:80"); std::vector current(45000); for (int i = 0; i < 45000; ++i) {