aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/cpp/end2end
diff options
context:
space:
mode:
authorGravatar Mark D. Roth <roth@google.com>2016-10-31 14:39:45 -0700
committerGravatar Mark D. Roth <roth@google.com>2016-10-31 14:39:45 -0700
commit6df607591ce42eee46538726432960e03f6db85d (patch)
treeb74339f6fcd879e598bcd84c9fed3f0424882610 /test/cpp/end2end
parentfd635add1c96344398fafb33fb2ba86a22055a5d (diff)
Fix portability problems.
Diffstat (limited to 'test/cpp/end2end')
-rw-r--r--test/cpp/end2end/round_robin_end2end_test.cc28
1 files changed, 15 insertions, 13 deletions
diff --git a/test/cpp/end2end/round_robin_end2end_test.cc b/test/cpp/end2end/round_robin_end2end_test.cc
index 6ee7417db8..f4ca3baa54 100644
--- a/test/cpp/end2end/round_robin_end2end_test.cc
+++ b/test/cpp/end2end/round_robin_end2end_test.cc
@@ -63,6 +63,8 @@ namespace {
// every call to the Echo RPC.
class MyTestServiceImpl : public TestServiceImpl {
public:
+ MyTestServiceImpl() : request_count_(0) {}
+
Status Echo(ServerContext* context, const EchoRequest* request,
EchoResponse* response) GRPC_OVERRIDE {
{
@@ -79,7 +81,7 @@ class MyTestServiceImpl : public TestServiceImpl {
private:
mutex mu_;
- int request_count_ = 0;
+ int request_count_;
};
class RoundRobinEnd2endTest : public ::testing::Test {
@@ -93,8 +95,8 @@ class RoundRobinEnd2endTest : public ::testing::Test {
}
void TearDown() GRPC_OVERRIDE {
- for (const auto& server : servers_) {
- server->Shutdown();
+ for (size_t i = 0; i < servers_.size(); ++i) {
+ servers_[i]->Shutdown();
}
}
@@ -135,17 +137,15 @@ class RoundRobinEnd2endTest : public ::testing::Test {
gpr_log(GPR_INFO, "starting server on port %d", port_);
std::mutex mu;
std::condition_variable cond;
- thread_ = new std::thread([this, server_host, &mu, &cond]() {
- Start(server_host);
- lock_guard<mutex> lock(mu);
- cond.notify_one();
- });
+ thread_ = new std::thread(
+ std::bind(&ServerData::Start, this, server_host, &mu, &cond));
unique_lock<mutex> lock(mu);
cond.wait(lock);
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;
server_address << server_host << ":" << port_;
ServerBuilder builder;
@@ -153,6 +153,8 @@ class RoundRobinEnd2endTest : public ::testing::Test {
InsecureServerCredentials());
builder.RegisterService(&service_);
server_ = builder.BuildAndStart();
+ lock_guard<mutex> lock(*mu);
+ cond->notify_one();
}
void Shutdown() {
@@ -175,8 +177,8 @@ TEST_F(RoundRobinEnd2endTest, PickFirst) {
SendRpc(kNumServers);
// All requests should have gone to a single server.
bool found = false;
- for (const auto& server : servers_) {
- const int request_count = server->service_.request_count();
+ for (size_t i = 0; i < servers_.size(); ++i) {
+ const int request_count = servers_[i]->service_.request_count();
if (request_count == kNumServers) {
found = true;
} else {
@@ -193,8 +195,8 @@ TEST_F(RoundRobinEnd2endTest, RoundRobin) {
ResetStub(true /* round_robin */);
SendRpc(kNumServers);
// One request should have gone to each server.
- for (const auto& server : servers_) {
- EXPECT_EQ(1, server->service_.request_count());
+ for (size_t i = 0; i < servers_.size(); ++i) {
+ EXPECT_EQ(1, servers_[i]->service_.request_count());
}
}