Fix portability problems.

pull/8523/head
Mark D. Roth 9 years ago
parent fd635add1c
commit 6df607591c
  1. 28
      test/cpp/end2end/round_robin_end2end_test.cc

@ -63,6 +63,8 @@ namespace {
// every call to the Echo RPC. // every call to the Echo RPC.
class MyTestServiceImpl : public TestServiceImpl { class MyTestServiceImpl : public TestServiceImpl {
public: public:
MyTestServiceImpl() : request_count_(0) {}
Status Echo(ServerContext* context, const EchoRequest* request, Status Echo(ServerContext* context, const EchoRequest* request,
EchoResponse* response) GRPC_OVERRIDE { EchoResponse* response) GRPC_OVERRIDE {
{ {
@ -79,7 +81,7 @@ class MyTestServiceImpl : public TestServiceImpl {
private: private:
mutex mu_; mutex mu_;
int request_count_ = 0; int request_count_;
}; };
class RoundRobinEnd2endTest : public ::testing::Test { class RoundRobinEnd2endTest : public ::testing::Test {
@ -93,8 +95,8 @@ class RoundRobinEnd2endTest : public ::testing::Test {
} }
void TearDown() GRPC_OVERRIDE { void TearDown() GRPC_OVERRIDE {
for (const auto& server : servers_) { for (size_t i = 0; i < servers_.size(); ++i) {
server->Shutdown(); servers_[i]->Shutdown();
} }
} }
@ -135,17 +137,15 @@ class RoundRobinEnd2endTest : public ::testing::Test {
gpr_log(GPR_INFO, "starting server on port %d", port_); gpr_log(GPR_INFO, "starting server on port %d", port_);
std::mutex mu; std::mutex mu;
std::condition_variable cond; std::condition_variable cond;
thread_ = new std::thread([this, server_host, &mu, &cond]() { thread_ = new std::thread(
Start(server_host); std::bind(&ServerData::Start, this, server_host, &mu, &cond));
lock_guard<mutex> lock(mu);
cond.notify_one();
});
unique_lock<mutex> lock(mu); unique_lock<mutex> lock(mu);
cond.wait(lock); cond.wait(lock);
gpr_log(GPR_INFO, "server startup complete"); gpr_log(GPR_INFO, "server startup complete");
} }
void Start(const grpc::string& server_host) { void Start(const grpc::string& server_host, std::mutex* mu,
std::condition_variable* cond) {
std::ostringstream server_address; std::ostringstream server_address;
server_address << server_host << ":" << port_; server_address << server_host << ":" << port_;
ServerBuilder builder; ServerBuilder builder;
@ -153,6 +153,8 @@ class RoundRobinEnd2endTest : public ::testing::Test {
InsecureServerCredentials()); InsecureServerCredentials());
builder.RegisterService(&service_); builder.RegisterService(&service_);
server_ = builder.BuildAndStart(); server_ = builder.BuildAndStart();
lock_guard<mutex> lock(*mu);
cond->notify_one();
} }
void Shutdown() { void Shutdown() {
@ -175,8 +177,8 @@ TEST_F(RoundRobinEnd2endTest, PickFirst) {
SendRpc(kNumServers); SendRpc(kNumServers);
// All requests should have gone to a single server. // All requests should have gone to a single server.
bool found = false; bool found = false;
for (const auto& server : servers_) { for (size_t i = 0; i < servers_.size(); ++i) {
const int request_count = server->service_.request_count(); const int request_count = servers_[i]->service_.request_count();
if (request_count == kNumServers) { if (request_count == kNumServers) {
found = true; found = true;
} else { } else {
@ -193,8 +195,8 @@ TEST_F(RoundRobinEnd2endTest, RoundRobin) {
ResetStub(true /* round_robin */); ResetStub(true /* round_robin */);
SendRpc(kNumServers); SendRpc(kNumServers);
// One request should have gone to each server. // One request should have gone to each server.
for (const auto& server : servers_) { for (size_t i = 0; i < servers_.size(); ++i) {
EXPECT_EQ(1, server->service_.request_count()); EXPECT_EQ(1, servers_[i]->service_.request_count());
} }
} }

Loading…
Cancel
Save