diff options
Diffstat (limited to 'test/cpp')
-rw-r--r-- | test/cpp/end2end/thread_stress_test.cc | 6 | ||||
-rw-r--r-- | test/cpp/grpclb/grpclb_test.cc | 3 | ||||
-rw-r--r-- | test/cpp/interop/client.cc | 9 | ||||
-rw-r--r-- | test/cpp/interop/interop_client.cc | 47 | ||||
-rw-r--r-- | test/cpp/interop/interop_client.h | 1 | ||||
-rw-r--r-- | test/cpp/interop/interop_server.cc | 5 | ||||
-rw-r--r-- | test/cpp/qps/client_sync.cc | 4 | ||||
-rw-r--r-- | test/cpp/qps/driver.cc | 3 | ||||
-rw-r--r-- | test/cpp/qps/server_async.cc | 11 | ||||
-rw-r--r-- | test/cpp/test/server_context_test_spouse_test.cc | 108 |
10 files changed, 185 insertions, 12 deletions
diff --git a/test/cpp/end2end/thread_stress_test.cc b/test/cpp/end2end/thread_stress_test.cc index b021b34523..0b9d4cda9f 100644 --- a/test/cpp/end2end/thread_stress_test.cc +++ b/test/cpp/end2end/thread_stress_test.cc @@ -339,7 +339,11 @@ static void SendRpc(grpc::testing::EchoTestService::Stub* stub, int num_rpcs) { ClientContext context; Status s = stub->Echo(&context, request, &response); EXPECT_EQ(response.message(), request.message()); - EXPECT_TRUE(s.ok()); + if (!s.ok()) { + gpr_log(GPR_ERROR, "RPC error: %d: %s", s.error_code(), + s.error_message().c_str()); + } + ASSERT_TRUE(s.ok()); } } diff --git a/test/cpp/grpclb/grpclb_test.cc b/test/cpp/grpclb/grpclb_test.cc index 7666c4e60b..80f2fa4f4d 100644 --- a/test/cpp/grpclb/grpclb_test.cc +++ b/test/cpp/grpclb/grpclb_test.cc @@ -334,8 +334,7 @@ static void start_backend_server(server_fixture *sf) { // have a version for int but does have one for long long int. string expected_token = "token" + std::to_string((long long int)sf->port); expected_token.resize(64, '-'); - GPR_ASSERT(contains_metadata(&request_metadata_recv, - "load-reporting-initial", + GPR_ASSERT(contains_metadata(&request_metadata_recv, "lb-token", expected_token.c_str())); gpr_log(GPR_INFO, "Server[%s] after tag 100", sf->servers_hostport); diff --git a/test/cpp/interop/client.cc b/test/cpp/interop/client.cc index 999be9d8a3..245e27b2bb 100644 --- a/test/cpp/interop/client.cc +++ b/test/cpp/interop/client.cc @@ -79,7 +79,8 @@ DEFINE_string(test_case, "large_unary", "slow_consumer : single request with response streaming with " "slow client consumer;\n" "status_code_and_message: verify status code & message;\n" - "timeout_on_sleeping_server: deadline exceeds on stream;\n"); + "timeout_on_sleeping_server: deadline exceeds on stream;\n" + "unimplemented_method: client calls an unimplemented_method;\n"); DEFINE_string(default_service_account, "", "Email of GCE default service account"); DEFINE_string(service_account_key_file, "", @@ -149,6 +150,8 @@ int main(int argc, char** argv) { client.DoStatusWithMessage(); } else if (FLAGS_test_case == "custom_metadata") { client.DoCustomMetadata(); + } else if (FLAGS_test_case == "unimplemented_method") { + client.DoUnimplementedMethod(); } else if (FLAGS_test_case == "cacheable_unary") { client.DoCacheableUnary(); } else if (FLAGS_test_case == "all") { @@ -168,6 +171,7 @@ int main(int argc, char** argv) { client.DoEmptyStream(); client.DoStatusWithMessage(); client.DoCustomMetadata(); + client.DoUnimplementedMethod(); client.DoCacheableUnary(); // service_account_creds and jwt_token_creds can only run with ssl. if (FLAGS_use_tls) { @@ -202,7 +206,8 @@ int main(int argc, char** argv) { "server_compressed_unary", "server_streaming", "status_code_and_message", - "timeout_on_sleeping_server"}; + "timeout_on_sleeping_server", + "unimplemented_method"}; char* joined_testcases = gpr_strjoin_sep(testcases, GPR_ARRAY_SIZE(testcases), "\n", NULL); diff --git a/test/cpp/interop/interop_client.cc b/test/cpp/interop/interop_client.cc index e9a804ccae..f95d8c6ef6 100644 --- a/test/cpp/interop/interop_client.cc +++ b/test/cpp/interop/interop_client.cc @@ -827,21 +827,42 @@ bool InteropClient::DoStatusWithMessage() { gpr_log(GPR_DEBUG, "Sending RPC with a request for status code 2 and message"); + const grpc::StatusCode test_code = grpc::StatusCode::UNKNOWN; + const grpc::string test_msg = "This is a test message"; + + // Test UnaryCall. ClientContext context; SimpleRequest request; SimpleResponse response; EchoStatus* requested_status = request.mutable_response_status(); - requested_status->set_code(grpc::StatusCode::UNKNOWN); - grpc::string test_msg = "This is a test message"; + requested_status->set_code(test_code); requested_status->set_message(test_msg); - Status s = serviceStub_.Get()->UnaryCall(&context, request, &response); - if (!AssertStatusCode(s, grpc::StatusCode::UNKNOWN)) { return false; } + GPR_ASSERT(s.error_message() == test_msg); + // Test FullDuplexCall. + ClientContext stream_context; + std::shared_ptr<ClientReaderWriter<StreamingOutputCallRequest, + StreamingOutputCallResponse>> + stream(serviceStub_.Get()->FullDuplexCall(&stream_context)); + StreamingOutputCallRequest streaming_request; + requested_status = streaming_request.mutable_response_status(); + requested_status->set_code(test_code); + requested_status->set_message(test_msg); + stream->Write(streaming_request); + stream->WritesDone(); + StreamingOutputCallResponse streaming_response; + while (stream->Read(&streaming_response)) + ; + s = stream->Finish(); + if (!AssertStatusCode(s, grpc::StatusCode::UNKNOWN)) { + return false; + } GPR_ASSERT(s.error_message() == test_msg); + gpr_log(GPR_DEBUG, "Done testing Status and Message"); return true; } @@ -981,5 +1002,23 @@ bool InteropClient::DoCustomMetadata() { return true; } +bool InteropClient::DoUnimplementedMethod() { + gpr_log(GPR_DEBUG, "Sending a request for an unimplemented rpc..."); + + Empty request = Empty::default_instance(); + Empty response = Empty::default_instance(); + ClientContext context; + + Status s = + serviceStub_.Get()->UnimplementedMethod(&context, request, &response); + + if (!AssertStatusCode(s, StatusCode::UNIMPLEMENTED)) { + return false; + } + + gpr_log(GPR_DEBUG, "unimplemented rpc done."); + return true; +} + } // namespace testing } // namespace grpc diff --git a/test/cpp/interop/interop_client.h b/test/cpp/interop/interop_client.h index 1e89f0987d..0a96e7734d 100644 --- a/test/cpp/interop/interop_client.h +++ b/test/cpp/interop/interop_client.h @@ -79,6 +79,7 @@ class InteropClient { bool DoEmptyStream(); bool DoStatusWithMessage(); bool DoCustomMetadata(); + bool DoUnimplementedMethod(); bool DoCacheableUnary(); // Auth tests. // username is a string containing the user email diff --git a/test/cpp/interop/interop_server.cc b/test/cpp/interop/interop_server.cc index 58f20aa611..8b50ae8c05 100644 --- a/test/cpp/interop/interop_server.cc +++ b/test/cpp/interop/interop_server.cc @@ -269,6 +269,11 @@ class TestServiceImpl : public TestService::Service { StreamingOutputCallResponse response; bool write_success = true; while (write_success && stream->Read(&request)) { + if (request.has_response_status()) { + return Status( + static_cast<grpc::StatusCode>(request.response_status().code()), + request.response_status().message()); + } if (request.response_parameters_size() != 0) { response.mutable_payload()->set_type(request.payload().type()); response.mutable_payload()->set_body( diff --git a/test/cpp/qps/client_sync.cc b/test/cpp/qps/client_sync.cc index 8062424a1f..0ccf4e270b 100644 --- a/test/cpp/qps/client_sync.cc +++ b/test/cpp/qps/client_sync.cc @@ -130,6 +130,10 @@ class SynchronousUnaryClient GRPC_FINAL : public SynchronousClient { grpc::Status s = stub->UnaryCall(&context, request_, &responses_[thread_idx]); entry->set_value((UsageTimer::Now() - start) * 1e9); + if (!s.ok()) { + gpr_log(GPR_ERROR, "RPC error: %d: %s", s.error_code(), + s.error_message().c_str()); + } return s.ok(); } }; diff --git a/test/cpp/qps/driver.cc b/test/cpp/qps/driver.cc index 7460bb526a..6c675e3483 100644 --- a/test/cpp/qps/driver.cc +++ b/test/cpp/qps/driver.cc @@ -45,6 +45,7 @@ #include <grpc/support/host_port.h> #include <grpc/support/log.h> +#include "src/core/lib/profiling/timers.h" #include "src/core/lib/support/env.h" #include "src/proto/grpc/testing/services.grpc.pb.h" #include "test/core/util/port.h" @@ -438,6 +439,8 @@ std::unique_ptr<ScenarioResult> RunScenario( start, gpr_time_from_seconds(warmup_seconds + benchmark_seconds, GPR_TIMESPAN))); + gpr_timer_set_enabled(0); + // Finish a run std::unique_ptr<ScenarioResult> result(new ScenarioResult); Histogram merged_latencies; diff --git a/test/cpp/qps/server_async.cc b/test/cpp/qps/server_async.cc index 082b4bc72f..73a96a8443 100644 --- a/test/cpp/qps/server_async.cc +++ b/test/cpp/qps/server_async.cc @@ -131,9 +131,7 @@ class AsyncQpsServerTest : public Server { std::lock_guard<std::mutex> lock((*ss)->mutex); (*ss)->shutdown = true; } - // TODO (vpai): Remove this deadline and allow Shutdown to finish properly - auto deadline = std::chrono::system_clock::now() + std::chrono::seconds(3); - server_->Shutdown(deadline); + std::thread shutdown_thread(&AsyncQpsServerTest::ShutdownThreadFunc, this); for (auto cq = srv_cqs_.begin(); cq != srv_cqs_.end(); ++cq) { (*cq)->Shutdown(); } @@ -146,9 +144,16 @@ class AsyncQpsServerTest : public Server { while ((*cq)->Next(&got_tag, &ok)) ; } + shutdown_thread.join(); } private: + void ShutdownThreadFunc() { + // TODO (vpai): Remove this deadline and allow Shutdown to finish properly + auto deadline = std::chrono::system_clock::now() + std::chrono::seconds(3); + server_->Shutdown(deadline); + } + void ThreadFunc(int thread_idx) { // Wait until work is available or we are shutting down bool ok; diff --git a/test/cpp/test/server_context_test_spouse_test.cc b/test/cpp/test/server_context_test_spouse_test.cc new file mode 100644 index 0000000000..e0d6a2ff67 --- /dev/null +++ b/test/cpp/test/server_context_test_spouse_test.cc @@ -0,0 +1,108 @@ +/* + * + * 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 <grpc++/test/server_context_test_spouse.h> + +#include <cstring> +#include <vector> + +#include <gtest/gtest.h> + +namespace grpc { +namespace testing { + +const char key1[] = "metadata-key1"; +const char key2[] = "metadata-key2"; +const char val1[] = "metadata-val1"; +const char val2[] = "metadata-val2"; + +bool ClientMetadataContains(const ServerContext& context, + const grpc::string_ref& key, + const grpc::string_ref& value) { + const auto& client_metadata = context.client_metadata(); + for (auto iter = client_metadata.begin(); iter != client_metadata.end(); + ++iter) { + if (iter->first == key && iter->second == value) { + return true; + } + } + return false; +} + +TEST(ServerContextTestSpouseTest, ClientMetadata) { + ServerContext context; + ServerContextTestSpouse spouse(&context); + + spouse.AddClientMetadata(key1, val1); + ASSERT_TRUE(ClientMetadataContains(context, key1, val1)); + + spouse.AddClientMetadata(key2, val2); + ASSERT_TRUE(ClientMetadataContains(context, key1, val1)); + ASSERT_TRUE(ClientMetadataContains(context, key2, val2)); +} + +TEST(ServerContextTestSpouseTest, InitialMetadata) { + ServerContext context; + ServerContextTestSpouse spouse(&context); + std::multimap<grpc::string, grpc::string> metadata; + + context.AddInitialMetadata(key1, val1); + metadata.insert(std::pair<grpc::string, grpc::string>(key1, val1)); + ASSERT_EQ(metadata, spouse.GetInitialMetadata()); + + context.AddInitialMetadata(key2, val2); + metadata.insert(std::pair<grpc::string, grpc::string>(key2, val2)); + ASSERT_EQ(metadata, spouse.GetInitialMetadata()); +} + +TEST(ServerContextTestSpouseTest, TrailingMetadata) { + ServerContext context; + ServerContextTestSpouse spouse(&context); + std::multimap<grpc::string, grpc::string> metadata; + + context.AddTrailingMetadata(key1, val1); + metadata.insert(std::pair<grpc::string, grpc::string>(key1, val1)); + ASSERT_EQ(metadata, spouse.GetTrailingMetadata()); + + context.AddTrailingMetadata(key2, val2); + metadata.insert(std::pair<grpc::string, grpc::string>(key2, val2)); + ASSERT_EQ(metadata, spouse.GetTrailingMetadata()); +} + +} // namespace +} // namespace grpc + +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} |