From 572dd8e8970ec660fb281dfde0cf22c0ee20f31c Mon Sep 17 00:00:00 2001 From: Dan Wittmer Date: Mon, 6 Nov 2017 10:50:26 -0800 Subject: Change adds a version of grpc::testing::interop::RunServer that allows clients to pass in optional condition_variable which will be notified when the server has started and port to use, avoiding the need for callers to work with command line options. Above is used to support clients running the server in a separate thread in the same process as the tests are run to support local only tests. Existing grpc::testing::interop::RunServer calls into new version passing in FLAGS_port and null condition variable. --- test/cpp/interop/interop_server.cc | 15 +++++++++++++-- test/cpp/interop/server_helper.h | 15 +++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) (limited to 'test/cpp/interop') diff --git a/test/cpp/interop/interop_server.cc b/test/cpp/interop/interop_server.cc index 4149724b1e..bcef9c38b7 100644 --- a/test/cpp/interop/interop_server.cc +++ b/test/cpp/interop/interop_server.cc @@ -317,9 +317,16 @@ class TestServiceImpl : public TestService::Service { void grpc::testing::interop::RunServer( std::shared_ptr creds) { - GPR_ASSERT(FLAGS_port != 0); + RunServer(creds, FLAGS_port, nullptr); +} + +void grpc::testing::interop::RunServer( + std::shared_ptr creds, + const int port, + std::condition_variable *server_started_condition) { + GPR_ASSERT(port != 0); std::ostringstream server_address; - server_address << "0.0.0.0:" << FLAGS_port; + server_address << "0.0.0.0:" << port; TestServiceImpl service; SimpleRequest request; @@ -333,6 +340,10 @@ void grpc::testing::interop::RunServer( } std::unique_ptr server(builder.BuildAndStart()); gpr_log(GPR_INFO, "Server listening on %s", server_address.str().c_str()); + + // Signal that the server has started. + if (server_started_condition) server_started_condition->notify_all(); + while (!gpr_atm_no_barrier_load(&g_got_sigint)) { gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(5, GPR_TIMESPAN))); diff --git a/test/cpp/interop/server_helper.h b/test/cpp/interop/server_helper.h index 6af003fe93..8e7a6dddf7 100644 --- a/test/cpp/interop/server_helper.h +++ b/test/cpp/interop/server_helper.h @@ -19,6 +19,7 @@ #ifndef GRPC_TEST_CPP_INTEROP_SERVER_HELPER_H #define GRPC_TEST_CPP_INTEROP_SERVER_HELPER_H +#include #include #include @@ -50,8 +51,22 @@ class InteropServerContextInspector { namespace interop { extern gpr_atm g_got_sigint; + +/// Run gRPC interop server using port FLAGS_port. +/// +/// \param creds The credentials associated with the server. void RunServer(std::shared_ptr creds); +/// Run gRPC interop server. +/// +/// \param creds The credentials associated with the server. +/// \param port Port to use for the server. +/// \param server_started_condition (optional) Condition variable to used to +/// notify when the server has started. +void RunServer(std::shared_ptr creds, + int port, + std::condition_variable *server_started_condition); + } // namespace interop } // namespace testing } // namespace grpc -- cgit v1.2.3 From 728f1d2c44b112800d3d420a30033d1e3e291b92 Mon Sep 17 00:00:00 2001 From: Dan Wittmer Date: Thu, 16 Nov 2017 14:37:49 -0800 Subject: s//used --- test/cpp/interop/server_helper.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/cpp/interop') diff --git a/test/cpp/interop/server_helper.h b/test/cpp/interop/server_helper.h index 8e7a6dddf7..bdbea8f653 100644 --- a/test/cpp/interop/server_helper.h +++ b/test/cpp/interop/server_helper.h @@ -61,8 +61,8 @@ void RunServer(std::shared_ptr creds); /// /// \param creds The credentials associated with the server. /// \param port Port to use for the server. -/// \param server_started_condition (optional) Condition variable to used to -/// notify when the server has started. +/// \param server_started_condition (optional) Condition variable used to notify +/// when the server has started. void RunServer(std::shared_ptr creds, int port, std::condition_variable *server_started_condition); -- cgit v1.2.3 From 6d18fcd3ab5815af5044d416f20f7b684d950e17 Mon Sep 17 00:00:00 2001 From: Dan Wittmer Date: Thu, 16 Nov 2017 16:45:23 -0800 Subject: Add ServerStartedCondition to hold the mutex, condition variable and condition. Changes allow callers to correctly handle spurious wakeups. --- test/cpp/interop/interop_server.cc | 8 ++++++-- test/cpp/interop/server_helper.h | 12 +++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) (limited to 'test/cpp/interop') diff --git a/test/cpp/interop/interop_server.cc b/test/cpp/interop/interop_server.cc index bcef9c38b7..5b9e229804 100644 --- a/test/cpp/interop/interop_server.cc +++ b/test/cpp/interop/interop_server.cc @@ -323,7 +323,7 @@ void grpc::testing::interop::RunServer( void grpc::testing::interop::RunServer( std::shared_ptr creds, const int port, - std::condition_variable *server_started_condition) { + ServerStartedCondition *server_started_condition) { GPR_ASSERT(port != 0); std::ostringstream server_address; server_address << "0.0.0.0:" << port; @@ -342,7 +342,11 @@ void grpc::testing::interop::RunServer( gpr_log(GPR_INFO, "Server listening on %s", server_address.str().c_str()); // Signal that the server has started. - if (server_started_condition) server_started_condition->notify_all(); + if (server_started_condition) { + std::unique_lock lock(server_started_condition->mutex); + server_started_condition->server_started = true; + server_started_condition->condition.notify_all(); + } while (!gpr_atm_no_barrier_load(&g_got_sigint)) { gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), diff --git a/test/cpp/interop/server_helper.h b/test/cpp/interop/server_helper.h index bdbea8f653..ab5de07c0e 100644 --- a/test/cpp/interop/server_helper.h +++ b/test/cpp/interop/server_helper.h @@ -52,6 +52,12 @@ namespace interop { extern gpr_atm g_got_sigint; +struct ServerStartedCondition { + std::mutex mutex; + std::condition_variable condition; + bool server_started = false; +}; + /// Run gRPC interop server using port FLAGS_port. /// /// \param creds The credentials associated with the server. @@ -61,11 +67,11 @@ void RunServer(std::shared_ptr creds); /// /// \param creds The credentials associated with the server. /// \param port Port to use for the server. -/// \param server_started_condition (optional) Condition variable used to notify -/// when the server has started. +/// \param server_started_condition (optional) Struct holding mutex, condition +/// variable, and condition used to notify when the server has started. void RunServer(std::shared_ptr creds, int port, - std::condition_variable *server_started_condition); + ServerStartedCondition *server_started_condition); } // namespace interop } // namespace testing -- cgit v1.2.3 From b88ab92af28bea0badf96b320538011abaffa2c6 Mon Sep 17 00:00:00 2001 From: Dan Wittmer Date: Fri, 17 Nov 2017 15:23:32 -0800 Subject: Fix formatting of RunServer params. --- test/cpp/interop/interop_server.cc | 3 +-- test/cpp/interop/server_helper.h | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'test/cpp/interop') diff --git a/test/cpp/interop/interop_server.cc b/test/cpp/interop/interop_server.cc index 5b9e229804..f697dda444 100644 --- a/test/cpp/interop/interop_server.cc +++ b/test/cpp/interop/interop_server.cc @@ -321,8 +321,7 @@ void grpc::testing::interop::RunServer( } void grpc::testing::interop::RunServer( - std::shared_ptr creds, - const int port, + std::shared_ptr creds, const int port, ServerStartedCondition *server_started_condition) { GPR_ASSERT(port != 0); std::ostringstream server_address; diff --git a/test/cpp/interop/server_helper.h b/test/cpp/interop/server_helper.h index ab5de07c0e..92920b3936 100644 --- a/test/cpp/interop/server_helper.h +++ b/test/cpp/interop/server_helper.h @@ -69,8 +69,7 @@ void RunServer(std::shared_ptr creds); /// \param port Port to use for the server. /// \param server_started_condition (optional) Struct holding mutex, condition /// variable, and condition used to notify when the server has started. -void RunServer(std::shared_ptr creds, - int port, +void RunServer(std::shared_ptr creds, int port, ServerStartedCondition *server_started_condition); } // namespace interop -- cgit v1.2.3 From 472d7c92324213f5b7c0debc5f23720007d910b9 Mon Sep 17 00:00:00 2001 From: Dan Wittmer Date: Fri, 17 Nov 2017 15:49:11 -0800 Subject: Fix formatting - missed moving ‘*’ next to type. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/cpp/interop/interop_server.cc | 2 +- test/cpp/interop/server_helper.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'test/cpp/interop') diff --git a/test/cpp/interop/interop_server.cc b/test/cpp/interop/interop_server.cc index f697dda444..7a028111ef 100644 --- a/test/cpp/interop/interop_server.cc +++ b/test/cpp/interop/interop_server.cc @@ -322,7 +322,7 @@ void grpc::testing::interop::RunServer( void grpc::testing::interop::RunServer( std::shared_ptr creds, const int port, - ServerStartedCondition *server_started_condition) { + ServerStartedCondition* server_started_condition) { GPR_ASSERT(port != 0); std::ostringstream server_address; server_address << "0.0.0.0:" << port; diff --git a/test/cpp/interop/server_helper.h b/test/cpp/interop/server_helper.h index 92920b3936..1bf7db1e14 100644 --- a/test/cpp/interop/server_helper.h +++ b/test/cpp/interop/server_helper.h @@ -70,7 +70,7 @@ void RunServer(std::shared_ptr creds); /// \param server_started_condition (optional) Struct holding mutex, condition /// variable, and condition used to notify when the server has started. void RunServer(std::shared_ptr creds, int port, - ServerStartedCondition *server_started_condition); + ServerStartedCondition* server_started_condition); } // namespace interop } // namespace testing -- cgit v1.2.3