diff options
author | Craig Tiller <ctiller@google.com> | 2015-07-17 22:59:53 -0700 |
---|---|---|
committer | Craig Tiller <ctiller@google.com> | 2015-07-17 22:59:53 -0700 |
commit | b5980be9a08678212e5dbd6549b923f545d83539 (patch) | |
tree | e0318622c5a5576377537783608b60516b46c4cf /test/cpp/interop | |
parent | a14215a67841ea7920260c655c01e4570595a3db (diff) | |
parent | f87a0984ab727e95b068237f3bb0689d9685c8ea (diff) |
Merge github.com:grpc/grpc into sometimes-its-good-just-to-check-in-with-each-other
Diffstat (limited to 'test/cpp/interop')
-rw-r--r-- | test/cpp/interop/client.cc | 5 | ||||
-rw-r--r-- | test/cpp/interop/interop_client.cc | 21 | ||||
-rw-r--r-- | test/cpp/interop/interop_client.h | 1 | ||||
-rw-r--r-- | test/cpp/interop/server.cc | 12 | ||||
-rw-r--r-- | test/cpp/interop/server_helper.cc | 13 | ||||
-rw-r--r-- | test/cpp/interop/server_helper.h | 13 |
6 files changed, 58 insertions, 7 deletions
diff --git a/test/cpp/interop/client.cc b/test/cpp/interop/client.cc index 65ce2e9c2a..96149c5e75 100644 --- a/test/cpp/interop/client.cc +++ b/test/cpp/interop/client.cc @@ -64,6 +64,7 @@ DEFINE_string(test_case, "large_unary", "ping_pong : full-duplex streaming; " "cancel_after_begin : cancel stream after starting it; " "cancel_after_first_response: cancel on first response; " + "timeout_on_sleeping_server: deadline exceeds on stream; " "service_account_creds : large_unary with service_account auth; " "compute_engine_creds: large_unary with compute engine auth; " "jwt_token_creds: large_unary with JWT token auth; " @@ -101,6 +102,8 @@ int main(int argc, char** argv) { client.DoCancelAfterBegin(); } else if (FLAGS_test_case == "cancel_after_first_response") { client.DoCancelAfterFirstResponse(); + } else if (FLAGS_test_case == "timeout_on_sleeping_server") { + client.DoTimeoutOnSleepingServer(); } else if (FLAGS_test_case == "service_account_creds") { grpc::string json_key = GetServiceAccountJsonKey(); client.DoServiceAccountCreds(json_key, FLAGS_oauth_scope); @@ -119,6 +122,7 @@ int main(int argc, char** argv) { client.DoPingPong(); client.DoCancelAfterBegin(); client.DoCancelAfterFirstResponse(); + client.DoTimeoutOnSleepingServer(); // service_account_creds and jwt_token_creds can only run with ssl. if (FLAGS_enable_ssl) { grpc::string json_key = GetServiceAccountJsonKey(); @@ -132,6 +136,7 @@ int main(int argc, char** argv) { "Unsupported test case %s. Valid options are all|empty_unary|" "large_unary|client_streaming|server_streaming|half_duplex|ping_pong|" "cancel_after_begin|cancel_after_first_response|" + "timeout_on_sleeping_server|" "service_account_creds|compute_engine_creds|jwt_token_creds", FLAGS_test_case.c_str()); ret = 1; diff --git a/test/cpp/interop/interop_client.cc b/test/cpp/interop/interop_client.cc index f08f90b139..d88eff759c 100644 --- a/test/cpp/interop/interop_client.cc +++ b/test/cpp/interop/interop_client.cc @@ -351,5 +351,26 @@ void InteropClient::DoCancelAfterFirstResponse() { gpr_log(GPR_INFO, "Canceling pingpong streaming done."); } +void InteropClient::DoTimeoutOnSleepingServer() { + gpr_log(GPR_INFO, "Sending Ping Pong streaming rpc with a short deadline..."); + std::unique_ptr<TestService::Stub> stub(TestService::NewStub(channel_)); + + ClientContext context; + std::chrono::system_clock::time_point deadline = + std::chrono::system_clock::now() + std::chrono::milliseconds(1); + context.set_deadline(deadline); + std::unique_ptr<ClientReaderWriter<StreamingOutputCallRequest, + StreamingOutputCallResponse>> + stream(stub->FullDuplexCall(&context)); + + StreamingOutputCallRequest request; + request.mutable_payload()->set_body(grpc::string(27182, '\0')); + stream->Write(request); + + Status s = stream->Finish(); + GPR_ASSERT(s.error_code() == StatusCode::DEADLINE_EXCEEDED); + gpr_log(GPR_INFO, "Pingpong streaming timeout done."); +} + } // namespace testing } // namespace grpc diff --git a/test/cpp/interop/interop_client.h b/test/cpp/interop/interop_client.h index d9c895dfd9..d02e583d94 100644 --- a/test/cpp/interop/interop_client.h +++ b/test/cpp/interop/interop_client.h @@ -59,6 +59,7 @@ class InteropClient { void DoResponseStreamingWithSlowConsumer(); void DoCancelAfterBegin(); void DoCancelAfterFirstResponse(); + void DoTimeoutOnSleepingServer(); // Auth tests. // username is a string containing the user email void DoJwtTokenCreds(const grpc::string& username); diff --git a/test/cpp/interop/server.cc b/test/cpp/interop/server.cc index 22b8910a24..db87872cf5 100644 --- a/test/cpp/interop/server.cc +++ b/test/cpp/interop/server.cc @@ -149,14 +149,12 @@ class TestServiceImpl : public TestService::Service { StreamingOutputCallResponse response; bool write_success = true; while (write_success && stream->Read(&request)) { - response.mutable_payload()->set_type(request.payload().type()); - if (request.response_parameters_size() == 0) { - return Status(grpc::StatusCode::INTERNAL, - "Request does not have response parameters."); + if (request.response_parameters_size() != 0) { + response.mutable_payload()->set_type(request.payload().type()); + response.mutable_payload()->set_body( + grpc::string(request.response_parameters(0).size(), '\0')); + write_success = stream->Write(response); } - response.mutable_payload()->set_body( - grpc::string(request.response_parameters(0).size(), '\0')); - write_success = stream->Write(response); } if (write_success) { return Status::OK; diff --git a/test/cpp/interop/server_helper.cc b/test/cpp/interop/server_helper.cc index c2e750dcf7..30a78ffddf 100644 --- a/test/cpp/interop/server_helper.cc +++ b/test/cpp/interop/server_helper.cc @@ -58,5 +58,18 @@ std::shared_ptr<ServerCredentials> CreateInteropServerCredentials() { } } +InteropContextInspector::InteropContextInspector( + const ::grpc::ServerContext& context) + : context_(context) {} + +std::shared_ptr<const AuthContext> InteropContextInspector::GetAuthContext() + const { + return context_.auth_context(); +} + +bool InteropContextInspector::IsCancelled() const { + return context_.IsCancelled(); +} + } // namespace testing } // namespace grpc diff --git a/test/cpp/interop/server_helper.h b/test/cpp/interop/server_helper.h index f98e67bb67..ce977b4705 100644 --- a/test/cpp/interop/server_helper.h +++ b/test/cpp/interop/server_helper.h @@ -36,6 +36,7 @@ #include <memory> +#include <grpc++/server_context.h> #include <grpc++/server_credentials.h> namespace grpc { @@ -43,6 +44,18 @@ namespace testing { std::shared_ptr<ServerCredentials> CreateInteropServerCredentials(); +class InteropContextInspector { + public: + InteropContextInspector(const ::grpc::ServerContext& context); + + // Inspector methods, able to peek inside ServerContext, follow. + std::shared_ptr<const AuthContext> GetAuthContext() const; + bool IsCancelled() const; + + private: + const ::grpc::ServerContext& context_; +}; + } // namespace testing } // namespace grpc |