diff options
author | Craig Tiller <ctiller@google.com> | 2017-07-05 08:37:09 -0700 |
---|---|---|
committer | Craig Tiller <ctiller@google.com> | 2017-07-05 08:37:09 -0700 |
commit | a1a3f363ee0309bdfbcdf919ab57468e3522731a (patch) | |
tree | a4d755c6b8512f47771a23ae8255ccb567391359 /test/cpp | |
parent | f95873e67632c2b7c323c6613b5e23cae60ecf17 (diff) | |
parent | 7405347cd848f27067b9ce3c029325799ebaa888 (diff) |
Merge github.com:grpc/grpc into optimize_for
Diffstat (limited to 'test/cpp')
-rw-r--r-- | test/cpp/common/alarm_cpp_test.cc | 31 | ||||
-rw-r--r-- | test/cpp/common/channel_filter_test.cc | 4 | ||||
-rw-r--r-- | test/cpp/end2end/client_lb_end2end_test.cc | 60 | ||||
-rw-r--r-- | test/cpp/end2end/filter_end2end_test.cc | 3 | ||||
-rw-r--r-- | test/cpp/microbenchmarks/bm_chttp2_hpack.cc | 2 | ||||
-rw-r--r-- | test/cpp/util/grpc_tool.cc | 8 |
6 files changed, 89 insertions, 19 deletions
diff --git a/test/cpp/common/alarm_cpp_test.cc b/test/cpp/common/alarm_cpp_test.cc index 3e4999994a..ce4168843c 100644 --- a/test/cpp/common/alarm_cpp_test.cc +++ b/test/cpp/common/alarm_cpp_test.cc @@ -40,6 +40,37 @@ TEST(AlarmTest, RegularExpiry) { EXPECT_EQ(junk, output_tag); } +TEST(AlarmTest, MoveConstructor) { + CompletionQueue cq; + void* junk = reinterpret_cast<void*>(1618033); + Alarm first(&cq, grpc_timeout_seconds_to_deadline(1), junk); + Alarm second(std::move(first)); + void* output_tag; + bool ok; + const CompletionQueue::NextStatus status = cq.AsyncNext( + (void**)&output_tag, &ok, grpc_timeout_seconds_to_deadline(2)); + EXPECT_EQ(status, CompletionQueue::GOT_EVENT); + EXPECT_TRUE(ok); + EXPECT_EQ(junk, output_tag); +} + +TEST(AlarmTest, MoveAssignment) { + CompletionQueue cq; + void* junk = reinterpret_cast<void*>(1618033); + Alarm first(&cq, grpc_timeout_seconds_to_deadline(1), junk); + Alarm second(std::move(first)); + first = std::move(second); + + void* output_tag; + bool ok; + const CompletionQueue::NextStatus status = cq.AsyncNext( + (void**)&output_tag, &ok, grpc_timeout_seconds_to_deadline(2)); + + EXPECT_EQ(status, CompletionQueue::GOT_EVENT); + EXPECT_TRUE(ok); + EXPECT_EQ(junk, output_tag); +} + TEST(AlarmTest, RegularExpiryChrono) { CompletionQueue cq; void* junk = reinterpret_cast<void*>(1618033); diff --git a/test/cpp/common/channel_filter_test.cc b/test/cpp/common/channel_filter_test.cc index e747e633a0..638518107b 100644 --- a/test/cpp/common/channel_filter_test.cc +++ b/test/cpp/common/channel_filter_test.cc @@ -28,7 +28,7 @@ class MyChannelData : public ChannelData { public: MyChannelData() {} - grpc_error* Init(grpc_exec_ctx* exec_ctx, + grpc_error* Init(grpc_exec_ctx* exec_ctx, grpc_channel_element* elem, grpc_channel_element_args* args) override { (void)args->channel_args; // Make sure field is available. return GRPC_ERROR_NONE; @@ -39,7 +39,7 @@ class MyCallData : public CallData { public: MyCallData() {} - grpc_error* Init(grpc_exec_ctx* exec_ctx, ChannelData* channel_data, + grpc_error* Init(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, const grpc_call_element_args* args) override { (void)args->path; // Make sure field is available. return GRPC_ERROR_NONE; diff --git a/test/cpp/end2end/client_lb_end2end_test.cc b/test/cpp/end2end/client_lb_end2end_test.cc index 776d94d3b6..f71e557450 100644 --- a/test/cpp/end2end/client_lb_end2end_test.cc +++ b/test/cpp/end2end/client_lb_end2end_test.cc @@ -97,9 +97,12 @@ class ClientLbEnd2endTest : public ::testing::Test { } } - void StartServers(int num_servers) { - for (int i = 0; i < num_servers; ++i) { - servers_.emplace_back(new ServerData(server_host_)); + void StartServers(size_t num_servers, + std::vector<int> ports = std::vector<int>()) { + for (size_t i = 0; i < num_servers; ++i) { + int port = 0; + if (ports.size() == num_servers) port = ports[i]; + servers_.emplace_back(new ServerData(server_host_, port)); } } @@ -146,14 +149,18 @@ class ClientLbEnd2endTest : public ::testing::Test { stub_ = grpc::testing::EchoTestService::NewStub(channel_); } - void SendRpc() { + void SendRpc(bool expect_ok = true) { EchoRequest request; EchoResponse response; request.set_message("Live long and prosper."); ClientContext context; Status status = stub_->Echo(&context, request, &response); - EXPECT_TRUE(status.ok()); - EXPECT_EQ(response.message(), request.message()); + if (expect_ok) { + EXPECT_TRUE(status.ok()); + EXPECT_EQ(response.message(), request.message()); + } else { + EXPECT_FALSE(status.ok()); + } } struct ServerData { @@ -162,8 +169,8 @@ class ClientLbEnd2endTest : public ::testing::Test { MyTestServiceImpl service_; std::unique_ptr<std::thread> thread_; - explicit ServerData(const grpc::string& server_host) { - port_ = grpc_pick_unused_port_or_die(); + explicit ServerData(const grpc::string& server_host, int port = 0) { + port_ = port > 0 ? port : grpc_pick_unused_port_or_die(); gpr_log(GPR_INFO, "starting server on port %d", port_); std::mutex mu; std::condition_variable cond; @@ -187,9 +194,9 @@ class ClientLbEnd2endTest : public ::testing::Test { cond->notify_one(); } - void Shutdown() { + void Shutdown(bool join = true) { server_->Shutdown(); - thread_->join(); + if (join) thread_->join(); } }; @@ -456,6 +463,39 @@ TEST_F(ClientLbEnd2endTest, RoundRobinManyUpdates) { EXPECT_EQ("round_robin", channel_->GetLoadBalancingPolicyName()); } +TEST_F(ClientLbEnd2endTest, RoundRobinReconnect) { + // Start servers and send one RPC per server. + const int kNumServers = 1; + std::vector<int> ports; + ports.push_back(grpc_pick_unused_port_or_die()); + StartServers(kNumServers, ports); + ResetStub("round_robin"); + SetNextResolution(ports); + // Send one RPC per backend and make sure they are used in order. + // Note: This relies on the fact that the subchannels are reported in + // 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(); + 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); + + // Bring servers back up on the same port (we aren't recreating the channel). + StartServers(kNumServers, ports); + + // Client request should succeed. + SendRpc(); +} + } // namespace } // namespace testing } // namespace grpc diff --git a/test/cpp/end2end/filter_end2end_test.cc b/test/cpp/end2end/filter_end2end_test.cc index bf5a9c227a..f260ea0016 100644 --- a/test/cpp/end2end/filter_end2end_test.cc +++ b/test/cpp/end2end/filter_end2end_test.cc @@ -100,7 +100,8 @@ int GetCallCounterValue() { class ChannelDataImpl : public ChannelData { public: - grpc_error* Init(grpc_exec_ctx* exec_ctx, grpc_channel_element_args* args) { + grpc_error* Init(grpc_exec_ctx* exec_ctx, grpc_channel_element* elem, + grpc_channel_element_args* args) { IncrementConnectionCounter(); return GRPC_ERROR_NONE; } diff --git a/test/cpp/microbenchmarks/bm_chttp2_hpack.cc b/test/cpp/microbenchmarks/bm_chttp2_hpack.cc index 3457fd77cf..adbfa4d796 100644 --- a/test/cpp/microbenchmarks/bm_chttp2_hpack.cc +++ b/test/cpp/microbenchmarks/bm_chttp2_hpack.cc @@ -82,7 +82,7 @@ static void BM_HpackEncoderEncodeHeader(benchmark::State &state) { (size_t)state.range(1), &stats, }; - grpc_chttp2_encode_header(&exec_ctx, &c, &b, &hopt, &outbuf); + grpc_chttp2_encode_header(&exec_ctx, &c, NULL, 0, &b, &hopt, &outbuf); if (!logged_representative_output && state.iterations() > 3) { logged_representative_output = true; for (size_t i = 0; i < outbuf.count; i++) { diff --git a/test/cpp/util/grpc_tool.cc b/test/cpp/util/grpc_tool.cc index af0afa9b55..bb6f878020 100644 --- a/test/cpp/util/grpc_tool.cc +++ b/test/cpp/util/grpc_tool.cc @@ -445,12 +445,10 @@ bool GrpcTool::CallMethod(int argc, const char** argv, bool print_mode = false; std::shared_ptr<grpc::Channel> channel = - FLAGS_remotedb - ? grpc::CreateChannel(server_address, cred.GetCredentials()) - : nullptr; + grpc::CreateChannel(server_address, cred.GetCredentials()); - parser.reset(new grpc::testing::ProtoFileParser(channel, FLAGS_proto_path, - FLAGS_protofiles)); + parser.reset(new grpc::testing::ProtoFileParser( + FLAGS_remotedb ? channel : nullptr, FLAGS_proto_path, FLAGS_protofiles)); if (FLAGS_binary_input) { formatted_method_name = method_name; |