From 7190b0c6510b75766362c43ec32c9e497057bced Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Wed, 26 Oct 2016 09:02:37 -0700 Subject: [PATCH 1/7] Add ChannelArguments::SetLoadBalancingPolicyName() to C++ API. --- include/grpc++/support/channel_arguments.h | 5 +++++ src/cpp/common/channel_arguments.cc | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/include/grpc++/support/channel_arguments.h b/include/grpc++/support/channel_arguments.h index ae243939e9a..9de5497fb8f 100644 --- a/include/grpc++/support/channel_arguments.h +++ b/include/grpc++/support/channel_arguments.h @@ -80,6 +80,11 @@ class ChannelArguments { /// The given string will be sent at the front of the user agent string. void SetUserAgentPrefix(const grpc::string& user_agent_prefix); + // Set LB policy name. + // Note that if the name resolver returns only balancer addresses, the + // grpclb LB policy will be used, regardless of what is specified here. + void SetLoadBalancingPolicyName(const grpc::string& lb_policy_name); + // Generic channel argument setters. Only for advanced use cases. /// Set an integer argument \a value under \a key. void SetInt(const grpc::string& key, int value); diff --git a/src/cpp/common/channel_arguments.cc b/src/cpp/common/channel_arguments.cc index f297ae85870..d16d27e86cf 100644 --- a/src/cpp/common/channel_arguments.cc +++ b/src/cpp/common/channel_arguments.cc @@ -113,6 +113,11 @@ void ChannelArguments::SetUserAgentPrefix( } } +void ChannelArguments::SetLoadBalancingPolicyName( + const grpc::string& lb_policy_name) { + SetString(GRPC_ARG_LB_POLICY_NAME, lb_policy_name); +} + void ChannelArguments::SetInt(const grpc::string& key, int value) { grpc_arg arg; arg.type = GRPC_ARG_INTEGER; From 452287607fd2d838e1f5dd7f009cbf7ad95e2346 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Wed, 26 Oct 2016 14:54:56 -0700 Subject: [PATCH 2/7] Add test for setting LB policy via C++ API. --- Makefile | 48 ++++ build.yaml | 13 ++ test/cpp/end2end/round_robin_end2end_test.cc | 209 ++++++++++++++++++ tools/run_tests/sources_and_headers.json | 19 ++ tools/run_tests/tests.json | 22 ++ .../round_robin_end2end_test.vcxproj | 207 +++++++++++++++++ .../round_robin_end2end_test.vcxproj.filters | 21 ++ 7 files changed, 539 insertions(+) create mode 100644 test/cpp/end2end/round_robin_end2end_test.cc create mode 100644 vsprojects/vcxproj/test/round_robin_end2end_test/round_robin_end2end_test.vcxproj create mode 100644 vsprojects/vcxproj/test/round_robin_end2end_test/round_robin_end2end_test.vcxproj.filters diff --git a/Makefile b/Makefile index e789b1f38b6..e13c0045092 100644 --- a/Makefile +++ b/Makefile @@ -1075,6 +1075,7 @@ qps_openloop_test: $(BINDIR)/$(CONFIG)/qps_openloop_test qps_worker: $(BINDIR)/$(CONFIG)/qps_worker reconnect_interop_client: $(BINDIR)/$(CONFIG)/reconnect_interop_client reconnect_interop_server: $(BINDIR)/$(CONFIG)/reconnect_interop_server +round_robin_end2end_test: $(BINDIR)/$(CONFIG)/round_robin_end2end_test secure_auth_context_test: $(BINDIR)/$(CONFIG)/secure_auth_context_test secure_sync_unary_ping_pong_test: $(BINDIR)/$(CONFIG)/secure_sync_unary_ping_pong_test server_builder_plugin_test: $(BINDIR)/$(CONFIG)/server_builder_plugin_test @@ -1451,6 +1452,7 @@ buildtests_cxx: privatelibs_cxx \ $(BINDIR)/$(CONFIG)/qps_worker \ $(BINDIR)/$(CONFIG)/reconnect_interop_client \ $(BINDIR)/$(CONFIG)/reconnect_interop_server \ + $(BINDIR)/$(CONFIG)/round_robin_end2end_test \ $(BINDIR)/$(CONFIG)/secure_auth_context_test \ $(BINDIR)/$(CONFIG)/secure_sync_unary_ping_pong_test \ $(BINDIR)/$(CONFIG)/server_builder_plugin_test \ @@ -1539,6 +1541,7 @@ buildtests_cxx: privatelibs_cxx \ $(BINDIR)/$(CONFIG)/qps_worker \ $(BINDIR)/$(CONFIG)/reconnect_interop_client \ $(BINDIR)/$(CONFIG)/reconnect_interop_server \ + $(BINDIR)/$(CONFIG)/round_robin_end2end_test \ $(BINDIR)/$(CONFIG)/secure_auth_context_test \ $(BINDIR)/$(CONFIG)/secure_sync_unary_ping_pong_test \ $(BINDIR)/$(CONFIG)/server_builder_plugin_test \ @@ -1845,6 +1848,8 @@ test_cxx: buildtests_cxx $(Q) $(BINDIR)/$(CONFIG)/proto_server_reflection_test || ( echo test proto_server_reflection_test failed ; exit 1 ) $(E) "[RUN] Testing qps_openloop_test" $(Q) $(BINDIR)/$(CONFIG)/qps_openloop_test || ( echo test qps_openloop_test failed ; exit 1 ) + $(E) "[RUN] Testing round_robin_end2end_test" + $(Q) $(BINDIR)/$(CONFIG)/round_robin_end2end_test || ( echo test round_robin_end2end_test failed ; exit 1 ) $(E) "[RUN] Testing secure_auth_context_test" $(Q) $(BINDIR)/$(CONFIG)/secure_auth_context_test || ( echo test secure_auth_context_test failed ; exit 1 ) $(E) "[RUN] Testing secure_sync_unary_ping_pong_test" @@ -13014,6 +13019,49 @@ endif $(OBJDIR)/$(CONFIG)/test/cpp/interop/reconnect_interop_server.o: $(GENDIR)/src/proto/grpc/testing/empty.pb.cc $(GENDIR)/src/proto/grpc/testing/empty.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/test.pb.cc $(GENDIR)/src/proto/grpc/testing/test.grpc.pb.cc +ROUND_ROBIN_END2END_TEST_SRC = \ + test/cpp/end2end/round_robin_end2end_test.cc \ + +ROUND_ROBIN_END2END_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(ROUND_ROBIN_END2END_TEST_SRC)))) +ifeq ($(NO_SECURE),true) + +# You can't build secure targets if you don't have OpenSSL. + +$(BINDIR)/$(CONFIG)/round_robin_end2end_test: openssl_dep_error + +else + + + + +ifeq ($(NO_PROTOBUF),true) + +# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. + +$(BINDIR)/$(CONFIG)/round_robin_end2end_test: protobuf_dep_error + +else + +$(BINDIR)/$(CONFIG)/round_robin_end2end_test: $(PROTOBUF_DEP) $(ROUND_ROBIN_END2END_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a + $(E) "[LD] Linking $@" + $(Q) mkdir -p `dirname $@` + $(Q) $(LDXX) $(LDFLAGS) $(ROUND_ROBIN_END2END_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/round_robin_end2end_test + +endif + +endif + +$(OBJDIR)/$(CONFIG)/test/cpp/end2end/round_robin_end2end_test.o: $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a + +deps_round_robin_end2end_test: $(ROUND_ROBIN_END2END_TEST_OBJS:.o=.dep) + +ifneq ($(NO_SECURE),true) +ifneq ($(NO_DEPS),true) +-include $(ROUND_ROBIN_END2END_TEST_OBJS:.o=.dep) +endif +endif + + SECURE_AUTH_CONTEXT_TEST_SRC = \ test/cpp/common/secure_auth_context_test.cc \ diff --git a/build.yaml b/build.yaml index 0400fa7b213..bd2349b8ef4 100644 --- a/build.yaml +++ b/build.yaml @@ -3319,6 +3319,19 @@ targets: - gpr_test_util - gpr - grpc++_test_config +- name: round_robin_end2end_test + gtest: true + build: test + language: c++ + src: + - test/cpp/end2end/round_robin_end2end_test.cc + deps: + - grpc++_test_util + - grpc_test_util + - grpc++ + - grpc + - gpr_test_util + - gpr - name: secure_auth_context_test gtest: true build: test diff --git a/test/cpp/end2end/round_robin_end2end_test.cc b/test/cpp/end2end/round_robin_end2end_test.cc new file mode 100644 index 00000000000..fe0cd0baa40 --- /dev/null +++ b/test/cpp/end2end/round_robin_end2end_test.cc @@ -0,0 +1,209 @@ +/* + * + * Copyright 2016, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "src/proto/grpc/testing/echo.grpc.pb.h" +#include "test/core/util/port.h" +#include "test/core/util/test_config.h" +#include "test/cpp/end2end/test_service_impl.h" + +using grpc::testing::EchoRequest; +using grpc::testing::EchoResponse; +using std::chrono::system_clock; + +namespace grpc { +namespace testing { +namespace { + +// Subclass of TestServiceImpl that increments a request counter for +// every call to the Echo RPC. +class MyTestServiceImpl : public TestServiceImpl { + public: + Status Echo(ServerContext* context, const EchoRequest* request, + EchoResponse* response) GRPC_OVERRIDE { + { + unique_lock lock(mu_); + ++request_count_; + } + return TestServiceImpl::Echo(context, request, response); + } + + int request_count() { + unique_lock lock(mu_); + return request_count_; + } + + private: + mutex mu_; + int request_count_ = 0; +}; + +class RoundRobinEnd2endTest : public ::testing::Test { + protected: + RoundRobinEnd2endTest() : server_host_("localhost") {} + + void StartServers(int num_servers) { + for (int i = 0; i < num_servers; ++i) { + servers_.emplace_back(new ServerData(server_host_)); + } + } + + void TearDown() GRPC_OVERRIDE { + for (const auto& server : servers_) { + server->Shutdown(); + } + } + + void ResetStub(bool round_robin) { + ChannelArguments args; + if (round_robin) args.SetLoadBalancingPolicyName("round_robin"); + std::ostringstream uri; + uri << "ipv4:///"; + for (size_t i = 0; i < servers_.size() - 1; ++i) { + uri << "127.0.0.1:" << servers_[i]->port_ << ","; + } + uri << "127.0.0.1:" << servers_[servers_.size() - 1]->port_; + std::shared_ptr channel = CreateCustomChannel( + uri.str(), InsecureChannelCredentials(), args); + stub_ = grpc::testing::EchoTestService::NewStub(channel); + } + + void SendRpc(int num_rpcs) { + EchoRequest request; + EchoResponse response; + request.set_message("Live long and prosper."); + for (int i = 0; i < num_rpcs; i++) { + ClientContext context; + Status status = stub_->Echo(&context, request, &response); + EXPECT_TRUE(status.ok()); + EXPECT_EQ(response.message(), request.message()); + } + } + + struct ServerData { + int port_; + std::unique_ptr server_; + MyTestServiceImpl service_; + std::thread* thread_; + + explicit ServerData(const grpc::string& server_host) { + port_ = grpc_pick_unused_port_or_die(); + 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 lock(mu); + cond.notify_one(); + }); + unique_lock lock(mu); + cond.wait(lock); + gpr_log(GPR_INFO, "server startup complete"); + } + + void Start(const grpc::string& server_host) { + std::ostringstream server_address; + server_address << server_host << ":" << port_; + ServerBuilder builder; + builder.AddListeningPort(server_address.str(), + InsecureServerCredentials()); + builder.RegisterService(&service_); + server_ = builder.BuildAndStart(); + } + + void Shutdown() { + server_->Shutdown(); + thread_->join(); + } + }; + + const grpc::string server_host_; + CompletionQueue cli_cq_; + std::unique_ptr stub_; + std::vector> servers_; +}; + +TEST_F(RoundRobinEnd2endTest, PickFirst) { + // Start servers and send one RPC per server. + const int kNumServers = 3; + StartServers(kNumServers); + ResetStub(false /* round_robin */); + 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(); + if (request_count == kNumServers) { + found = true; + } else { + EXPECT_EQ(0, request_count); + } + } + EXPECT_TRUE(found); +} + +TEST_F(RoundRobinEnd2endTest, RoundRobin) { + // Start servers and send one RPC per server. + const int kNumServers = 3; + StartServers(kNumServers); + 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()); + } +} + +} // namespace +} // namespace testing +} // namespace grpc + +int main(int argc, char** argv) { + grpc_test_init(argc, argv); + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/tools/run_tests/sources_and_headers.json b/tools/run_tests/sources_and_headers.json index 46a83c24794..4b5ba6a1d5a 100644 --- a/tools/run_tests/sources_and_headers.json +++ b/tools/run_tests/sources_and_headers.json @@ -2971,6 +2971,25 @@ "third_party": false, "type": "target" }, + { + "deps": [ + "gpr", + "gpr_test_util", + "grpc", + "grpc++", + "grpc++_test_util", + "grpc_test_util" + ], + "headers": [], + "is_filegroup": false, + "language": "c++", + "name": "round_robin_end2end_test", + "src": [ + "test/cpp/end2end/round_robin_end2end_test.cc" + ], + "third_party": false, + "type": "target" + }, { "deps": [ "gpr", diff --git a/tools/run_tests/tests.json b/tools/run_tests/tests.json index 5cb50cc999c..278e2868519 100644 --- a/tools/run_tests/tests.json +++ b/tools/run_tests/tests.json @@ -2801,6 +2801,28 @@ "posix" ] }, + { + "args": [], + "ci_platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "gtest": true, + "language": "c++", + "name": "round_robin_end2end_test", + "platforms": [ + "linux", + "mac", + "posix", + "windows" + ] + }, { "args": [], "ci_platforms": [ diff --git a/vsprojects/vcxproj/test/round_robin_end2end_test/round_robin_end2end_test.vcxproj b/vsprojects/vcxproj/test/round_robin_end2end_test/round_robin_end2end_test.vcxproj new file mode 100644 index 00000000000..55e16f188dc --- /dev/null +++ b/vsprojects/vcxproj/test/round_robin_end2end_test/round_robin_end2end_test.vcxproj @@ -0,0 +1,207 @@ + + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {54B15DF6-42BA-5347-C9B8-2D7F1F2921C6} + true + $(SolutionDir)IntDir\$(MSBuildProjectName)\ + + + + v100 + + + v110 + + + v120 + + + v140 + + + Application + true + Unicode + + + Application + false + true + Unicode + + + + + + + + + + + + + + + + round_robin_end2end_test + static + Debug + static + Debug + + + round_robin_end2end_test + static + Release + static + Release + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + true + None + false + + + Console + true + false + + + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + true + None + false + + + Console + true + false + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + true + None + false + + + Console + true + false + true + true + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + true + None + false + + + Console + true + false + true + true + + + + + + + + + + {0BE77741-552A-929B-A497-4EF7ECE17A64} + + + {17BCAFC0-5FDC-4C94-AEB9-95F3E220614B} + + + {C187A093-A0FE-489D-A40A-6E33DE0F9FEB} + + + {29D16885-7228-4C31-81ED-5F9187C7F2A9} + + + {EAB0A629-17A9-44DB-B5FF-E91A721FE037} + + + {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792} + + + + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + + + diff --git a/vsprojects/vcxproj/test/round_robin_end2end_test/round_robin_end2end_test.vcxproj.filters b/vsprojects/vcxproj/test/round_robin_end2end_test/round_robin_end2end_test.vcxproj.filters new file mode 100644 index 00000000000..95a149953fc --- /dev/null +++ b/vsprojects/vcxproj/test/round_robin_end2end_test/round_robin_end2end_test.vcxproj.filters @@ -0,0 +1,21 @@ + + + + + test\cpp\end2end + + + + + + {e151f47d-6563-5ef9-fae6-70708f9f8ee6} + + + {07958594-fd93-28f7-9388-c67c952701b8} + + + {7596a0dd-caa4-b365-a59f-f7ffef38b10d} + + + + From fd635add1c96344398fafb33fb2ba86a22055a5d Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Mon, 31 Oct 2016 14:20:56 -0700 Subject: [PATCH 3/7] clang-format --- test/cpp/end2end/round_robin_end2end_test.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/cpp/end2end/round_robin_end2end_test.cc b/test/cpp/end2end/round_robin_end2end_test.cc index fe0cd0baa40..6ee7417db87 100644 --- a/test/cpp/end2end/round_robin_end2end_test.cc +++ b/test/cpp/end2end/round_robin_end2end_test.cc @@ -107,8 +107,8 @@ class RoundRobinEnd2endTest : public ::testing::Test { uri << "127.0.0.1:" << servers_[i]->port_ << ","; } uri << "127.0.0.1:" << servers_[servers_.size() - 1]->port_; - std::shared_ptr channel = CreateCustomChannel( - uri.str(), InsecureChannelCredentials(), args); + std::shared_ptr channel = + CreateCustomChannel(uri.str(), InsecureChannelCredentials(), args); stub_ = grpc::testing::EchoTestService::NewStub(channel); } From 6df607591ce42eee46538726432960e03f6db85d Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Mon, 31 Oct 2016 14:39:45 -0700 Subject: [PATCH 4/7] Fix portability problems. --- test/cpp/end2end/round_robin_end2end_test.cc | 28 +++++++++++--------- 1 file 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 6ee7417db87..f4ca3baa548 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 lock(mu); - cond.notify_one(); - }); + thread_ = new std::thread( + std::bind(&ServerData::Start, this, server_host, &mu, &cond)); unique_lock 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 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()); } } From 3f265857f41c88ef7c7d7a8f1ace89a1a3f839ba Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Mon, 31 Oct 2016 14:42:22 -0700 Subject: [PATCH 5/7] Fix memory leak. --- test/cpp/end2end/round_robin_end2end_test.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/cpp/end2end/round_robin_end2end_test.cc b/test/cpp/end2end/round_robin_end2end_test.cc index f4ca3baa548..796b01cd4ac 100644 --- a/test/cpp/end2end/round_robin_end2end_test.cc +++ b/test/cpp/end2end/round_robin_end2end_test.cc @@ -130,15 +130,15 @@ class RoundRobinEnd2endTest : public ::testing::Test { int port_; std::unique_ptr server_; MyTestServiceImpl service_; - std::thread* thread_; + std::unique_ptr thread_; explicit ServerData(const grpc::string& server_host) { port_ = grpc_pick_unused_port_or_die(); gpr_log(GPR_INFO, "starting server on port %d", port_); std::mutex mu; std::condition_variable cond; - thread_ = new std::thread( - std::bind(&ServerData::Start, this, server_host, &mu, &cond)); + thread_.reset(new std::thread( + std::bind(&ServerData::Start, this, server_host, &mu, &cond))); unique_lock lock(mu); cond.wait(lock); gpr_log(GPR_INFO, "server startup complete"); From 87a066e5b1fa42cf057b3fdf4849ca581153bf5b Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Tue, 1 Nov 2016 11:06:26 -0700 Subject: [PATCH 6/7] Ran generate_projects.sh --- tools/run_tests/tests.json | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/run_tests/tests.json b/tools/run_tests/tests.json index 4f602fe31e1..878cba35dfa 100644 --- a/tools/run_tests/tests.json +++ b/tools/run_tests/tests.json @@ -3025,6 +3025,7 @@ ], "cpu_cost": 1.0, "exclude_configs": [], + "exclude_iomgrs": [], "flaky": false, "gtest": false, "language": "c++", From 754b2b88bc7bf35629573ba46a9600e385cd7100 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Wed, 2 Nov 2016 08:39:16 -0700 Subject: [PATCH 7/7] Code review changes. --- include/grpc++/support/channel_arguments.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/grpc++/support/channel_arguments.h b/include/grpc++/support/channel_arguments.h index 11d10f4a559..49a3e9461cf 100644 --- a/include/grpc++/support/channel_arguments.h +++ b/include/grpc++/support/channel_arguments.h @@ -85,9 +85,9 @@ class ChannelArguments { /// The given buffer pool will be attached to the constructed channel void SetResourceQuota(const ResourceQuota& resource_quota); - // Set LB policy name. - // Note that if the name resolver returns only balancer addresses, the - // grpclb LB policy will be used, regardless of what is specified here. + /// Set LB policy name. + /// Note that if the name resolver returns only balancer addresses, the + /// grpclb LB policy will be used, regardless of what is specified here. void SetLoadBalancingPolicyName(const grpc::string& lb_policy_name); // Generic channel argument setters. Only for advanced use cases.