diff --git a/test/cpp/qps/json_run_localhost.cc b/test/cpp/qps/json_run_localhost.cc index e7383a245ba..eaa6e4a1b5f 100644 --- a/test/cpp/qps/json_run_localhost.cc +++ b/test/cpp/qps/json_run_localhost.cc @@ -88,12 +88,16 @@ int main(int argc, char** argv) { bool first = true; for (int i = 0; i < kNumWorkers; i++) { - const auto port = grpc_pick_unused_port_or_die(); + const auto driver_port = grpc_pick_unused_port_or_die(); + // ServerPort can be used or not later depending on the type of worker + // but we like to issue all ports required here to avoid port conflict. + const auto server_port = grpc_pick_unused_port_or_die(); std::vector args = {bin_dir + "/qps_worker", "-driver_port", - as_string(port)}; + as_string(driver_port), "-server_port", + as_string(server_port)}; g_workers[i] = new SubProcess(args); if (!first) env << ","; - env << "localhost:" << port; + env << "localhost:" << driver_port; first = false; } diff --git a/test/cpp/qps/qps_worker.cc b/test/cpp/qps/qps_worker.cc index fd207765ca5..c364216bc02 100644 --- a/test/cpp/qps/qps_worker.cc +++ b/test/cpp/qps/qps_worker.cc @@ -280,6 +280,7 @@ QpsWorker::QpsWorker(int driver_port, int server_port, gpr_atm_rel_store(&done_, static_cast(0)); std::unique_ptr builder = CreateQpsServerBuilder(); + builder->AddChannelArgument(GRPC_ARG_ALLOW_REUSEPORT, 0); if (driver_port >= 0) { std::string server_address = grpc_core::JoinHostPort("::", driver_port); builder->AddListeningPort( diff --git a/test/cpp/qps/server_async.cc b/test/cpp/qps/server_async.cc index 6a07accb151..51d410b1cbf 100644 --- a/test/cpp/qps/server_async.cc +++ b/test/cpp/qps/server_async.cc @@ -82,7 +82,8 @@ class AsyncQpsServerTest final : public grpc::testing::Server { if (port_num >= 0) { std::string server_address = grpc_core::JoinHostPort("::", port_num); builder->AddListeningPort(server_address.c_str(), - Server::CreateServerCredentials(config)); + Server::CreateServerCredentials(config), + &port_num); } register_service(builder.get(), &async_service_); @@ -105,6 +106,11 @@ class AsyncQpsServerTest final : public grpc::testing::Server { ApplyConfigToBuilder(config, builder.get()); server_ = builder->BuildAndStart(); + if (server_ == nullptr) { + gpr_log(GPR_ERROR, "Server: Fail to BuildAndStart(port=%d)", port_num); + } else { + gpr_log(GPR_INFO, "Server: BuildAndStart(port=%d)", port_num); + } auto process_rpc_bound = std::bind(process_rpc, config.payload_config(), std::placeholders::_1, diff --git a/test/cpp/qps/server_callback.cc b/test/cpp/qps/server_callback.cc index e4aa10946d2..a0a95312229 100644 --- a/test/cpp/qps/server_callback.cc +++ b/test/cpp/qps/server_callback.cc @@ -104,7 +104,8 @@ class CallbackServer final : public grpc::testing::Server { if (port_num >= 0) { std::string server_address = grpc_core::JoinHostPort("::", port_num); builder->AddListeningPort(server_address.c_str(), - Server::CreateServerCredentials(config)); + Server::CreateServerCredentials(config), + &port_num); } ApplyConfigToBuilder(config, builder.get()); @@ -112,6 +113,11 @@ class CallbackServer final : public grpc::testing::Server { builder->RegisterService(&service_); impl_ = builder->BuildAndStart(); + if (impl_ == nullptr) { + gpr_log(GPR_ERROR, "Server: Fail to BuildAndStart(port=%d)", port_num); + } else { + gpr_log(GPR_INFO, "Server: BuildAndStart(port=%d)", port_num); + } } std::shared_ptr InProcessChannel( diff --git a/test/cpp/qps/server_sync.cc b/test/cpp/qps/server_sync.cc index 19d406a167c..13b3c248ac2 100644 --- a/test/cpp/qps/server_sync.cc +++ b/test/cpp/qps/server_sync.cc @@ -162,7 +162,8 @@ class SynchronousServer final : public grpc::testing::Server { if (port_num >= 0) { std::string server_address = grpc_core::JoinHostPort("::", port_num); builder->AddListeningPort(server_address.c_str(), - Server::CreateServerCredentials(config)); + Server::CreateServerCredentials(config), + &port_num); } ApplyConfigToBuilder(config, builder.get()); @@ -170,6 +171,11 @@ class SynchronousServer final : public grpc::testing::Server { builder->RegisterService(&service_); impl_ = builder->BuildAndStart(); + if (impl_ == nullptr) { + gpr_log(GPR_ERROR, "Server: Fail to BuildAndStart(port=%d)", port_num); + } else { + gpr_log(GPR_INFO, "Server: BuildAndStart(port=%d)", port_num); + } } std::shared_ptr InProcessChannel(