aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/cpp/interop
diff options
context:
space:
mode:
authorGravatar Dan Wittmer <wittmer@google.com>2017-11-06 10:50:26 -0800
committerGravatar Dan Wittmer <wittmer@google.com>2017-11-09 12:01:31 -0800
commit572dd8e8970ec660fb281dfde0cf22c0ee20f31c (patch)
tree7829a3fc25eae040d65c66f51e866382c76ee0a1 /test/cpp/interop
parente5bca395f9bd9e6c017db3fd318ec608b5289341 (diff)
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.
Diffstat (limited to 'test/cpp/interop')
-rw-r--r--test/cpp/interop/interop_server.cc15
-rw-r--r--test/cpp/interop/server_helper.h15
2 files changed, 28 insertions, 2 deletions
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<ServerCredentials> creds) {
- GPR_ASSERT(FLAGS_port != 0);
+ RunServer(creds, FLAGS_port, nullptr);
+}
+
+void grpc::testing::interop::RunServer(
+ std::shared_ptr<ServerCredentials> 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> 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 <condition_variable>
#include <memory>
#include <grpc/compression.h>
@@ -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<ServerCredentials> 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<ServerCredentials> creds,
+ int port,
+ std::condition_variable *server_started_condition);
+
} // namespace interop
} // namespace testing
} // namespace grpc