aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/cpp
diff options
context:
space:
mode:
authorGravatar Mark D. Roth <roth@google.com>2017-05-19 15:19:14 -0700
committerGravatar Mark D. Roth <roth@google.com>2017-05-19 15:19:14 -0700
commitf91eb714c29f4599fda5709278b57a9c5a18e3aa (patch)
tree77f34bbb1813755b1ba0709df494e0825c128a12 /test/cpp
parentaf3cc761adfd06b7620b77d70e87640b7a341ba1 (diff)
Change round_robin LB policy to use the addresses in the order given.
Diffstat (limited to 'test/cpp')
-rw-r--r--test/cpp/end2end/grpclb_end2end_test.cc6
-rw-r--r--test/cpp/end2end/round_robin_end2end_test.cc31
2 files changed, 12 insertions, 25 deletions
diff --git a/test/cpp/end2end/grpclb_end2end_test.cc b/test/cpp/end2end/grpclb_end2end_test.cc
index 4e1bcc7a60..b0d4e2dadf 100644
--- a/test/cpp/end2end/grpclb_end2end_test.cc
+++ b/test/cpp/end2end/grpclb_end2end_test.cc
@@ -568,9 +568,11 @@ TEST_F(SingleBalancerTest, RepeatedServerlist) {
// only the first half of the backends will receive them.
for (size_t i = 0; i < backends_.size(); ++i) {
if (i < backends_.size() / 2)
- EXPECT_EQ(1U, backend_servers_[i].service_->request_count());
+ EXPECT_EQ(1U, backend_servers_[i].service_->request_count())
+ << "for backend #" << i;
else
- EXPECT_EQ(0U, backend_servers_[i].service_->request_count());
+ EXPECT_EQ(0U, backend_servers_[i].service_->request_count())
+ << "for backend #" << i;
}
EXPECT_EQ(statuses_and_responses.size(), num_backends_ / 2);
for (const auto& status_and_response : statuses_and_responses) {
diff --git a/test/cpp/end2end/round_robin_end2end_test.cc b/test/cpp/end2end/round_robin_end2end_test.cc
index f8e3cc06c0..ea7639bc8f 100644
--- a/test/cpp/end2end/round_robin_end2end_test.cc
+++ b/test/cpp/end2end/round_robin_end2end_test.cc
@@ -42,7 +42,6 @@
#include <grpc++/server_builder.h>
#include <grpc/grpc.h>
#include <grpc/support/log.h>
-#include <grpc/support/thd.h>
#include <grpc/support/time.h>
#include "src/proto/grpc/testing/echo.grpc.pb.h"
@@ -131,22 +130,10 @@ class RoundRobinEnd2endTest : public ::testing::Test {
int port_;
std::unique_ptr<Server> server_;
MyTestServiceImpl service_;
- std::unique_ptr<std::thread> thread_;
explicit ServerData(const grpc::string& server_host) {
port_ = grpc_pick_unused_port_or_die();
gpr_log(GPR_INFO, "starting server on port %d", port_);
- std::mutex mu;
- std::condition_variable cond;
- thread_.reset(new std::thread(
- std::bind(&ServerData::Start, this, server_host, &mu, &cond)));
- std::unique_lock<std::mutex> lock(mu);
- cond.wait(lock);
- gpr_log(GPR_INFO, "server startup complete");
- }
-
- void Start(const grpc::string& server_host, std::mutex* mu,
- std::condition_variable* cond) {
std::ostringstream server_address;
server_address << server_host << ":" << port_;
ServerBuilder builder;
@@ -154,18 +141,13 @@ class RoundRobinEnd2endTest : public ::testing::Test {
InsecureServerCredentials());
builder.RegisterService(&service_);
server_ = builder.BuildAndStart();
- std::lock_guard<std::mutex> lock(*mu);
- cond->notify_one();
+ gpr_log(GPR_INFO, "server startup complete");
}
- void Shutdown() {
- server_->Shutdown();
- thread_->join();
- }
+ void Shutdown() { server_->Shutdown(); }
};
const grpc::string server_host_;
- CompletionQueue cli_cq_;
std::shared_ptr<Channel> channel_;
std::unique_ptr<grpc::testing::EchoTestService::Stub> stub_;
std::vector<std::unique_ptr<ServerData>> servers_;
@@ -197,10 +179,13 @@ TEST_F(RoundRobinEnd2endTest, RoundRobin) {
const int kNumServers = 3;
StartServers(kNumServers);
ResetStub(true /* round_robin */);
- SendRpc(kNumServers);
- // One request should have gone to each server.
+ // Send one RPC per backend and make sure they are used in order.
+ // Note: This relies on the fact that the subchannels are reported in
+ // state READY in the order in which the addresses are specified,
+ // which is only true because the backends are all local.
for (size_t i = 0; i < servers_.size(); ++i) {
- EXPECT_EQ(1, servers_[i]->service_.request_count());
+ SendRpc(1);
+ EXPECT_EQ(1, servers_[i]->service_.request_count()) << "for backend #" << i;
}
// Check LB policy name for the channel.
EXPECT_EQ("round_robin", channel_->GetLoadBalancingPolicyName());