diff options
author | David Garcia Quintas <dgq@google.com> | 2017-09-06 18:58:25 -0700 |
---|---|---|
committer | David Garcia Quintas <dgq@google.com> | 2017-09-06 18:58:25 -0700 |
commit | 4dc3c0bdd33892af5a79964ee3e881c7ad86eb3e (patch) | |
tree | ff9e6e138b061a6a770393b5368258c2d647d1df /test/cpp | |
parent | 243fe9d43c6bed0168670255d8208795c8438a79 (diff) | |
parent | 04035de631a6a46c03ebf3e8db2102d5688dc71a (diff) |
Merge branch 'master' of github.com:grpc/grpc into filters_prio
Diffstat (limited to 'test/cpp')
-rw-r--r-- | test/cpp/codegen/BUILD | 9 | ||||
-rw-r--r-- | test/cpp/common/BUILD | 9 | ||||
-rw-r--r-- | test/cpp/end2end/BUILD | 12 | ||||
-rw-r--r-- | test/cpp/end2end/client_lb_end2end_test.cc | 77 | ||||
-rw-r--r-- | test/cpp/interop/BUILD | 9 | ||||
-rw-r--r-- | test/cpp/microbenchmarks/BUILD | 9 | ||||
-rw-r--r-- | test/cpp/microbenchmarks/bm_cq_multiple_threads.cc | 2 | ||||
-rw-r--r-- | test/cpp/microbenchmarks/helpers.cc | 7 | ||||
-rw-r--r-- | test/cpp/microbenchmarks/helpers.h | 3 | ||||
-rw-r--r-- | test/cpp/qps/BUILD | 9 | ||||
-rw-r--r-- | test/cpp/qps/client.h | 28 | ||||
-rw-r--r-- | test/cpp/qps/interarrival.h | 12 | ||||
-rw-r--r-- | test/cpp/server/BUILD | 4 | ||||
-rw-r--r-- | test/cpp/util/BUILD | 10 |
14 files changed, 89 insertions, 111 deletions
diff --git a/test/cpp/codegen/BUILD b/test/cpp/codegen/BUILD index 4780800645..8de46be816 100644 --- a/test/cpp/codegen/BUILD +++ b/test/cpp/codegen/BUILD @@ -14,14 +14,9 @@ licenses(["notice"]) # Apache v2 -load("//bazel:grpc_build_system.bzl", "grpc_cc_test") +load("//bazel:grpc_build_system.bzl", "grpc_cc_test", "grpc_package") -package( - features = [ - "-layering_check", - "-parse_headers", - ], -) +grpc_package(name = "test/cpp/codegen") grpc_cc_test( name = "codegen_test_full", diff --git a/test/cpp/common/BUILD b/test/cpp/common/BUILD index be9c279f13..e2b6365b13 100644 --- a/test/cpp/common/BUILD +++ b/test/cpp/common/BUILD @@ -14,14 +14,9 @@ licenses(["notice"]) # Apache v2 -load("//bazel:grpc_build_system.bzl", "grpc_cc_test") +load("//bazel:grpc_build_system.bzl", "grpc_cc_test", "grpc_package") -package( - features = [ - "-layering_check", - "-parse_headers", - ], -) +grpc_package(name = "test/cpp/common") grpc_cc_test( name = "alarm_cpp_test", diff --git a/test/cpp/end2end/BUILD b/test/cpp/end2end/BUILD index 27c5492c17..b29a13d4fb 100644 --- a/test/cpp/end2end/BUILD +++ b/test/cpp/end2end/BUILD @@ -14,15 +14,9 @@ licenses(["notice"]) # Apache v2 -load("//bazel:grpc_build_system.bzl", "grpc_cc_library", "grpc_cc_test") +load("//bazel:grpc_build_system.bzl", "grpc_cc_library", "grpc_cc_test", "grpc_package") -package( - default_visibility=["//visibility:public"], # Allows external users to implement end2end tests. - features = [ - "-layering_check", - "-parse_headers", - ], -) +grpc_package(name = "test/cpp/end2end", visibility = "public") # Allows external users to implement end2end tests. grpc_cc_library( name = "test_service_impl", @@ -199,6 +193,7 @@ grpc_cc_test( "//test/cpp/util:test_util", ], external_deps = [ + "gmock", "gtest", ], ) @@ -241,6 +236,7 @@ grpc_cc_test( "//test/cpp/util:test_util", ], external_deps = [ + "gmock", "gtest", ], ) diff --git a/test/cpp/end2end/client_lb_end2end_test.cc b/test/cpp/end2end/client_lb_end2end_test.cc index 0f541c4364..b588eda84f 100644 --- a/test/cpp/end2end/client_lb_end2end_test.cc +++ b/test/cpp/end2end/client_lb_end2end_test.cc @@ -85,7 +85,8 @@ class MyTestServiceImpl : public TestServiceImpl { class ClientLbEnd2endTest : public ::testing::Test { protected: - ClientLbEnd2endTest() : server_host_("localhost") {} + ClientLbEnd2endTest() + : server_host_("localhost"), kRequestMessage_("Live long and prosper.") {} void SetUp() override { response_generator_ = grpc_fake_resolver_response_generator_create(); @@ -139,6 +140,7 @@ class ClientLbEnd2endTest : public ::testing::Test { } // else, default to pick first args.SetPointer(GRPC_ARG_FAKE_RESOLVER_RESPONSE_GENERATOR, response_generator_); + args.SetInt("grpc.testing.fixed_reconnect_backoff_ms", 2000); std::ostringstream uri; uri << "fake:///"; for (size_t i = 0; i < servers_.size() - 1; ++i) { @@ -150,18 +152,27 @@ class ClientLbEnd2endTest : public ::testing::Test { stub_ = grpc::testing::EchoTestService::NewStub(channel_); } - void SendRpc(bool expect_ok = true) { + Status SendRpc(EchoResponse* response = nullptr) { + const bool local_response = (response == nullptr); + if (local_response) response = new EchoResponse; EchoRequest request; - EchoResponse response; - request.set_message("Live long and prosper."); + request.set_message(kRequestMessage_); ClientContext context; - Status status = stub_->Echo(&context, request, &response); - if (expect_ok) { - EXPECT_TRUE(status.ok()); - EXPECT_EQ(response.message(), request.message()); - } else { - EXPECT_FALSE(status.ok()); - } + Status status = stub_->Echo(&context, request, response); + if (local_response) delete response; + return status; + } + + void CheckRpcSendOk() { + EchoResponse response; + const Status status = SendRpc(&response); + EXPECT_TRUE(status.ok()); + EXPECT_EQ(response.message(), kRequestMessage_); + } + + void CheckRpcSendFailure() { + const Status status = SendRpc(); + EXPECT_FALSE(status.ok()); } struct ServerData { @@ -207,7 +218,7 @@ class ClientLbEnd2endTest : public ::testing::Test { void WaitForServer(size_t server_idx) { do { - SendRpc(); + CheckRpcSendOk(); } while (servers_[server_idx]->service_.request_count() == 0); ResetCounters(); } @@ -217,6 +228,7 @@ class ClientLbEnd2endTest : public ::testing::Test { std::unique_ptr<grpc::testing::EchoTestService::Stub> stub_; std::vector<std::unique_ptr<ServerData>> servers_; grpc_fake_resolver_response_generator* response_generator_; + const grpc::string kRequestMessage_; }; TEST_F(ClientLbEnd2endTest, PickFirst) { @@ -230,7 +242,7 @@ TEST_F(ClientLbEnd2endTest, PickFirst) { } SetNextResolution(ports); for (size_t i = 0; i < servers_.size(); ++i) { - SendRpc(); + CheckRpcSendOk(); } // All requests should have gone to a single server. bool found = false; @@ -258,7 +270,7 @@ TEST_F(ClientLbEnd2endTest, PickFirstUpdates) { ports.emplace_back(servers_[0]->port_); SetNextResolution(ports); gpr_log(GPR_INFO, "****** SET [0] *******"); - SendRpc(); + CheckRpcSendOk(); EXPECT_EQ(servers_[0]->service_.request_count(), 1); // An empty update will result in the channel going into TRANSIENT_FAILURE. @@ -304,7 +316,7 @@ TEST_F(ClientLbEnd2endTest, PickFirstUpdateSuperset) { ports.emplace_back(servers_[0]->port_); SetNextResolution(ports); gpr_log(GPR_INFO, "****** SET [0] *******"); - SendRpc(); + CheckRpcSendOk(); EXPECT_EQ(servers_[0]->service_.request_count(), 1); servers_[0]->service_.ResetCounters(); @@ -314,7 +326,7 @@ TEST_F(ClientLbEnd2endTest, PickFirstUpdateSuperset) { ports.emplace_back(servers_[0]->port_); SetNextResolution(ports); gpr_log(GPR_INFO, "****** SET superset *******"); - SendRpc(); + CheckRpcSendOk(); // We stick to the previously connected server. WaitForServer(0); EXPECT_EQ(0, servers_[1]->service_.request_count()); @@ -338,7 +350,7 @@ TEST_F(ClientLbEnd2endTest, PickFirstManyUpdates) { for (size_t i = 0; i < 1000; ++i) { std::random_shuffle(ports.begin(), ports.end()); SetNextResolution(ports); - if (i % 10 == 0) SendRpc(); + if (i % 10 == 0) CheckRpcSendOk(); } } // Check LB policy name for the channel. @@ -356,7 +368,7 @@ TEST_F(ClientLbEnd2endTest, RoundRobin) { } SetNextResolution(ports); for (size_t i = 0; i < servers_.size(); ++i) { - SendRpc(); + CheckRpcSendOk(); } // One request should have gone to each server. for (size_t i = 0; i < servers_.size(); ++i) { @@ -378,7 +390,7 @@ TEST_F(ClientLbEnd2endTest, RoundRobinUpdates) { SetNextResolution(ports); WaitForServer(0); // Send RPCs. They should all go servers_[0] - for (size_t i = 0; i < 10; ++i) SendRpc(); + for (size_t i = 0; i < 10; ++i) CheckRpcSendOk(); EXPECT_EQ(10, servers_[0]->service_.request_count()); EXPECT_EQ(0, servers_[1]->service_.request_count()); EXPECT_EQ(0, servers_[2]->service_.request_count()); @@ -394,7 +406,7 @@ TEST_F(ClientLbEnd2endTest, RoundRobinUpdates) { EXPECT_EQ(0, servers_[1]->service_.request_count()); WaitForServer(1); - for (size_t i = 0; i < 10; ++i) SendRpc(); + for (size_t i = 0; i < 10; ++i) CheckRpcSendOk(); EXPECT_EQ(0, servers_[0]->service_.request_count()); EXPECT_EQ(10, servers_[1]->service_.request_count()); EXPECT_EQ(0, servers_[2]->service_.request_count()); @@ -406,7 +418,7 @@ TEST_F(ClientLbEnd2endTest, RoundRobinUpdates) { SetNextResolution(ports); WaitForServer(2); - for (size_t i = 0; i < 10; ++i) SendRpc(); + for (size_t i = 0; i < 10; ++i) CheckRpcSendOk(); EXPECT_EQ(0, servers_[0]->service_.request_count()); EXPECT_EQ(0, servers_[1]->service_.request_count()); EXPECT_EQ(10, servers_[2]->service_.request_count()); @@ -423,7 +435,7 @@ TEST_F(ClientLbEnd2endTest, RoundRobinUpdates) { WaitForServer(2); // Send three RPCs, one per server. - for (size_t i = 0; i < 3; ++i) SendRpc(); + for (size_t i = 0; i < 3; ++i) CheckRpcSendOk(); EXPECT_EQ(1, servers_[0]->service_.request_count()); EXPECT_EQ(1, servers_[1]->service_.request_count()); EXPECT_EQ(1, servers_[2]->service_.request_count()); @@ -493,7 +505,7 @@ TEST_F(ClientLbEnd2endTest, RoundRobinManyUpdates) { for (size_t i = 0; i < 1000; ++i) { std::random_shuffle(ports.begin(), ports.end()); SetNextResolution(ports); - if (i % 10 == 0) SendRpc(); + if (i % 10 == 0) CheckRpcSendOk(); } // Check LB policy name for the channel. EXPECT_EQ("round_robin", channel_->GetLoadBalancingPolicyName()); @@ -504,11 +516,13 @@ TEST_F(ClientLbEnd2endTest, RoundRobinConcurrentUpdates) { // update provisions of RR. } -TEST_F(ClientLbEnd2endTest, RoundRobinReconnect) { +TEST_F(ClientLbEnd2endTest, RoundRobinReresolve) { // Start servers and send one RPC per server. - const int kNumServers = 1; + const int kNumServers = 3; std::vector<int> ports; - ports.push_back(grpc_pick_unused_port_or_die()); + for (int i = 0; i < kNumServers; ++i) { + ports.push_back(grpc_pick_unused_port_or_die()); + } StartServers(kNumServers, ports); ResetStub("round_robin"); SetNextResolution(ports); @@ -517,24 +531,19 @@ TEST_F(ClientLbEnd2endTest, RoundRobinReconnect) { // state READY in the order in which the addresses are specified, // which is only true because the backends are all local. for (size_t i = 0; i < servers_.size(); ++i) { - SendRpc(); + CheckRpcSendOk(); EXPECT_EQ(1, servers_[i]->service_.request_count()) << "for backend #" << i; } - // Check LB policy name for the channel. - EXPECT_EQ("round_robin", channel_->GetLoadBalancingPolicyName()); - // Kill all servers for (size_t i = 0; i < servers_.size(); ++i) { servers_[i]->Shutdown(false); } // Client request should fail. - SendRpc(false); - + CheckRpcSendFailure(); // Bring servers back up on the same port (we aren't recreating the channel). StartServers(kNumServers, ports); - // Client request should succeed. - SendRpc(); + CheckRpcSendOk(); } } // namespace diff --git a/test/cpp/interop/BUILD b/test/cpp/interop/BUILD index 9123bd929e..4f21551ff4 100644 --- a/test/cpp/interop/BUILD +++ b/test/cpp/interop/BUILD @@ -14,14 +14,9 @@ licenses(["notice"]) # Apache v2 -load("//bazel:grpc_build_system.bzl", "grpc_cc_library", "grpc_cc_test", "grpc_cc_binary") +load("//bazel:grpc_build_system.bzl", "grpc_cc_library", "grpc_cc_test", "grpc_cc_binary", "grpc_package") -package( - features = [ - "-layering_check", - "-parse_headers", - ], -) +grpc_package(name = "test/cpp/interop") grpc_cc_library( name = "server_helper_lib", diff --git a/test/cpp/microbenchmarks/BUILD b/test/cpp/microbenchmarks/BUILD index fc0294da56..83b91e2ce9 100644 --- a/test/cpp/microbenchmarks/BUILD +++ b/test/cpp/microbenchmarks/BUILD @@ -14,14 +14,9 @@ licenses(["notice"]) # Apache v2 -load("//bazel:grpc_build_system.bzl", "grpc_cc_test", "grpc_cc_library", "grpc_cc_binary") +load("//bazel:grpc_build_system.bzl", "grpc_cc_test", "grpc_cc_library", "grpc_cc_binary", "grpc_package") -package( - features = [ - "-layering_check", - "-parse_headers", - ], -) +grpc_package(name = "test/cpp/microbenchmarks") grpc_cc_test( name = "noop-benchmark", diff --git a/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc b/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc index f109fe6251..9d71d3990d 100644 --- a/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc +++ b/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc @@ -38,6 +38,8 @@ struct grpc_pollset { namespace grpc { namespace testing { +auto& force_library_initialization = Library::get(); + static void* g_tag = (void*)(intptr_t)10; // Some random number static grpc_completion_queue* g_cq; static grpc_event_engine_vtable g_vtable; diff --git a/test/cpp/microbenchmarks/helpers.cc b/test/cpp/microbenchmarks/helpers.cc index 0c10d6c4ce..415d27445f 100644 --- a/test/cpp/microbenchmarks/helpers.cc +++ b/test/cpp/microbenchmarks/helpers.cc @@ -29,6 +29,13 @@ void TrackCounters::Finish(benchmark::State &state) { } void TrackCounters::AddToLabel(std::ostream &out, benchmark::State &state) { + grpc_stats_data stats_end; + grpc_stats_collect(&stats_end); + for (int i = 0; i < GRPC_STATS_COUNTER_COUNT; i++) { + out << " " << grpc_stats_counter_name[i] << "/iter:" + << ((double)(stats_end.counters[i] - stats_begin_.counters[i]) / + (double)state.iterations()); + } #ifdef GPR_LOW_LEVEL_COUNTERS grpc_memory_counters counters_at_end = grpc_memory_counters_snapshot(); out << " locks/iter:" << ((double)(gpr_atm_no_barrier_load(&gpr_mu_locks) - diff --git a/test/cpp/microbenchmarks/helpers.h b/test/cpp/microbenchmarks/helpers.h index c81d95a4ea..07dd611709 100644 --- a/test/cpp/microbenchmarks/helpers.h +++ b/test/cpp/microbenchmarks/helpers.h @@ -23,6 +23,7 @@ extern "C" { #include <grpc/support/port_platform.h> +#include "src/core/lib/debug/stats.h" #include "test/core/util/memory_counters.h" } @@ -62,10 +63,12 @@ extern "C" gpr_atm gpr_now_call_count; class TrackCounters { public: + TrackCounters() { grpc_stats_collect(&stats_begin_); } virtual void Finish(benchmark::State& state); virtual void AddToLabel(std::ostream& out, benchmark::State& state); private: + grpc_stats_data stats_begin_; #ifdef GPR_LOW_LEVEL_COUNTERS const size_t mu_locks_at_start_ = gpr_atm_no_barrier_load(&gpr_mu_locks); const size_t atm_cas_at_start_ = diff --git a/test/cpp/qps/BUILD b/test/cpp/qps/BUILD index b3348b76fa..31f210dec0 100644 --- a/test/cpp/qps/BUILD +++ b/test/cpp/qps/BUILD @@ -14,14 +14,9 @@ licenses(["notice"]) # Apache v2 -load("//bazel:grpc_build_system.bzl", "grpc_cc_test", "grpc_cc_library", "grpc_cc_binary") +load("//bazel:grpc_build_system.bzl", "grpc_cc_test", "grpc_cc_library", "grpc_cc_binary", "grpc_package") -package( - features = [ - "-layering_check", - "-parse_headers", - ], -) +grpc_package(name = "test/cpp/qps") grpc_cc_library( name = "parse_json", diff --git a/test/cpp/qps/client.h b/test/cpp/qps/client.h index 0794a1569a..b1d90aa9c4 100644 --- a/test/cpp/qps/client.h +++ b/test/cpp/qps/client.h @@ -369,12 +369,11 @@ class ClientImpl : public Client { ClientImpl(const ClientConfig& config, std::function<std::unique_ptr<StubType>(std::shared_ptr<Channel>)> create_stub) - : cores_(gpr_cpu_num_cores()), - channels_(config.client_channels()), - create_stub_(create_stub) { + : cores_(gpr_cpu_num_cores()), create_stub_(create_stub) { for (int i = 0; i < config.client_channels(); i++) { - channels_[i].init(config.server_targets(i % config.server_targets_size()), - config, create_stub_, i); + channels_.emplace_back( + config.server_targets(i % config.server_targets_size()), config, + create_stub_, i); } ClientRequestCreator<RequestType> create_req(&request_, @@ -388,20 +387,11 @@ class ClientImpl : public Client { class ClientChannelInfo { public: - ClientChannelInfo() {} - ClientChannelInfo(const ClientChannelInfo& i) { - // The copy constructor is to satisfy old compilers - // that need it for using std::vector . It is only ever - // used for empty entries - GPR_ASSERT(!i.channel_ && !i.stub_); - } - void init(const grpc::string& target, const ClientConfig& config, - std::function<std::unique_ptr<StubType>(std::shared_ptr<Channel>)> - create_stub, - int shard) { - // We have to use a 2-phase init like this with a default - // constructor followed by an initializer function to make - // old compilers happy with using this in std::vector + ClientChannelInfo( + const grpc::string& target, const ClientConfig& config, + std::function<std::unique_ptr<StubType>(std::shared_ptr<Channel>)> + create_stub, + int shard) { ChannelArguments args; args.SetInt("shard_to_ensure_no_subchannel_merges", shard); set_channel_args(config, &args); diff --git a/test/cpp/qps/interarrival.h b/test/cpp/qps/interarrival.h index c6e417985a..1fa310c209 100644 --- a/test/cpp/qps/interarrival.h +++ b/test/cpp/qps/interarrival.h @@ -21,7 +21,7 @@ #include <chrono> #include <cmath> -#include <cstdlib> +#include <random> #include <vector> #include <grpc++/support/config.h> @@ -75,13 +75,13 @@ class InterarrivalTimer { public: InterarrivalTimer() {} void init(const RandomDistInterface& r, int threads, int entries = 1000000) { + std::random_device devrand; + std::mt19937_64 generator(devrand()); + std::uniform_real_distribution<double> rando(0, 1); for (int i = 0; i < entries; i++) { - // rand is the only choice that is portable across POSIX and Windows - // and that supports new and old compilers - const double uniform_0_1 = - static_cast<double>(rand()) / static_cast<double>(RAND_MAX); random_table_.push_back( - static_cast<int64_t>(1e9 * r.transform(uniform_0_1))); + static_cast<int64_t>(1e9 * r.transform(rando(generator)))); + ; } // Now set up the thread positions for (int i = 0; i < threads; i++) { diff --git a/test/cpp/server/BUILD b/test/cpp/server/BUILD index 3f63be2aa3..7538845803 100644 --- a/test/cpp/server/BUILD +++ b/test/cpp/server/BUILD @@ -14,7 +14,9 @@ licenses(["notice"]) # Apache v2 -load("//bazel:grpc_build_system.bzl", "grpc_cc_test", "grpc_cc_library", "grpc_cc_binary") +load("//bazel:grpc_build_system.bzl", "grpc_cc_test", "grpc_cc_library", "grpc_cc_binary", "grpc_package") + +grpc_package(name = "test/cpp/server") grpc_cc_test( name = "server_builder_test", diff --git a/test/cpp/util/BUILD b/test/cpp/util/BUILD index fbdec05698..2559c18c32 100644 --- a/test/cpp/util/BUILD +++ b/test/cpp/util/BUILD @@ -14,15 +14,9 @@ licenses(["notice"]) # Apache v2 -load("//bazel:grpc_build_system.bzl", "grpc_cc_library", "grpc_cc_binary", "grpc_cc_test") +load("//bazel:grpc_build_system.bzl", "grpc_cc_library", "grpc_cc_binary", "grpc_cc_test", "grpc_package") -package( - default_visibility = ["//visibility:public"], - features = [ - "-layering_check", - "-parse_headers", - ], -) +grpc_package(name = "test/cpp/util", visibility = "public") grpc_cc_library( name = "test_config", |