diff options
author | ncteisen <ncteisen@gmail.com> | 2017-05-18 19:01:53 -0700 |
---|---|---|
committer | ncteisen <ncteisen@gmail.com> | 2017-05-18 19:01:53 -0700 |
commit | df8c3eec39f05c84d9504467b2dccd55738523be (patch) | |
tree | fad1ea316ba39eb2051bed9167d21f7bb608e9bb /test/cpp | |
parent | d21040bf1ef56a96808eebe4961039e726fbc80c (diff) | |
parent | 9ea6d79474a2cc842b9a7a927dfc2b30d8373ae3 (diff) |
Merge branch 'master' of https://github.com/grpc/grpc into more-bm-diff
Diffstat (limited to 'test/cpp')
36 files changed, 584 insertions, 173 deletions
diff --git a/test/cpp/codegen/BUILD b/test/cpp/codegen/BUILD index 43d133fc34..f974e63eb4 100644 --- a/test/cpp/codegen/BUILD +++ b/test/cpp/codegen/BUILD @@ -29,37 +29,45 @@ licenses(["notice"]) # 3-clause BSD -cc_test( +load("//bazel:grpc_build_system.bzl", "grpc_cc_test") + +grpc_cc_test( name = "codegen_test_full", srcs = ["codegen_test_full.cc"], deps = [ "//:grpc++", - "//external:gtest", "//test/core/util:gpr_test_util", ], + external_deps = [ + "gtest", + ], ) -cc_test( +grpc_cc_test( name = "codegen_test_minimal", srcs = ["codegen_test_minimal.cc"], deps = [ "//:grpc++", - "//external:gtest", "//test/core/util:gpr_test_util", ], + external_deps = [ + "gtest", + ], ) -cc_test( +grpc_cc_test( name = "proto_utils_test", srcs = ["proto_utils_test.cc"], deps = [ "//:grpc++", - "//external:gtest", "//test/core/util:gpr_test_util", ], + external_deps = [ + "gtest", + ], ) -cc_test( +grpc_cc_test( name = "golden_file_test", srcs = ["golden_file_test.cc"], args = ["--generated_file_path=$(GENDIR)/src/proto/grpc/testing/"], @@ -69,9 +77,11 @@ cc_test( ], deps = [ "//:grpc++", - "//external:gflags", - "//external:gtest", "//src/proto/grpc/testing:compiler_test_proto", "//test/core/util:gpr_test_util", ], + external_deps = [ + "gtest", + "gflags", + ], ) diff --git a/test/cpp/common/BUILD b/test/cpp/common/BUILD index 48ad583981..c8b3e46f5f 100644 --- a/test/cpp/common/BUILD +++ b/test/cpp/common/BUILD @@ -29,32 +29,66 @@ licenses(["notice"]) # 3-clause BSD -cc_test( +load("//bazel:grpc_build_system.bzl", "grpc_cc_test") + +grpc_cc_test( name = "alarm_cpp_test", srcs = ["alarm_cpp_test.cc"], - deps = ["//:grpc++", "//external:gtest", "//test/core/util:gpr_test_util"], + deps = [ + "//:grpc++", + "//test/core/util:gpr_test_util", + ], + external_deps = [ + "gtest", + ], ) -cc_test( +grpc_cc_test( name = "auth_property_iterator_test", srcs = ["auth_property_iterator_test.cc"], - deps = ["//:grpc++", "//external:gtest", "//test/core/util:gpr_test_util", "//test/cpp/util:test_util"], + deps = [ + "//:grpc++", + "//test/core/util:gpr_test_util", + "//test/cpp/util:test_util", + ], + external_deps = [ + "gtest", + ], ) -cc_test( +grpc_cc_test( name = "channel_arguments_test", srcs = ["channel_arguments_test.cc"], - deps = ["//:grpc++", "//external:gtest", "//test/core/util:gpr_test_util"], + deps = [ + "//:grpc++", + "//test/core/util:gpr_test_util", + ], + external_deps = [ + "gtest", + ], ) -cc_test( +grpc_cc_test( name = "channel_filter_test", srcs = ["channel_filter_test.cc"], - deps = ["//:grpc++", "//external:gtest", "//test/core/util:gpr_test_util"], + deps = [ + "//:grpc++", + "//test/core/util:gpr_test_util", + ], + external_deps = [ + "gtest", + ], ) -cc_test( +grpc_cc_test( name = "secure_auth_context_test", srcs = ["secure_auth_context_test.cc"], - deps = ["//:grpc++", "//external:gtest", "//test/core/util:gpr_test_util", "//test/cpp/util:test_util"], + deps = [ + "//:grpc++", + "//test/core/util:gpr_test_util", + "//test/cpp/util:test_util", + ], + external_deps = [ + "gtest", + ], ) diff --git a/test/cpp/end2end/BUILD b/test/cpp/end2end/BUILD index e867493fb9..9b691a83e0 100644 --- a/test/cpp/end2end/BUILD +++ b/test/cpp/end2end/BUILD @@ -29,25 +29,30 @@ licenses(["notice"]) # 3-clause BSD -cc_library( +load("//bazel:grpc_build_system.bzl", "grpc_cc_library", "grpc_cc_test") + +package(default_visibility=["//visibility:public"]) # Allows external users to implement end2end tests. + +grpc_cc_library( name = "test_service_impl", srcs = ["test_service_impl.cc"], hdrs = ["test_service_impl.h"], deps = [ - "//external:gtest", "//src/proto/grpc/testing:echo_proto", "//test/cpp/util:test_util", ], + external_deps = [ + "gtest", + ], ) -cc_test( +grpc_cc_test( name = "async_end2end_test", srcs = ["async_end2end_test.cc"], deps = [ "//:gpr", "//:grpc", "//:grpc++", - "//external:gtest", "//src/proto/grpc/health/v1:health_proto", "//src/proto/grpc/testing:echo_messages_proto", "//src/proto/grpc/testing:echo_proto", @@ -56,16 +61,18 @@ cc_test( "//test/core/util:grpc_test_util", "//test/cpp/util:test_util", ], + external_deps = [ + "gtest", + ], ) -cc_test( +grpc_cc_test( name = "client_crash_test", srcs = ["client_crash_test.cc"], deps = [ "//:gpr", "//:grpc", "//:grpc++", - "//external:gtest", "//src/proto/grpc/testing:echo_messages_proto", "//src/proto/grpc/testing:echo_proto", "//src/proto/grpc/testing/duplicate:echo_duplicate_proto", @@ -73,17 +80,18 @@ cc_test( "//test/core/util:grpc_test_util", "//test/cpp/util:test_util", ], + external_deps = [ + "gtest", + ], ) -cc_test( +grpc_cc_test( name = "client_crash_test_server", srcs = ["client_crash_test_server.cc"], deps = [ "//:gpr", "//:grpc", "//:grpc++", - "//external:gflags", - "//external:gtest", "//src/proto/grpc/testing:echo_messages_proto", "//src/proto/grpc/testing:echo_proto", "//src/proto/grpc/testing/duplicate:echo_duplicate_proto", @@ -91,17 +99,21 @@ cc_test( "//test/core/util:grpc_test_util", "//test/cpp/util:test_util", ], + external_deps = [ + "gflags", + "gtest", + ], ) -cc_test( - name = "end2end_test", +grpc_cc_library( + name = "end2end_test_lib", srcs = ["end2end_test.cc"], + testonly = True, deps = [ ":test_service_impl", "//:gpr", "//:grpc", "//:grpc++", - "//external:gtest", "//src/proto/grpc/testing:echo_messages_proto", "//src/proto/grpc/testing:echo_proto", "//src/proto/grpc/testing/duplicate:echo_duplicate_proto", @@ -109,16 +121,25 @@ cc_test( "//test/core/util:grpc_test_util", "//test/cpp/util:test_util", ], + external_deps = [ + "gtest", + ], ) -cc_test( +grpc_cc_test( + name = "end2end_test", + deps = [ + ":end2end_test_lib" + ], +) + +grpc_cc_test( name = "filter_end2end_test", srcs = ["filter_end2end_test.cc"], deps = [ "//:gpr", "//:grpc", "//:grpc++", - "//external:gtest", "//src/proto/grpc/testing:echo_messages_proto", "//src/proto/grpc/testing:echo_proto", "//src/proto/grpc/testing/duplicate:echo_duplicate_proto", @@ -126,16 +147,18 @@ cc_test( "//test/core/util:grpc_test_util", "//test/cpp/util:test_util", ], + external_deps = [ + "gtest", + ], ) -cc_test( +grpc_cc_test( name = "generic_end2end_test", srcs = ["generic_end2end_test.cc"], deps = [ "//:gpr", "//:grpc", "//:grpc++", - "//external:gtest", "//src/proto/grpc/testing:echo_messages_proto", "//src/proto/grpc/testing:echo_proto", "//src/proto/grpc/testing/duplicate:echo_duplicate_proto", @@ -143,9 +166,12 @@ cc_test( "//test/core/util:grpc_test_util", "//test/cpp/util:test_util", ], + external_deps = [ + "gtest", + ], ) -cc_test( +grpc_cc_test( name = "hybrid_end2end_test", srcs = ["hybrid_end2end_test.cc"], deps = [ @@ -153,7 +179,6 @@ cc_test( "//:gpr", "//:grpc", "//:grpc++", - "//external:gtest", "//src/proto/grpc/testing:echo_messages_proto", "//src/proto/grpc/testing:echo_proto", "//src/proto/grpc/testing/duplicate:echo_duplicate_proto", @@ -161,16 +186,19 @@ cc_test( "//test/core/util:grpc_test_util", "//test/cpp/util:test_util", ], + external_deps = [ + "gtest", + ], ) -cc_test( +grpc_cc_test( name = "mock_test", srcs = ["mock_test.cc"], deps = [ "//:gpr", "//:grpc", "//:grpc++", - "//external:gtest", + "//:grpc++_test", "//src/proto/grpc/testing:echo_messages_proto", "//src/proto/grpc/testing:echo_proto", "//src/proto/grpc/testing/duplicate:echo_duplicate_proto", @@ -178,9 +206,12 @@ cc_test( "//test/core/util:grpc_test_util", "//test/cpp/util:test_util", ], + external_deps = [ + "gtest", + ], ) -cc_test( +grpc_cc_test( name = "round_robin_end2end_test", srcs = ["round_robin_end2end_test.cc"], deps = [ @@ -188,7 +219,6 @@ cc_test( "//:gpr", "//:grpc", "//:grpc++", - "//external:gtest", "//src/proto/grpc/testing:echo_messages_proto", "//src/proto/grpc/testing:echo_proto", "//src/proto/grpc/testing/duplicate:echo_duplicate_proto", @@ -196,10 +226,12 @@ cc_test( "//test/core/util:grpc_test_util", "//test/cpp/util:test_util", ], + external_deps = [ + "gtest", + ], ) - -cc_test( +grpc_cc_test( name = "grpclb_end2end_test", srcs = ["grpclb_end2end_test.cc"], deps = [ @@ -207,7 +239,6 @@ cc_test( "//:gpr", "//:grpc", "//:grpc++", - "//external:gtest", "//src/proto/grpc/lb/v1:load_balancer_proto", "//src/proto/grpc/testing:echo_messages_proto", "//src/proto/grpc/testing:echo_proto", @@ -217,9 +248,12 @@ cc_test( "//test/core/util:grpc_test_util", "//test/cpp/util:test_util", ], + external_deps = [ + "gtest", + ], ) -cc_test( +grpc_cc_test( name = "proto_server_reflection_test", srcs = ["proto_server_reflection_test.cc"], deps = [ @@ -228,8 +262,6 @@ cc_test( "//:grpc", "//:grpc++", "//:grpc++_reflection", - "//external:gflags", - "//external:gtest", "//src/proto/grpc/testing:echo_messages_proto", "//src/proto/grpc/testing:echo_proto", "//src/proto/grpc/testing/duplicate:echo_duplicate_proto", @@ -238,9 +270,13 @@ cc_test( "//test/cpp/util:grpc++_proto_reflection_desc_db", "//test/cpp/util:test_util", ], + external_deps = [ + "gtest", + "gflags", + ], ) -cc_test( +grpc_cc_test( name = "server_builder_plugin_test", srcs = ["server_builder_plugin_test.cc"], deps = [ @@ -248,7 +284,6 @@ cc_test( "//:gpr", "//:grpc", "//:grpc++", - "//external:gtest", "//src/proto/grpc/testing:echo_messages_proto", "//src/proto/grpc/testing:echo_proto", "//src/proto/grpc/testing/duplicate:echo_duplicate_proto", @@ -256,16 +291,18 @@ cc_test( "//test/core/util:grpc_test_util", "//test/cpp/util:test_util", ], + external_deps = [ + "gtest", + ], ) -cc_test( +grpc_cc_test( name = "server_crash_test", srcs = ["server_crash_test.cc"], deps = [ "//:gpr", "//:grpc", "//:grpc++", - "//external:gtest", "//src/proto/grpc/testing:echo_messages_proto", "//src/proto/grpc/testing:echo_proto", "//src/proto/grpc/testing/duplicate:echo_duplicate_proto", @@ -273,17 +310,18 @@ cc_test( "//test/core/util:grpc_test_util", "//test/cpp/util:test_util", ], + external_deps = [ + "gtest", + ], ) -cc_test( +grpc_cc_test( name = "server_crash_test_client", srcs = ["server_crash_test_client.cc"], deps = [ "//:gpr", "//:grpc", "//:grpc++", - "//external:gflags", - "//external:gtest", "//src/proto/grpc/testing:echo_messages_proto", "//src/proto/grpc/testing:echo_proto", "//src/proto/grpc/testing/duplicate:echo_duplicate_proto", @@ -291,16 +329,19 @@ cc_test( "//test/core/util:grpc_test_util", "//test/cpp/util:test_util", ], + external_deps = [ + "gflags", + "gtest", + ], ) -cc_test( +grpc_cc_test( name = "shutdown_test", srcs = ["shutdown_test.cc"], deps = [ "//:gpr", "//:grpc", "//:grpc++", - "//external:gtest", "//src/proto/grpc/testing:echo_messages_proto", "//src/proto/grpc/testing:echo_proto", "//src/proto/grpc/testing/duplicate:echo_duplicate_proto", @@ -308,16 +349,18 @@ cc_test( "//test/core/util:grpc_test_util", "//test/cpp/util:test_util", ], + external_deps = [ + "gtest", + ], ) -cc_test( +grpc_cc_test( name = "streaming_throughput_test", srcs = ["streaming_throughput_test.cc"], deps = [ "//:gpr", "//:grpc", "//:grpc++", - "//external:gtest", "//src/proto/grpc/testing:echo_messages_proto", "//src/proto/grpc/testing:echo_proto", "//src/proto/grpc/testing/duplicate:echo_duplicate_proto", @@ -325,16 +368,18 @@ cc_test( "//test/core/util:grpc_test_util", "//test/cpp/util:test_util", ], + external_deps = [ + "gtest", + ], ) -cc_test( +grpc_cc_test( name = "thread_stress_test", srcs = ["thread_stress_test.cc"], deps = [ "//:gpr", "//:grpc", "//:grpc++", - "//external:gtest", "//src/proto/grpc/testing:echo_messages_proto", "//src/proto/grpc/testing:echo_proto", "//src/proto/grpc/testing/duplicate:echo_duplicate_proto", @@ -342,4 +387,7 @@ cc_test( "//test/core/util:grpc_test_util", "//test/cpp/util:test_util", ], + external_deps = [ + "gtest", + ], ) diff --git a/test/cpp/end2end/async_end2end_test.cc b/test/cpp/end2end/async_end2end_test.cc index cc3958bf13..8d59cbb7e0 100644 --- a/test/cpp/end2end/async_end2end_test.cc +++ b/test/cpp/end2end/async_end2end_test.cc @@ -47,7 +47,6 @@ #include <grpc/support/thd.h> #include <grpc/support/time.h> #include <grpc/support/tls.h> -#include <gtest/gtest.h> #include "src/core/lib/iomgr/port.h" #include "src/proto/grpc/health/v1/health.grpc.pb.h" @@ -58,6 +57,8 @@ #include "test/cpp/util/string_ref_helper.h" #include "test/cpp/util/test_credentials_provider.h" +#include <gtest/gtest.h> + #ifdef GRPC_POSIX_SOCKET #include "src/core/lib/iomgr/ev_posix.h" #endif diff --git a/test/cpp/end2end/client_crash_test.cc b/test/cpp/end2end/client_crash_test.cc index 966c04b0e3..0ea520925f 100644 --- a/test/cpp/end2end/client_crash_test.cc +++ b/test/cpp/end2end/client_crash_test.cc @@ -41,7 +41,6 @@ #include <grpc/support/log.h> #include <grpc/support/thd.h> #include <grpc/support/time.h> -#include <gtest/gtest.h> #include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h" #include "src/proto/grpc/testing/echo.grpc.pb.h" @@ -49,6 +48,8 @@ #include "test/core/util/test_config.h" #include "test/cpp/util/subprocess.h" +#include <gtest/gtest.h> + using grpc::testing::EchoRequest; using grpc::testing::EchoResponse; using std::chrono::system_clock; diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc index df71777e4b..9a9e81853f 100644 --- a/test/cpp/end2end/end2end_test.cc +++ b/test/cpp/end2end/end2end_test.cc @@ -48,7 +48,6 @@ #include <grpc/support/log.h> #include <grpc/support/thd.h> #include <grpc/support/time.h> -#include <gtest/gtest.h> #include "src/core/lib/security/credentials/credentials.h" #include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h" @@ -59,6 +58,8 @@ #include "test/cpp/util/string_ref_helper.h" #include "test/cpp/util/test_credentials_provider.h" +#include <gtest/gtest.h> + using grpc::testing::EchoRequest; using grpc::testing::EchoResponse; using grpc::testing::kTlsCredentialsType; diff --git a/test/cpp/end2end/filter_end2end_test.cc b/test/cpp/end2end/filter_end2end_test.cc index 2f873eeaa8..5589e2fddc 100644 --- a/test/cpp/end2end/filter_end2end_test.cc +++ b/test/cpp/end2end/filter_end2end_test.cc @@ -48,7 +48,6 @@ #include <grpc/grpc.h> #include <grpc/support/thd.h> #include <grpc/support/time.h> -#include <gtest/gtest.h> #include "src/cpp/common/channel_filter.h" #include "src/proto/grpc/testing/echo.grpc.pb.h" @@ -56,6 +55,8 @@ #include "test/core/util/test_config.h" #include "test/cpp/util/byte_buffer_proto_helper.h" +#include <gtest/gtest.h> + using grpc::testing::EchoRequest; using grpc::testing::EchoResponse; using std::chrono::system_clock; diff --git a/test/cpp/end2end/generic_end2end_test.cc b/test/cpp/end2end/generic_end2end_test.cc index 25c221bb2b..281c58efad 100644 --- a/test/cpp/end2end/generic_end2end_test.cc +++ b/test/cpp/end2end/generic_end2end_test.cc @@ -46,13 +46,14 @@ #include <grpc/grpc.h> #include <grpc/support/thd.h> #include <grpc/support/time.h> -#include <gtest/gtest.h> #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/util/byte_buffer_proto_helper.h" +#include <gtest/gtest.h> + using grpc::testing::EchoRequest; using grpc::testing::EchoResponse; using std::chrono::system_clock; @@ -115,6 +116,10 @@ class GenericEnd2endTest : public ::testing::Test { void client_fail(int i) { verify_ok(&cli_cq_, i, false); } void SendRpc(int num_rpcs) { + SendRpc(num_rpcs, false, gpr_inf_future(GPR_CLOCK_MONOTONIC)); + } + + void SendRpc(int num_rpcs, bool check_deadline, gpr_timespec deadline) { const grpc::string kMethodName("/grpc.cpp.test.util.EchoTestService/Echo"); for (int i = 0; i < num_rpcs; i++) { EchoRequest send_request; @@ -129,6 +134,11 @@ class GenericEnd2endTest : public ::testing::Test { // The string needs to be long enough to test heap-based slice. send_request.set_message("Hello world. Hello world. Hello world."); + + if (check_deadline) { + cli_ctx.set_deadline(deadline); + } + std::unique_ptr<GenericClientAsyncReaderWriter> call = generic_stub_->Call(&cli_ctx, kMethodName, &cli_cq_, tag(1)); client_ok(1); @@ -147,6 +157,12 @@ class GenericEnd2endTest : public ::testing::Test { verify_ok(srv_cq_.get(), 4, true); EXPECT_EQ(server_host_, srv_ctx.host().substr(0, server_host_.length())); EXPECT_EQ(kMethodName, srv_ctx.method()); + + if (check_deadline) { + EXPECT_TRUE(gpr_time_similar(deadline, srv_ctx.raw_deadline(), + gpr_time_from_millis(100, GPR_TIMESPAN))); + } + ByteBuffer recv_buffer; stream.Read(&recv_buffer, tag(5)); server_ok(5); @@ -262,6 +278,12 @@ TEST_F(GenericEnd2endTest, SimpleBidiStreaming) { EXPECT_TRUE(recv_status.ok()); } +TEST_F(GenericEnd2endTest, Deadline) { + ResetStub(); + SendRpc(1, true, gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), + gpr_time_from_seconds(10, GPR_TIMESPAN))); +} + } // namespace } // namespace testing } // namespace grpc diff --git a/test/cpp/end2end/grpclb_end2end_test.cc b/test/cpp/end2end/grpclb_end2end_test.cc index 8417f1a99c..4e1bcc7a60 100644 --- a/test/cpp/end2end/grpclb_end2end_test.cc +++ b/test/cpp/end2end/grpclb_end2end_test.cc @@ -98,12 +98,12 @@ namespace { template <typename ServiceType> class CountedService : public ServiceType { public: - int request_count() { + size_t request_count() { std::unique_lock<std::mutex> lock(mu_); return request_count_; } - int response_count() { + size_t response_count() { std::unique_lock<std::mutex> lock(mu_); return response_count_; } @@ -121,8 +121,8 @@ class CountedService : public ServiceType { std::mutex mu_; private: - int request_count_ = 0; - int response_count_ = 0; + size_t request_count_ = 0; + size_t response_count_ = 0; }; using BackendService = CountedService<TestServiceImpl>; @@ -243,9 +243,18 @@ class BalancerServiceImpl : public BalancerService { } static LoadBalanceResponse BuildResponseForBackends( - const std::vector<int>& backend_ports) { + const std::vector<int>& backend_ports, int num_drops_for_rate_limiting, + int num_drops_for_load_balancing) { LoadBalanceResponse response; - for (const int backend_port : backend_ports) { + for (int i = 0; i < num_drops_for_rate_limiting; ++i) { + auto* server = response.mutable_server_list()->add_servers(); + server->set_drop_for_rate_limiting(true); + } + for (int i = 0; i < num_drops_for_load_balancing; ++i) { + auto* server = response.mutable_server_list()->add_servers(); + server->set_drop_for_load_balancing(true); + } + for (const int& backend_port : backend_ports) { auto* server = response.mutable_server_list()->add_servers(); server->set_ip_address(Ip4ToPackedString("127.0.0.1")); server->set_port(backend_port); @@ -327,10 +336,8 @@ class GrpclbEnd2endTest : public ::testing::Test { ChannelArguments args; args.SetPointer(GRPC_ARG_FAKE_RESOLVER_RESPONSE_GENERATOR, response_generator_); - std::ostringstream uri; - uri << "test:///servername_not_used"; - channel_ = - CreateCustomChannel(uri.str(), InsecureChannelCredentials(), args); + channel_ = CreateCustomChannel("test:///not_used", + InsecureChannelCredentials(), args); stub_ = grpc::testing::EchoTestService::NewStub(channel_); } @@ -467,26 +474,33 @@ class SingleBalancerTest : public GrpclbEnd2endTest { }; TEST_F(SingleBalancerTest, Vanilla) { + const size_t kNumRpcsPerAddress = 100; ScheduleResponseForBalancer( - 0, BalancerServiceImpl::BuildResponseForBackends(GetBackendPorts()), 0); + 0, BalancerServiceImpl::BuildResponseForBackends(GetBackendPorts(), 0, 0), + 0); // Make sure that trying to connect works without a call. channel_->GetState(true /* try_to_connect */); - // Start servers and send 100 RPCs per server. - const auto& statuses_and_responses = SendRpc(kMessage_, 100 * num_backends_); + // Send 100 RPCs per server. + const auto& statuses_and_responses = + SendRpc(kMessage_, kNumRpcsPerAddress * num_backends_); for (const auto& status_and_response : statuses_and_responses) { - EXPECT_TRUE(status_and_response.first.ok()); - EXPECT_EQ(status_and_response.second.message(), kMessage_); + const Status& status = status_and_response.first; + const EchoResponse& response = status_and_response.second; + EXPECT_TRUE(status.ok()) << "code=" << status.error_code() + << " message=" << status.error_message(); + EXPECT_EQ(response.message(), kMessage_); } // Each backend should have gotten 100 requests. for (size_t i = 0; i < backends_.size(); ++i) { - EXPECT_EQ(100, backend_servers_[i].service_->request_count()); + EXPECT_EQ(kNumRpcsPerAddress, + backend_servers_[i].service_->request_count()); } // The balancer got a single request. - EXPECT_EQ(1, balancer_servers_[0].service_->request_count()); + EXPECT_EQ(1U, balancer_servers_[0].service_->request_count()); // and sent a single response. - EXPECT_EQ(1, balancer_servers_[0].service_->response_count()); + EXPECT_EQ(1U, balancer_servers_[0].service_->response_count()); // Check LB policy name for the channel. EXPECT_EQ("grpclb", channel_->GetLoadBalancingPolicyName()); @@ -500,7 +514,7 @@ TEST_F(SingleBalancerTest, InitiallyEmptyServerlist) { ScheduleResponseForBalancer(0, LoadBalanceResponse(), 0); // Send non-empty serverlist only after kServerlistDelayMs ScheduleResponseForBalancer( - 0, BalancerServiceImpl::BuildResponseForBackends(GetBackendPorts()), + 0, BalancerServiceImpl::BuildResponseForBackends(GetBackendPorts(), 0, 0), kServerlistDelayMs); const auto t0 = system_clock::now(); @@ -518,17 +532,20 @@ TEST_F(SingleBalancerTest, InitiallyEmptyServerlist) { // Each backend should have gotten 1 request. for (size_t i = 0; i < backends_.size(); ++i) { - EXPECT_EQ(1, backend_servers_[i].service_->request_count()); + EXPECT_EQ(1U, backend_servers_[i].service_->request_count()); } for (const auto& status_and_response : statuses_and_responses) { - EXPECT_TRUE(status_and_response.first.ok()); - EXPECT_EQ(status_and_response.second.message(), kMessage_); + const Status& status = status_and_response.first; + const EchoResponse& response = status_and_response.second; + EXPECT_TRUE(status.ok()) << "code=" << status.error_code() + << " message=" << status.error_message(); + EXPECT_EQ(response.message(), kMessage_); } // The balancer got a single request. - EXPECT_EQ(1, balancer_servers_[0].service_->request_count()); + EXPECT_EQ(1U, balancer_servers_[0].service_->request_count()); // and sent two responses. - EXPECT_EQ(2, balancer_servers_[0].service_->response_count()); + EXPECT_EQ(2U, balancer_servers_[0].service_->response_count()); // Check LB policy name for the channel. EXPECT_EQ("grpclb", channel_->GetLoadBalancingPolicyName()); @@ -539,10 +556,11 @@ TEST_F(SingleBalancerTest, RepeatedServerlist) { // Send a serverlist right away. ScheduleResponseForBalancer( - 0, BalancerServiceImpl::BuildResponseForBackends(GetBackendPorts()), 0); + 0, BalancerServiceImpl::BuildResponseForBackends(GetBackendPorts(), 0, 0), + 0); // ... and the same one a bit later. ScheduleResponseForBalancer( - 0, BalancerServiceImpl::BuildResponseForBackends(GetBackendPorts()), + 0, BalancerServiceImpl::BuildResponseForBackends(GetBackendPorts(), 0, 0), kServerlistDelayMs); // Send num_backends/2 requests. @@ -550,14 +568,17 @@ TEST_F(SingleBalancerTest, RepeatedServerlist) { // only the first half of the backends will receive them. for (size_t i = 0; i < backends_.size(); ++i) { if (i < backends_.size() / 2) - EXPECT_EQ(1, backend_servers_[i].service_->request_count()); + EXPECT_EQ(1U, backend_servers_[i].service_->request_count()); else - EXPECT_EQ(0, backend_servers_[i].service_->request_count()); + EXPECT_EQ(0U, backend_servers_[i].service_->request_count()); } EXPECT_EQ(statuses_and_responses.size(), num_backends_ / 2); for (const auto& status_and_response : statuses_and_responses) { - EXPECT_TRUE(status_and_response.first.ok()); - EXPECT_EQ(status_and_response.second.message(), kMessage_); + const Status& status = status_and_response.first; + const EchoResponse& response = status_and_response.second; + EXPECT_TRUE(status.ok()) << "code=" << status.error_code() + << " message=" << status.error_message(); + EXPECT_EQ(response.message(), kMessage_); } // Wait for the (duplicated) serverlist update. @@ -566,7 +587,7 @@ TEST_F(SingleBalancerTest, RepeatedServerlist) { gpr_time_from_millis(kServerlistDelayMs * 1.1, GPR_TIMESPAN))); // Verify the LB has sent two responses. - EXPECT_EQ(2, balancer_servers_[0].service_->response_count()); + EXPECT_EQ(2U, balancer_servers_[0].service_->response_count()); // Some more calls to complete the total number of backends. statuses_and_responses = SendRpc( @@ -575,52 +596,146 @@ TEST_F(SingleBalancerTest, RepeatedServerlist) { // Because a duplicated serverlist should have no effect, all backends must // have been hit once now. for (size_t i = 0; i < backends_.size(); ++i) { - EXPECT_EQ(1, backend_servers_[i].service_->request_count()); + EXPECT_EQ(1U, backend_servers_[i].service_->request_count()); } EXPECT_EQ(statuses_and_responses.size(), num_backends_ / 2); for (const auto& status_and_response : statuses_and_responses) { - EXPECT_TRUE(status_and_response.first.ok()); - EXPECT_EQ(status_and_response.second.message(), kMessage_); + const Status& status = status_and_response.first; + const EchoResponse& response = status_and_response.second; + EXPECT_TRUE(status.ok()) << "code=" << status.error_code() + << " message=" << status.error_message(); + EXPECT_EQ(response.message(), kMessage_); } // The balancer got a single request. - EXPECT_EQ(1, balancer_servers_[0].service_->request_count()); + EXPECT_EQ(1U, balancer_servers_[0].service_->request_count()); // Check LB policy name for the channel. EXPECT_EQ("grpclb", channel_->GetLoadBalancingPolicyName()); } +TEST_F(SingleBalancerTest, Drop) { + const size_t kNumRpcsPerAddress = 100; + ScheduleResponseForBalancer( + 0, BalancerServiceImpl::BuildResponseForBackends(GetBackendPorts(), 1, 2), + 0); + // Send 100 RPCs for each server and drop address. + const auto& statuses_and_responses = + SendRpc(kMessage_, kNumRpcsPerAddress * (num_backends_ + 3)); + + size_t num_drops = 0; + for (const auto& status_and_response : statuses_and_responses) { + const Status& status = status_and_response.first; + const EchoResponse& response = status_and_response.second; + if (!status.ok() && + status.error_message() == "Call dropped by load balancing policy") { + ++num_drops; + } else { + EXPECT_TRUE(status.ok()) << "code=" << status.error_code() + << " message=" << status.error_message(); + EXPECT_EQ(response.message(), kMessage_); + } + } + EXPECT_EQ(kNumRpcsPerAddress * 3, num_drops); + + // Each backend should have gotten 100 requests. + for (size_t i = 0; i < backends_.size(); ++i) { + EXPECT_EQ(kNumRpcsPerAddress, + backend_servers_[i].service_->request_count()); + } + // The balancer got a single request. + EXPECT_EQ(1U, balancer_servers_[0].service_->request_count()); + // and sent a single response. + EXPECT_EQ(1U, balancer_servers_[0].service_->response_count()); +} + class SingleBalancerWithClientLoadReportingTest : public GrpclbEnd2endTest { public: SingleBalancerWithClientLoadReportingTest() : GrpclbEnd2endTest(4, 1, 2) {} }; TEST_F(SingleBalancerWithClientLoadReportingTest, Vanilla) { + const size_t kNumRpcsPerAddress = 100; ScheduleResponseForBalancer( - 0, BalancerServiceImpl::BuildResponseForBackends(GetBackendPorts()), 0); - // Start servers and send 100 RPCs per server. - const auto& statuses_and_responses = SendRpc(kMessage_, 100 * num_backends_); + 0, BalancerServiceImpl::BuildResponseForBackends(GetBackendPorts(), 0, 0), + 0); + // Send 100 RPCs per server. + const auto& statuses_and_responses = + SendRpc(kMessage_, kNumRpcsPerAddress * num_backends_); for (const auto& status_and_response : statuses_and_responses) { - EXPECT_TRUE(status_and_response.first.ok()); - EXPECT_EQ(status_and_response.second.message(), kMessage_); + const Status& status = status_and_response.first; + const EchoResponse& response = status_and_response.second; + EXPECT_TRUE(status.ok()) << "code=" << status.error_code() + << " message=" << status.error_message(); + EXPECT_EQ(response.message(), kMessage_); } // Each backend should have gotten 100 requests. for (size_t i = 0; i < backends_.size(); ++i) { - EXPECT_EQ(100, backend_servers_[i].service_->request_count()); + EXPECT_EQ(kNumRpcsPerAddress, + backend_servers_[i].service_->request_count()); } // The balancer got a single request. - EXPECT_EQ(1, balancer_servers_[0].service_->request_count()); + EXPECT_EQ(1U, balancer_servers_[0].service_->request_count()); // and sent a single response. - EXPECT_EQ(1, balancer_servers_[0].service_->response_count()); + EXPECT_EQ(1U, balancer_servers_[0].service_->response_count()); const ClientStats client_stats = WaitForLoadReports(); - EXPECT_EQ(100 * num_backends_, client_stats.num_calls_started); - EXPECT_EQ(100 * num_backends_, client_stats.num_calls_finished); + EXPECT_EQ(kNumRpcsPerAddress * num_backends_, client_stats.num_calls_started); + EXPECT_EQ(kNumRpcsPerAddress * num_backends_, + client_stats.num_calls_finished); EXPECT_EQ(0U, client_stats.num_calls_finished_with_drop_for_rate_limiting); EXPECT_EQ(0U, client_stats.num_calls_finished_with_drop_for_load_balancing); EXPECT_EQ(0U, client_stats.num_calls_finished_with_client_failed_to_send); - EXPECT_EQ(100 * num_backends_, + EXPECT_EQ(kNumRpcsPerAddress * num_backends_, + client_stats.num_calls_finished_known_received); +} + +TEST_F(SingleBalancerWithClientLoadReportingTest, Drop) { + const size_t kNumRpcsPerAddress = 3; + ScheduleResponseForBalancer( + 0, BalancerServiceImpl::BuildResponseForBackends(GetBackendPorts(), 2, 1), + 0); + // Send 100 RPCs for each server and drop address. + const auto& statuses_and_responses = + SendRpc(kMessage_, kNumRpcsPerAddress * (num_backends_ + 3)); + + size_t num_drops = 0; + for (const auto& status_and_response : statuses_and_responses) { + const Status& status = status_and_response.first; + const EchoResponse& response = status_and_response.second; + if (!status.ok() && + status.error_message() == "Call dropped by load balancing policy") { + ++num_drops; + } else { + EXPECT_TRUE(status.ok()) << "code=" << status.error_code() + << " message=" << status.error_message(); + EXPECT_EQ(response.message(), kMessage_); + } + } + EXPECT_EQ(kNumRpcsPerAddress * 3, num_drops); + + // Each backend should have gotten 100 requests. + for (size_t i = 0; i < backends_.size(); ++i) { + EXPECT_EQ(kNumRpcsPerAddress, + backend_servers_[i].service_->request_count()); + } + // The balancer got a single request. + EXPECT_EQ(1U, balancer_servers_[0].service_->request_count()); + // and sent a single response. + EXPECT_EQ(1U, balancer_servers_[0].service_->response_count()); + + const ClientStats client_stats = WaitForLoadReports(); + EXPECT_EQ(kNumRpcsPerAddress * (num_backends_ + 3), + client_stats.num_calls_started); + EXPECT_EQ(kNumRpcsPerAddress * (num_backends_ + 3), + client_stats.num_calls_finished); + EXPECT_EQ(kNumRpcsPerAddress * 2, + client_stats.num_calls_finished_with_drop_for_rate_limiting); + EXPECT_EQ(kNumRpcsPerAddress, + client_stats.num_calls_finished_with_drop_for_load_balancing); + EXPECT_EQ(0U, client_stats.num_calls_finished_with_client_failed_to_send); + EXPECT_EQ(kNumRpcsPerAddress * num_backends_, client_stats.num_calls_finished_known_received); } diff --git a/test/cpp/end2end/health_service_end2end_test.cc b/test/cpp/end2end/health_service_end2end_test.cc index 3d51007857..c320c78697 100644 --- a/test/cpp/end2end/health_service_end2end_test.cc +++ b/test/cpp/end2end/health_service_end2end_test.cc @@ -46,7 +46,6 @@ #include <grpc++/server_context.h> #include <grpc/grpc.h> #include <grpc/support/log.h> -#include <gtest/gtest.h> #include "src/proto/grpc/health/v1/health.grpc.pb.h" #include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h" @@ -55,6 +54,8 @@ #include "test/core/util/test_config.h" #include "test/cpp/end2end/test_service_impl.h" +#include <gtest/gtest.h> + using grpc::health::v1::Health; using grpc::health::v1::HealthCheckRequest; using grpc::health::v1::HealthCheckResponse; diff --git a/test/cpp/end2end/hybrid_end2end_test.cc b/test/cpp/end2end/hybrid_end2end_test.cc index a4ba76fed1..1cd515a23b 100644 --- a/test/cpp/end2end/hybrid_end2end_test.cc +++ b/test/cpp/end2end/hybrid_end2end_test.cc @@ -42,7 +42,6 @@ #include <grpc++/server_builder.h> #include <grpc++/server_context.h> #include <grpc/grpc.h> -#include <gtest/gtest.h> #include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h" #include "src/proto/grpc/testing/echo.grpc.pb.h" @@ -51,6 +50,8 @@ #include "test/cpp/end2end/test_service_impl.h" #include "test/cpp/util/byte_buffer_proto_helper.h" +#include <gtest/gtest.h> + namespace grpc { namespace testing { diff --git a/test/cpp/end2end/mock_test.cc b/test/cpp/end2end/mock_test.cc index 7e330063ed..3a82b3a5d6 100644 --- a/test/cpp/end2end/mock_test.cc +++ b/test/cpp/end2end/mock_test.cc @@ -45,7 +45,6 @@ #include <grpc/support/log.h> #include <grpc/support/thd.h> #include <grpc/support/time.h> -#include <gtest/gtest.h> #include <grpc++/test/mock_stream.h> @@ -55,6 +54,8 @@ #include "test/core/util/port.h" #include "test/core/util/test_config.h" +#include <gtest/gtest.h> + #include <iostream> using namespace std; diff --git a/test/cpp/end2end/proto_server_reflection_test.cc b/test/cpp/end2end/proto_server_reflection_test.cc index 8b9688d200..25cb0d5f73 100644 --- a/test/cpp/end2end/proto_server_reflection_test.cc +++ b/test/cpp/end2end/proto_server_reflection_test.cc @@ -41,7 +41,6 @@ #include <grpc++/server_builder.h> #include <grpc++/server_context.h> #include <grpc/grpc.h> -#include <gtest/gtest.h> #include "src/proto/grpc/testing/echo.grpc.pb.h" #include "test/core/util/port.h" @@ -49,6 +48,8 @@ #include "test/cpp/end2end/test_service_impl.h" #include "test/cpp/util/proto_reflection_descriptor_database.h" +#include <gtest/gtest.h> + namespace grpc { namespace testing { diff --git a/test/cpp/end2end/round_robin_end2end_test.cc b/test/cpp/end2end/round_robin_end2end_test.cc index cc340b96b3..f8e3cc06c0 100644 --- a/test/cpp/end2end/round_robin_end2end_test.cc +++ b/test/cpp/end2end/round_robin_end2end_test.cc @@ -44,13 +44,14 @@ #include <grpc/support/log.h> #include <grpc/support/thd.h> #include <grpc/support/time.h> -#include <gtest/gtest.h> #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" +#include <gtest/gtest.h> + using grpc::testing::EchoRequest; using grpc::testing::EchoResponse; using std::chrono::system_clock; diff --git a/test/cpp/end2end/server_builder_plugin_test.cc b/test/cpp/end2end/server_builder_plugin_test.cc index 1b6f4ce37d..81b747a7af 100644 --- a/test/cpp/end2end/server_builder_plugin_test.cc +++ b/test/cpp/end2end/server_builder_plugin_test.cc @@ -45,13 +45,14 @@ #include <grpc++/server_builder.h> #include <grpc++/server_context.h> #include <grpc/grpc.h> -#include <gtest/gtest.h> #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" +#include <gtest/gtest.h> + #define PLUGIN_NAME "TestServerBuilderPlugin" namespace grpc { diff --git a/test/cpp/end2end/server_crash_test.cc b/test/cpp/end2end/server_crash_test.cc index b1f9216055..4b7041aebe 100644 --- a/test/cpp/end2end/server_crash_test.cc +++ b/test/cpp/end2end/server_crash_test.cc @@ -41,7 +41,6 @@ #include <grpc/support/log.h> #include <grpc/support/thd.h> #include <grpc/support/time.h> -#include <gtest/gtest.h> #include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h" #include "src/proto/grpc/testing/echo.grpc.pb.h" @@ -49,6 +48,8 @@ #include "test/core/util/test_config.h" #include "test/cpp/util/subprocess.h" +#include <gtest/gtest.h> + using grpc::testing::EchoRequest; using grpc::testing::EchoResponse; using std::chrono::system_clock; diff --git a/test/cpp/end2end/shutdown_test.cc b/test/cpp/end2end/shutdown_test.cc index bd68e851d3..63b397dd1c 100644 --- a/test/cpp/end2end/shutdown_test.cc +++ b/test/cpp/end2end/shutdown_test.cc @@ -33,8 +33,6 @@ #include <thread> -#include <gtest/gtest.h> - #include <grpc++/channel.h> #include <grpc++/client_context.h> #include <grpc++/create_channel.h> @@ -51,6 +49,8 @@ #include "test/core/util/test_config.h" #include "test/cpp/util/test_credentials_provider.h" +#include <gtest/gtest.h> + using grpc::testing::EchoRequest; using grpc::testing::EchoResponse; diff --git a/test/cpp/end2end/streaming_throughput_test.cc b/test/cpp/end2end/streaming_throughput_test.cc index 302583766b..ec5b83d1da 100644 --- a/test/cpp/end2end/streaming_throughput_test.cc +++ b/test/cpp/end2end/streaming_throughput_test.cc @@ -35,8 +35,6 @@ #include <mutex> #include <thread> -#include <gtest/gtest.h> - #include <grpc++/channel.h> #include <grpc++/client_context.h> #include <grpc++/create_channel.h> @@ -56,6 +54,8 @@ #include "test/core/util/port.h" #include "test/core/util/test_config.h" +#include <gtest/gtest.h> + using grpc::testing::EchoRequest; using grpc::testing::EchoResponse; using std::chrono::system_clock; diff --git a/test/cpp/end2end/test_service_impl.cc b/test/cpp/end2end/test_service_impl.cc index b473dd1f52..5411b35f16 100644 --- a/test/cpp/end2end/test_service_impl.cc +++ b/test/cpp/end2end/test_service_impl.cc @@ -40,11 +40,11 @@ #include <grpc++/server_context.h> #include <grpc/support/log.h> -#include <gtest/gtest.h> - #include "src/proto/grpc/testing/echo.grpc.pb.h" #include "test/cpp/util/string_ref_helper.h" +#include <gtest/gtest.h> + using std::chrono::system_clock; namespace grpc { diff --git a/test/cpp/end2end/thread_stress_test.cc b/test/cpp/end2end/thread_stress_test.cc index d353f9894b..defa7894ff 100644 --- a/test/cpp/end2end/thread_stress_test.cc +++ b/test/cpp/end2end/thread_stress_test.cc @@ -43,7 +43,6 @@ #include <grpc/grpc.h> #include <grpc/support/thd.h> #include <grpc/support/time.h> -#include <gtest/gtest.h> #include "src/core/lib/surface/api_trace.h" #include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h" @@ -51,6 +50,8 @@ #include "test/core/util/port.h" #include "test/core/util/test_config.h" +#include <gtest/gtest.h> + using grpc::testing::EchoRequest; using grpc::testing::EchoResponse; using std::chrono::system_clock; diff --git a/test/cpp/microbenchmarks/BUILD b/test/cpp/microbenchmarks/BUILD index 208ac6d794..3a968a020a 100644 --- a/test/cpp/microbenchmarks/BUILD +++ b/test/cpp/microbenchmarks/BUILD @@ -29,14 +29,17 @@ licenses(["notice"]) # 3-clause BSD -cc_test( +load("//bazel:grpc_build_system.bzl", "grpc_cc_test", "grpc_cc_library") + +grpc_cc_test( name = "noop-benchmark", srcs = ["noop-benchmark.cc"], - linkopts = ["-pthread"], - deps = ["//external:benchmark"], + external_deps = [ + "benchmark", + ], ) -cc_library( +grpc_cc_library( name = "helpers", srcs = ["helpers.cc"], hdrs = [ @@ -44,64 +47,68 @@ cc_library( "fullstack_fixtures.h", "helpers.h", ], - linkopts = ["-pthread"], deps = [ "//:grpc++", - "//external:benchmark", "//src/proto/grpc/testing:echo_proto", "//test/core/util:grpc_test_util", ], + external_deps = [ + "benchmark", + ], ) -cc_test( +grpc_cc_test( name = "bm_closure", srcs = ["bm_closure.cc"], deps = [":helpers"], ) -cc_test( +grpc_cc_test( name = "bm_cq", srcs = ["bm_cq.cc"], deps = [":helpers"], ) -cc_test( +grpc_cc_test( name = "bm_cq_multiple_threads", srcs = ["bm_cq_multiple_threads.cc"], deps = [":helpers"], ) -cc_test( +grpc_cc_test( name = "bm_error", srcs = ["bm_error.cc"], deps = [":helpers"], ) -cc_test( +grpc_cc_test( name = "bm_fullstack_streaming_ping_pong", srcs = ["bm_fullstack_streaming_ping_pong.cc"], deps = [":helpers"], ) -cc_test( +grpc_cc_test( name = "bm_fullstack_streaming_pump", srcs = ["bm_fullstack_streaming_pump.cc"], deps = [":helpers"], ) -cc_test( +grpc_cc_test( name = "bm_fullstack_trickle", srcs = ["bm_fullstack_trickle.cc"], - deps = [":helpers", "//external:gflags"], + deps = [":helpers"], + external_deps = [ + "gflags", + ], ) -cc_test( +grpc_cc_test( name = "bm_fullstack_unary_ping_pong", srcs = ["bm_fullstack_unary_ping_pong.cc"], deps = [":helpers"], ) -cc_test( +grpc_cc_test( name = "bm_metadata", srcs = ["bm_metadata.cc"], deps = [":helpers"], diff --git a/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc b/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc index 0d267da723..704f255d5f 100644 --- a/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc +++ b/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc @@ -81,10 +81,16 @@ static void cq_done_cb(grpc_exec_ctx* exec_ctx, void* done_arg, gpr_free(cq_completion); } -/* Queues a completion tag. ZERO polling overhead */ +/* Queues a completion tag if deadline is > 0. + * Does nothing if deadline is 0 (i.e gpr_time_0(GPR_CLOCK_MONOTONIC)) */ static grpc_error* pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* ps, grpc_pollset_worker** worker, gpr_timespec now, gpr_timespec deadline) { + if (gpr_time_cmp(deadline, gpr_time_0(GPR_CLOCK_MONOTONIC)) == 0) { + gpr_log(GPR_ERROR, "no-op"); + return GRPC_ERROR_NONE; + } + gpr_mu_unlock(&ps->mu); grpc_cq_begin_op(g_cq, g_tag); grpc_cq_end_op(exec_ctx, g_cq, g_tag, GRPC_ERROR_NONE, cq_done_cb, NULL, @@ -115,6 +121,14 @@ static void setup() { static void teardown() { grpc_completion_queue_shutdown(g_cq); + + /* Drain any events */ + gpr_timespec deadline = gpr_time_0(GPR_CLOCK_MONOTONIC); + while (grpc_completion_queue_next(g_cq, deadline, NULL).type != + GRPC_QUEUE_SHUTDOWN) { + /* Do nothing */ + } + grpc_completion_queue_destroy(g_cq); } diff --git a/test/cpp/microbenchmarks/bm_fullstack_trickle.cc b/test/cpp/microbenchmarks/bm_fullstack_trickle.cc index 6b9fa8b38d..d7e3a9cf47 100644 --- a/test/cpp/microbenchmarks/bm_fullstack_trickle.cc +++ b/test/cpp/microbenchmarks/bm_fullstack_trickle.cc @@ -101,6 +101,8 @@ class TrickledCHTTP2 : public EndpointPairFixture { } void AddToLabel(std::ostream& out, benchmark::State& state) { + grpc_chttp2_transport* client = + reinterpret_cast<grpc_chttp2_transport*>(client_transport_); out << " writes/iter:" << ((double)stats_.num_writes / (double)state.iterations()) << " cli_transport_stalls/iter:" @@ -116,7 +118,8 @@ class TrickledCHTTP2 : public EndpointPairFixture { (double)state.iterations()) << " svr_stream_stalls/iter:" << ((double)server_stats_.streams_stalled_due_to_stream_flow_control / - (double)state.iterations()); + (double)state.iterations()) + << " cli_bw_est:" << (double)client->bdp_estimator.bw_est; } void Log(int64_t iteration) { diff --git a/test/cpp/microbenchmarks/fullstack_fixtures.h b/test/cpp/microbenchmarks/fullstack_fixtures.h index 98aca1c346..aa71c2ae3f 100644 --- a/test/cpp/microbenchmarks/fullstack_fixtures.h +++ b/test/cpp/microbenchmarks/fullstack_fixtures.h @@ -100,6 +100,12 @@ class FullstackFixture : public BaseFixture { } } + void AddToLabel(std::ostream& out, benchmark::State& state) { + BaseFixture::AddToLabel(out, state); + out << " polls/iter:" + << (double)grpc_get_cq_poll_num(this->cq()->cq()) / state.iterations(); + } + ServerCompletionQueue* cq() { return cq_.get(); } std::shared_ptr<Channel> channel() { return channel_; } @@ -212,6 +218,12 @@ class EndpointPairFixture : public BaseFixture { } } + void AddToLabel(std::ostream& out, benchmark::State& state) { + BaseFixture::AddToLabel(out, state); + out << " polls/iter:" + << (double)grpc_get_cq_poll_num(this->cq()->cq()) / state.iterations(); + } + ServerCompletionQueue* cq() { return cq_.get(); } std::shared_ptr<Channel> channel() { return channel_; } @@ -245,7 +257,7 @@ class InProcessCHTTP2 : public EndpointPairFixture { void AddToLabel(std::ostream& out, benchmark::State& state) { EndpointPairFixture::AddToLabel(out, state); out << " writes/iter:" - << ((double)stats_.num_writes / (double)state.iterations()); + << (double)stats_.num_writes / (double)state.iterations(); } private: diff --git a/test/cpp/microbenchmarks/helpers.cc b/test/cpp/microbenchmarks/helpers.cc index 6550742453..73ab9e4a1a 100644 --- a/test/cpp/microbenchmarks/helpers.cc +++ b/test/cpp/microbenchmarks/helpers.cc @@ -36,11 +36,11 @@ void TrackCounters::Finish(benchmark::State &state) { std::ostringstream out; AddToLabel(out, state); - auto label = out.str(); + std::string label = out.str(); if (label.length() && label[0] == ' ') { label = label.substr(1); } - state.SetLabel(label); + state.SetLabel(label.c_str()); } void TrackCounters::AddToLabel(std::ostream &out, benchmark::State &state) { diff --git a/test/cpp/qps/BUILD b/test/cpp/qps/BUILD index 6492b63ec3..c6a1fd2fce 100644 --- a/test/cpp/qps/BUILD +++ b/test/cpp/qps/BUILD @@ -29,14 +29,17 @@ licenses(["notice"]) # 3-clause BSD -cc_library( +load("//bazel:grpc_build_system.bzl", "grpc_cc_test", "grpc_cc_library", "grpc_cc_binary") + +grpc_cc_library( name = "parse_json", srcs = ["parse_json.cc"], hdrs = ["parse_json.h"], deps = ["//:grpc++"], + external_deps = ["protobuf"], ) -cc_library( +grpc_cc_library( name = "qps_worker_impl", srcs = [ "client_async.cc", @@ -56,7 +59,6 @@ cc_library( ":usage_timer", "//:grpc", "//:grpc++", - "//external:gtest", "//src/proto/grpc/testing:control_proto", "//src/proto/grpc/testing:payloads_proto", "//src/proto/grpc/testing:services_proto", @@ -65,9 +67,12 @@ cc_library( "//test/core/util:grpc_test_util", "//test/cpp/util:test_util", ], + external_deps = [ + "gtest", + ], ) -cc_library( +grpc_cc_library( name = "driver_impl", srcs = [ "driver.cc", @@ -90,7 +95,7 @@ cc_library( ], ) -cc_library( +grpc_cc_library( name = "benchmark_config", srcs = [ "benchmark_config.cc", @@ -102,12 +107,14 @@ cc_library( ":driver_impl", ":histogram", "//:grpc++", - "//external:gflags", "//src/proto/grpc/testing:control_proto", ], + external_deps = [ + "gflags", + ], ) -cc_library( +grpc_cc_library( name = "histogram", hdrs = [ "histogram.h", @@ -116,13 +123,13 @@ cc_library( deps = ["//:gpr"], ) -cc_library( +grpc_cc_library( name = "interarrival", hdrs = ["interarrival.h"], deps = ["//:grpc++"], ) -cc_binary( +grpc_cc_binary( name = "json_run_localhost", srcs = ["json_run_localhost.cc"], deps = [ @@ -133,7 +140,7 @@ cc_binary( ], ) -cc_test( +grpc_cc_test( name = "qps_interarrival_test", srcs = ["qps_interarrival_test.cc"], deps = [ @@ -142,18 +149,20 @@ cc_test( ], ) -cc_binary( +grpc_cc_binary( name = "qps_json_driver", srcs = ["qps_json_driver.cc"], deps = [ ":benchmark_config", ":driver_impl", "//:grpc++", - "//external:gflags", + ], + external_deps = [ + "gflags", ], ) -cc_test( +grpc_cc_test( name = "qps_openloop_test", srcs = ["qps_openloop_test.cc"], deps = [ @@ -163,7 +172,7 @@ cc_test( ], ) -cc_test( +grpc_cc_test( name = "secure_sync_unary_ping_pong_test", srcs = ["secure_sync_unary_ping_pong_test.cc"], deps = [ @@ -173,14 +182,14 @@ cc_test( ], ) -cc_library( +grpc_cc_library( name = "usage_timer", srcs = ["usage_timer.cc"], hdrs = ["usage_timer.h"], deps = ["//:gpr"], ) -cc_binary( +grpc_cc_binary( name = "qps_worker", srcs = ["worker.cc"], deps = [ diff --git a/test/cpp/qps/client.h b/test/cpp/qps/client.h index c3197eb622..5ae6b54f89 100644 --- a/test/cpp/qps/client.h +++ b/test/cpp/qps/client.h @@ -46,6 +46,7 @@ #include <grpc/support/log.h> #include <grpc/support/time.h> +#include "src/core/lib/surface/completion_queue.h" #include "src/proto/grpc/testing/payloads.pb.h" #include "src/proto/grpc/testing/services.grpc.pb.h" @@ -150,7 +151,8 @@ class Client { Client() : timer_(new UsageTimer), interarrival_timer_(), - started_requests_(false) { + started_requests_(false), + last_reset_poll_count_(0) { gpr_event_init(&start_requests_); } virtual ~Client() {} @@ -162,6 +164,8 @@ class Client { MaybeStartRequests(); + int cur_poll_count = GetPollCount(); + int poll_count = cur_poll_count - last_reset_poll_count_; if (reset) { std::vector<Histogram> to_merge(threads_.size()); std::vector<StatusHistogram> to_merge_status(threads_.size()); @@ -176,6 +180,7 @@ class Client { MergeStatusHistogram(to_merge_status[i], &statuses); } timer_result = timer->Mark(); + last_reset_poll_count_ = cur_poll_count; } else { // merge snapshots of each thread histogram for (size_t i = 0; i < threads_.size(); i++) { @@ -195,6 +200,7 @@ class Client { stats.set_time_elapsed(timer_result.wall); stats.set_time_system(timer_result.system); stats.set_time_user(timer_result.user); + stats.set_cq_poll_count(poll_count); return stats; } @@ -209,6 +215,11 @@ class Client { } } + virtual int GetPollCount() { + // For sync client. + return 0; + } + protected: bool closed_loop_; gpr_atm thread_pool_done_; @@ -351,6 +362,8 @@ class Client { gpr_event start_requests_; bool started_requests_; + int last_reset_poll_count_; + void MaybeStartRequests() { if (!started_requests_) { started_requests_ = true; diff --git a/test/cpp/qps/client_async.cc b/test/cpp/qps/client_async.cc index 82c3356f02..6b8f736813 100644 --- a/test/cpp/qps/client_async.cc +++ b/test/cpp/qps/client_async.cc @@ -205,6 +205,14 @@ class AsyncClient : public ClientImpl<StubType, RequestType> { } } + int GetPollCount() override { + int count = 0; + for (auto cq = cli_cqs_.begin(); cq != cli_cqs_.end(); cq++) { + count += grpc_get_cq_poll_num((*cq)->cq()); + } + return count; + } + protected: const int num_async_threads_; diff --git a/test/cpp/qps/client_sync.cc b/test/cpp/qps/client_sync.cc index 9075033bd4..f35713280a 100644 --- a/test/cpp/qps/client_sync.cc +++ b/test/cpp/qps/client_sync.cc @@ -48,7 +48,6 @@ #include <grpc/support/host_port.h> #include <grpc/support/log.h> #include <grpc/support/time.h> -#include <gtest/gtest.h> #include "src/core/lib/profiling/timers.h" #include "src/proto/grpc/testing/services.grpc.pb.h" diff --git a/test/cpp/qps/driver.cc b/test/cpp/qps/driver.cc index 74fe3662c1..ace5028876 100644 --- a/test/cpp/qps/driver.cc +++ b/test/cpp/qps/driver.cc @@ -112,6 +112,8 @@ static deque<string> get_workers(const string& env_name) { static double WallTime(ClientStats s) { return s.time_elapsed(); } static double SystemTime(ClientStats s) { return s.time_system(); } static double UserTime(ClientStats s) { return s.time_user(); } +static double CliPollCount(ClientStats s) { return s.cq_poll_count(); } +static double SvrPollCount(ServerStats s) { return s.cq_poll_count(); } static double ServerWallTime(ServerStats s) { return s.time_elapsed(); } static double ServerSystemTime(ServerStats s) { return s.time_system(); } static double ServerUserTime(ServerStats s) { return s.time_user(); } @@ -180,6 +182,11 @@ static void postprocess_scenario_result(ScenarioResult* result) { result->mutable_summary()->set_failed_requests_per_second(failures / time_estimate); } + + result->mutable_summary()->set_client_polls_per_request( + sum(result->client_stats(), CliPollCount) / histogram.Count()); + result->mutable_summary()->set_server_polls_per_request( + sum(result->server_stats(), SvrPollCount) / histogram.Count()); } std::unique_ptr<ScenarioResult> RunScenario( diff --git a/test/cpp/qps/qps_json_driver.cc b/test/cpp/qps/qps_json_driver.cc index a906137474..f00f771ea0 100644 --- a/test/cpp/qps/qps_json_driver.cc +++ b/test/cpp/qps/qps_json_driver.cc @@ -94,6 +94,7 @@ static std::unique_ptr<ScenarioResult> RunAndReport(const Scenario& scenario, GetReporter()->ReportLatency(*result); GetReporter()->ReportTimes(*result); GetReporter()->ReportCpuUsage(*result); + GetReporter()->ReportPollCount(*result); for (int i = 0; *success && i < result->client_success_size(); i++) { *success = result->client_success(i); diff --git a/test/cpp/qps/report.cc b/test/cpp/qps/report.cc index a9130bf5d4..8bb4c9a3a5 100644 --- a/test/cpp/qps/report.cc +++ b/test/cpp/qps/report.cc @@ -80,6 +80,12 @@ void CompositeReporter::ReportCpuUsage(const ScenarioResult& result) { } } +void CompositeReporter::ReportPollCount(const ScenarioResult& result) { + for (size_t i = 0; i < reporters_.size(); ++i) { + reporters_[i]->ReportPollCount(result); + } +} + void GprLogReporter::ReportQPS(const ScenarioResult& result) { gpr_log(GPR_INFO, "QPS: %.1f", result.summary().qps()); if (result.summary().failed_requests_per_second() > 0) { @@ -121,6 +127,13 @@ void GprLogReporter::ReportCpuUsage(const ScenarioResult& result) { result.summary().server_cpu_usage()); } +void GprLogReporter::ReportPollCount(const ScenarioResult& result) { + gpr_log(GPR_INFO, "Client Polls per Request: %.2f", + result.summary().client_polls_per_request()); + gpr_log(GPR_INFO, "Server Polls per Request: %.2f", + result.summary().server_polls_per_request()); +} + void JsonReporter::ReportQPS(const ScenarioResult& result) { grpc::string json_string = SerializeJson(result, "type.googleapis.com/grpc.testing.ScenarioResult"); @@ -145,6 +158,10 @@ void JsonReporter::ReportCpuUsage(const ScenarioResult& result) { // NOP - all reporting is handled by ReportQPS. } +void JsonReporter::ReportPollCount(const ScenarioResult& result) { + // NOP - all reporting is handled by ReportQPS. +} + void RpcReporter::ReportQPS(const ScenarioResult& result) { grpc::ClientContext context; grpc::Status status; @@ -177,5 +194,9 @@ void RpcReporter::ReportCpuUsage(const ScenarioResult& result) { // NOP - all reporting is handled by ReportQPS. } +void RpcReporter::ReportPollCount(const ScenarioResult& result) { + // NOP - all reporting is handled by ReportQPS. +} + } // namespace testing } // namespace grpc diff --git a/test/cpp/qps/report.h b/test/cpp/qps/report.h index 1749be98c6..621fa7cb00 100644 --- a/test/cpp/qps/report.h +++ b/test/cpp/qps/report.h @@ -76,6 +76,9 @@ class Reporter { /** Reports server cpu usage. */ virtual void ReportCpuUsage(const ScenarioResult& result) = 0; + /** Reports client and server poll usage inside completion queue. */ + virtual void ReportPollCount(const ScenarioResult& result) = 0; + private: const string name_; }; @@ -93,6 +96,7 @@ class CompositeReporter : public Reporter { void ReportLatency(const ScenarioResult& result) override; void ReportTimes(const ScenarioResult& result) override; void ReportCpuUsage(const ScenarioResult& result) override; + void ReportPollCount(const ScenarioResult& result) override; private: std::vector<std::unique_ptr<Reporter> > reporters_; @@ -109,6 +113,7 @@ class GprLogReporter : public Reporter { void ReportLatency(const ScenarioResult& result) override; void ReportTimes(const ScenarioResult& result) override; void ReportCpuUsage(const ScenarioResult& result) override; + void ReportPollCount(const ScenarioResult& result) override; }; /** Dumps the report to a JSON file. */ @@ -123,6 +128,7 @@ class JsonReporter : public Reporter { void ReportLatency(const ScenarioResult& result) override; void ReportTimes(const ScenarioResult& result) override; void ReportCpuUsage(const ScenarioResult& result) override; + void ReportPollCount(const ScenarioResult& result) override; const string report_file_; }; @@ -138,6 +144,7 @@ class RpcReporter : public Reporter { void ReportLatency(const ScenarioResult& result) override; void ReportTimes(const ScenarioResult& result) override; void ReportCpuUsage(const ScenarioResult& result) override; + void ReportPollCount(const ScenarioResult& result) override; std::unique_ptr<ReportQpsScenarioService::Stub> stub_; }; diff --git a/test/cpp/qps/server.h b/test/cpp/qps/server.h index 8fbf37a095..a03dd1a695 100644 --- a/test/cpp/qps/server.h +++ b/test/cpp/qps/server.h @@ -38,6 +38,7 @@ #include <grpc/support/cpu.h> #include <vector> +#include "src/core/lib/surface/completion_queue.h" #include "src/proto/grpc/testing/control.pb.h" #include "src/proto/grpc/testing/messages.pb.h" #include "test/core/end2end/data/ssl_test_data.h" @@ -49,7 +50,8 @@ namespace testing { class Server { public: - explicit Server(const ServerConfig& config) : timer_(new UsageTimer) { + explicit Server(const ServerConfig& config) + : timer_(new UsageTimer), last_reset_poll_count_(0) { cores_ = gpr_cpu_num_cores(); if (config.port()) { port_ = config.port(); @@ -62,10 +64,13 @@ class Server { ServerStats Mark(bool reset) { UsageTimer::Result timer_result; + int cur_poll_count = GetPollCount(); + int poll_count = cur_poll_count - last_reset_poll_count_; if (reset) { std::unique_ptr<UsageTimer> timer(new UsageTimer); timer.swap(timer_); timer_result = timer->Mark(); + last_reset_poll_count_ = cur_poll_count; } else { timer_result = timer_->Mark(); } @@ -76,6 +81,7 @@ class Server { stats.set_time_user(timer_result.user); stats.set_total_cpu_time(timer_result.total_cpu_time); stats.set_idle_cpu_time(timer_result.idle_cpu_time); + stats.set_cq_poll_count(poll_count); return stats; } @@ -106,10 +112,16 @@ class Server { } } + virtual int GetPollCount() { + // For sync server. + return 0; + } + private: int port_; int cores_; std::unique_ptr<UsageTimer> timer_; + int last_reset_poll_count_; }; std::unique_ptr<Server> CreateSynchronousServer(const ServerConfig& config); diff --git a/test/cpp/qps/server_async.cc b/test/cpp/qps/server_async.cc index 84f1579c2f..3403ffd326 100644 --- a/test/cpp/qps/server_async.cc +++ b/test/cpp/qps/server_async.cc @@ -186,6 +186,14 @@ class AsyncQpsServerTest final : public grpc::testing::Server { shutdown_thread.join(); } + int GetPollCount() override { + int count = 0; + for (auto cq = srv_cqs_.begin(); cq != srv_cqs_.end(); cq++) { + count += grpc_get_cq_poll_num((*cq)->cq()); + } + return count; + } + private: void ShutdownThreadFunc() { // TODO (vpai): Remove this deadline and allow Shutdown to finish properly diff --git a/test/cpp/util/BUILD b/test/cpp/util/BUILD index 9dde22b4d1..453e9b6c0f 100644 --- a/test/cpp/util/BUILD +++ b/test/cpp/util/BUILD @@ -29,16 +29,20 @@ licenses(["notice"]) # 3-clause BSD +load("//bazel:grpc_build_system.bzl", "grpc_cc_library", "grpc_cc_binary") + +package(default_visibility = ["//visibility:public"]) + # The following builds a shared-object to confirm that grpc++_unsecure # builds properly. Build-only is sufficient here -cc_binary( +grpc_cc_binary( name = "testso.so", srcs = [], linkshared = 1, deps = ["//:grpc++_unsecure"], ) -cc_library( +grpc_cc_library( name = "test_config", srcs = [ "test_config_cc.cc", @@ -46,14 +50,15 @@ cc_library( hdrs = [ "test_config.h", ], - visibility = ["//test:__subpackages__"], + external_deps = [ + "gflags", + ], deps = [ "//:gpr", - "//external:gflags", ], ) -cc_library( +grpc_cc_library( name = "grpc++_proto_reflection_desc_db", srcs = [ "proto_reflection_descriptor_database.cc", @@ -61,14 +66,13 @@ cc_library( hdrs = [ "proto_reflection_descriptor_database.h", ], - visibility = ["//test:__subpackages__"], deps = [ "//:grpc++_config_proto", "//src/proto/grpc/reflection/v1alpha:reflection_proto", ], ) -cc_library( +grpc_cc_library( name = "test_util", srcs = [ "byte_buffer_proto_helper.cc", @@ -84,12 +88,57 @@ cc_library( "subprocess.h", "test_credentials_provider.h", ], - visibility = ["//test:__subpackages__"], deps = [ "//:grpc++", "//test/core/end2end:ssl_test_data", "//test/core/util:gpr_test_util", ], + external_deps = [ + "protobuf", + ], +) + +grpc_cc_library( + name = "grpc_cli_libs", + srcs = [ + "cli_call.cc", + "cli_credentials.cc", + "grpc_tool.cc", + "proto_file_parser.cc", + "service_describer.cc", + ], + hdrs = [ + "cli_call.h", + "cli_credentials.h", + "config_grpc_cli.h", + "grpc_tool.h", + "proto_file_parser.h", + "service_describer.h", + ], + deps = [ + "//:grpc++", + "//src/proto/grpc/reflection/v1alpha:reflection_proto", + ":grpc++_proto_reflection_desc_db", + ], + external_deps = [ + "gflags", + "protobuf", + "protobuf_clib", + ], +) + +grpc_cc_library( + name = "metrics_server_lib", + srcs = [ + "metrics_server.cc", + ], + hdrs = [ + "metrics_server.h", + ], + deps = [ + "//src/proto/grpc/testing:metrics_proto", + "//:grpc++", + ], ) cc_test( |