aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/cpp
diff options
context:
space:
mode:
authorGravatar David Garcia Quintas <dgq@google.com>2016-11-29 17:22:48 -0800
committerGravatar David Garcia Quintas <dgq@google.com>2016-11-29 17:22:48 -0800
commitd6936b6bee465f903a5788dd2c76bbd49f8cb48b (patch)
treee0abed97a928e5ce33647593420f330db01f021c /test/cpp
parenta05909faf2394433e841a5eb4399e89afd05c26a (diff)
PR comments
Diffstat (limited to 'test/cpp')
-rw-r--r--test/cpp/qps/json_run_localhost.cc26
1 files changed, 13 insertions, 13 deletions
diff --git a/test/cpp/qps/json_run_localhost.cc b/test/cpp/qps/json_run_localhost.cc
index 70c50cdc71..59a5a89ca3 100644
--- a/test/cpp/qps/json_run_localhost.cc
+++ b/test/cpp/qps/json_run_localhost.cc
@@ -47,8 +47,9 @@
using grpc::SubProcess;
typedef std::unique_ptr<SubProcess> SubProcessPtr;
-std::vector<SubProcessPtr> g_workers;
SubProcessPtr g_driver;
+constexpr auto kNumWorkers = 2;
+std::vector<SubProcessPtr> g_workers(2);
template <class T>
std::string as_string(const T& val) {
@@ -58,10 +59,11 @@ std::string as_string(const T& val) {
}
static void sighandler(int sig) {
+ const int errno_saved = errno;
g_driver->Interrupt();
- for (auto it = g_workers.begin(); it != g_workers.end(); ++it) {
- (*it)->Interrupt();
- }
+ for (const auto& worker : g_workers)
+ if (worker) worker->Interrupt();
+ errno = errno_saved;
}
static void register_sighandler() {
@@ -82,11 +84,11 @@ int main(int argc, char** argv) {
std::ostringstream env;
bool first = true;
- for (int i = 0; i < 2; i++) {
- auto port = grpc_pick_unused_port_or_die();
+ for (int i = 0; i < kNumWorkers; i++) {
+ const auto port = grpc_pick_unused_port_or_die();
std::vector<std::string> args = {bin_dir + "/qps_worker", "-driver_port",
as_string(port)};
- g_workers.emplace_back(new SubProcess(args));
+ g_workers[i].reset(new SubProcess(args));
if (!first) env << ",";
env << "localhost:" << port;
first = false;
@@ -100,11 +102,9 @@ int main(int argc, char** argv) {
g_driver.reset(new SubProcess(args));
const int driver_join_status = g_driver->Join();
- for (auto it = g_workers.begin(); it != g_workers.end(); ++it) {
- (*it)->Interrupt();
- }
- for (auto it = g_workers.begin(); it != g_workers.end(); ++it) {
- (*it)->Join();
- }
+ for (const auto& worker : g_workers)
+ if (worker) worker->Interrupt();
+ for (const auto& worker : g_workers)
+ if (worker) worker->Join();
GPR_ASSERT(driver_join_status == 0);
}