diff options
Diffstat (limited to 'test/cpp')
-rw-r--r-- | test/cpp/end2end/async_end2end_test.cc | 21 | ||||
-rw-r--r-- | test/cpp/end2end/end2end_test.cc | 21 | ||||
-rw-r--r-- | test/cpp/grpclb/grpclb_test.cc | 33 | ||||
-rw-r--r-- | test/cpp/interop/client.cc | 180 | ||||
-rw-r--r-- | test/cpp/interop/interop_client.cc | 9 | ||||
-rw-r--r-- | test/cpp/interop/interop_client.h | 1 | ||||
-rw-r--r-- | test/cpp/interop/interop_server.cc | 4 | ||||
-rw-r--r-- | test/cpp/test/server_context_test_spouse_test.cc | 3 |
8 files changed, 140 insertions, 132 deletions
diff --git a/test/cpp/end2end/async_end2end_test.cc b/test/cpp/end2end/async_end2end_test.cc index f53601297c..2ce3f2f7bd 100644 --- a/test/cpp/end2end/async_end2end_test.cc +++ b/test/cpp/end2end/async_end2end_test.cc @@ -228,7 +228,12 @@ class TestScenario { : disable_blocking(non_block), credentials_type(creds_type), message_content(content) {} - void Log() const; + void Log() const { + gpr_log( + GPR_INFO, + "Scenario: disable_blocking %d, credentials %s, message size %" PRIuPTR, + disable_blocking, credentials_type.c_str(), message_content.size()); + } bool disable_blocking; // Although the below grpc::string's are logically const, we can't declare // them const because of a limitation in the way old compilers (e.g., gcc-4.4) @@ -237,20 +242,6 @@ class TestScenario { grpc::string message_content; }; -static std::ostream& operator<<(std::ostream& out, - const TestScenario& scenario) { - return out << "TestScenario{disable_blocking=" - << (scenario.disable_blocking ? "true" : "false") - << ", credentials='" << scenario.credentials_type - << "', message_size=" << scenario.message_content.size() << "}"; -} - -void TestScenario::Log() const { - std::ostringstream out; - out << *this; - gpr_log(GPR_DEBUG, "%s", out.str().c_str()); -} - class AsyncEnd2endTest : public ::testing::TestWithParam<TestScenario> { protected: AsyncEnd2endTest() { GetParam().Log(); } diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc index 47e5c5bd77..edd56cef88 100644 --- a/test/cpp/end2end/end2end_test.cc +++ b/test/cpp/end2end/end2end_test.cc @@ -209,7 +209,10 @@ class TestScenario { public: TestScenario(bool proxy, const grpc::string& creds_type) : use_proxy(proxy), credentials_type(creds_type) {} - void Log() const; + void Log() const { + gpr_log(GPR_INFO, "Scenario: proxy %d, credentials %s", use_proxy, + credentials_type.c_str()); + } bool use_proxy; // Although the below grpc::string is logically const, we can't declare // them const because of a limitation in the way old compilers (e.g., gcc-4.4) @@ -217,19 +220,6 @@ class TestScenario { grpc::string credentials_type; }; -static std::ostream& operator<<(std::ostream& out, - const TestScenario& scenario) { - return out << "TestScenario{use_proxy=" - << (scenario.use_proxy ? "true" : "false") << ", credentials='" - << scenario.credentials_type << "'}"; -} - -void TestScenario::Log() const { - std::ostringstream out; - out << *this; - gpr_log(GPR_DEBUG, "%s", out.str().c_str()); -} - class End2endTest : public ::testing::TestWithParam<TestScenario> { protected: End2endTest() @@ -646,7 +636,7 @@ TEST_P(End2endServerTryCancelTest, BidiStreamServerCancelAfter) { TestBidiStreamServerCancel(CANCEL_AFTER_PROCESSING, 5); } -TEST_P(End2endTest, SimpleRpcWithCustomUserAgentPrefix) { +TEST_P(End2endTest, SimpleRpcWithCustomeUserAgentPrefix) { user_agent_prefix_ = "custom_prefix"; ResetStub(); EchoRequest request; @@ -1305,7 +1295,6 @@ TEST_P(SecureEnd2endTest, BlockingAuthMetadataPluginAndProcessorFailure) { EXPECT_FALSE(s.ok()); EXPECT_EQ(s.error_code(), StatusCode::UNAUTHENTICATED); } - TEST_P(SecureEnd2endTest, SetPerCallCredentials) { ResetStub(); EchoRequest request; diff --git a/test/cpp/grpclb/grpclb_test.cc b/test/cpp/grpclb/grpclb_test.cc index 07db474b87..3637190b6d 100644 --- a/test/cpp/grpclb/grpclb_test.cc +++ b/test/cpp/grpclb/grpclb_test.cc @@ -213,7 +213,7 @@ static void start_lb_server(server_fixture *sf, int *ports, size_t nports, // receive request for backends op = ops; op->op = GRPC_OP_RECV_MESSAGE; - op->data.recv_message = &request_payload_recv; + op->data.recv_message.recv_message = &request_payload_recv; op->flags = 0; op->reserved = NULL; op++; @@ -268,7 +268,7 @@ static void start_lb_server(server_fixture *sf, int *ports, size_t nports, response_payload = grpc_raw_byte_buffer_create(&response_payload_slice, 1); op = ops; op->op = GRPC_OP_SEND_MESSAGE; - op->data.send_message = response_payload; + op->data.send_message.send_message = response_payload; op->flags = 0; op->reserved = NULL; op++; @@ -288,8 +288,7 @@ static void start_lb_server(server_fixture *sf, int *ports, size_t nports, op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_OK; - grpc_slice status_details = grpc_slice_from_static_string("xyz"); - op->data.send_status_from_server.status_details = &status_details; + op->data.send_status_from_server.status_details = "xyz"; op->flags = 0; op->reserved = NULL; op++; @@ -373,7 +372,7 @@ static void start_backend_server(server_fixture *sf) { while (!exit) { op = ops; op->op = GRPC_OP_RECV_MESSAGE; - op->data.recv_message = &request_payload_recv; + op->data.recv_message.recv_message = &request_payload_recv; op->flags = 0; op->reserved = NULL; op++; @@ -402,7 +401,7 @@ static void start_backend_server(server_fixture *sf) { grpc_raw_byte_buffer_create(&response_payload_slice, 1); op = ops; op->op = GRPC_OP_SEND_MESSAGE; - op->data.send_message = response_payload; + op->data.send_message.send_message = response_payload; op->flags = 0; op->reserved = NULL; op++; @@ -434,9 +433,7 @@ static void start_backend_server(server_fixture *sf) { op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_OK; - grpc_slice status_details = - grpc_slice_from_static_string("Backend server out a-ok"); - op->data.send_status_from_server.status_details = &status_details; + op->data.send_status_from_server.status_details = "Backend server out a-ok"; op->flags = 0; op->reserved = NULL; op++; @@ -465,7 +462,8 @@ static void perform_request(client_fixture *cf) { grpc_metadata_array trailing_metadata_recv; grpc_status_code status; grpc_call_error error; - grpc_slice details; + char *details = NULL; + size_t details_capacity = 0; grpc_byte_buffer *request_payload; grpc_byte_buffer *response_payload_recv; int i; @@ -474,11 +472,9 @@ static void perform_request(client_fixture *cf) { grpc_slice request_payload_slice = grpc_slice_from_copied_string("hello world"); - grpc_slice host = grpc_slice_from_static_string("foo.test.google.fr:1234"); c = grpc_channel_create_call(cf->client, NULL, GRPC_PROPAGATE_DEFAULTS, - cf->cq, grpc_slice_from_static_string("/foo"), - &host, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5), - NULL); + cf->cq, "/foo", "foo.test.google.fr:1234", + GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5), NULL); gpr_log(GPR_INFO, "Call 0x%" PRIxPTR " created", (intptr_t)c); GPR_ASSERT(c); char *peer; @@ -493,7 +489,7 @@ static void perform_request(client_fixture *cf) { op->reserved = NULL; op++; op->op = GRPC_OP_RECV_INITIAL_METADATA; - op->data.recv_initial_metadata = &initial_metadata_recv; + op->data.recv_initial_metadata.recv_initial_metadata = &initial_metadata_recv; op->flags = 0; op->reserved = NULL; op++; @@ -501,6 +497,7 @@ static void perform_request(client_fixture *cf) { op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -512,12 +509,12 @@ static void perform_request(client_fixture *cf) { op = ops; op->op = GRPC_OP_SEND_MESSAGE; - op->data.send_message = request_payload; + op->data.send_message.send_message = request_payload; op->flags = 0; op->reserved = NULL; op++; op->op = GRPC_OP_RECV_MESSAGE; - op->data.recv_message = &response_payload_recv; + op->data.recv_message.recv_message = &response_payload_recv; op->flags = 0; op->reserved = NULL; op++; @@ -556,7 +553,7 @@ static void perform_request(client_fixture *cf) { grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); - grpc_slice_unref(details); + gpr_free(details); gpr_log(GPR_INFO, "Client call (peer %s) DESTROYED.", peer); gpr_free(peer); } diff --git a/test/cpp/interop/client.cc b/test/cpp/interop/client.cc index 1df2fc8320..3265554444 100644 --- a/test/cpp/interop/client.cc +++ b/test/cpp/interop/client.cc @@ -32,7 +32,6 @@ */ #include <memory> -#include <unordered_map> #include <unistd.h> @@ -109,78 +108,119 @@ int main(int argc, char** argv) { grpc::testing::InteropClient client(CreateChannelForTestCase(FLAGS_test_case), true, FLAGS_do_not_abort_on_transient_failures); - - std::unordered_map<grpc::string, std::function<bool()>> actions; - actions["empty_unary"] = - std::bind(&grpc::testing::InteropClient::DoEmpty, &client); - actions["large_unary"] = - std::bind(&grpc::testing::InteropClient::DoLargeUnary, &client); - actions["server_compressed_unary"] = std::bind( - &grpc::testing::InteropClient::DoServerCompressedUnary, &client); - actions["client_compressed_unary"] = std::bind( - &grpc::testing::InteropClient::DoClientCompressedUnary, &client); - actions["client_streaming"] = - std::bind(&grpc::testing::InteropClient::DoRequestStreaming, &client); - actions["server_streaming"] = - std::bind(&grpc::testing::InteropClient::DoResponseStreaming, &client); - actions["server_compressed_streaming"] = std::bind( - &grpc::testing::InteropClient::DoServerCompressedStreaming, &client); - actions["client_compressed_streaming"] = std::bind( - &grpc::testing::InteropClient::DoClientCompressedStreaming, &client); - actions["slow_consumer"] = std::bind( - &grpc::testing::InteropClient::DoResponseStreamingWithSlowConsumer, - &client); - actions["half_duplex"] = - std::bind(&grpc::testing::InteropClient::DoHalfDuplex, &client); - actions["ping_pong"] = - std::bind(&grpc::testing::InteropClient::DoPingPong, &client); - actions["cancel_after_begin"] = - std::bind(&grpc::testing::InteropClient::DoCancelAfterBegin, &client); - actions["cancel_after_first_response"] = std::bind( - &grpc::testing::InteropClient::DoCancelAfterFirstResponse, &client); - actions["timeout_on_sleeping_server"] = std::bind( - &grpc::testing::InteropClient::DoTimeoutOnSleepingServer, &client); - actions["empty_stream"] = - std::bind(&grpc::testing::InteropClient::DoEmptyStream, &client); - if (FLAGS_use_tls) { - actions["compute_engine_creds"] = - std::bind(&grpc::testing::InteropClient::DoComputeEngineCreds, &client, - FLAGS_default_service_account, FLAGS_oauth_scope); - actions["jwt_token_creds"] = - std::bind(&grpc::testing::InteropClient::DoJwtTokenCreds, &client, - GetServiceAccountJsonKey()); - actions["oauth2_auth_token"] = - std::bind(&grpc::testing::InteropClient::DoOauth2AuthToken, &client, - FLAGS_default_service_account, FLAGS_oauth_scope); - actions["per_rpc_creds"] = - std::bind(&grpc::testing::InteropClient::DoPerRpcCreds, &client, - GetServiceAccountJsonKey()); - } - actions["status_code_and_message"] = - std::bind(&grpc::testing::InteropClient::DoStatusWithMessage, &client); - actions["custom_metadata"] = - std::bind(&grpc::testing::InteropClient::DoCustomMetadata, &client); - actions["unimplemented_method"] = - std::bind(&grpc::testing::InteropClient::DoUnimplementedMethod, &client); - actions["unimplemented_service"] = - std::bind(&grpc::testing::InteropClient::DoUnimplementedService, &client); - // actions["cacheable_unary"] = - // std::bind(&grpc::testing::InteropClient::DoCacheableUnary, &client); - - if (FLAGS_test_case == "all") { - for (const auto& action : actions) { - action.second(); + if (FLAGS_test_case == "empty_unary") { + client.DoEmpty(); + } else if (FLAGS_test_case == "large_unary") { + client.DoLargeUnary(); + } else if (FLAGS_test_case == "server_compressed_unary") { + client.DoServerCompressedUnary(); + } else if (FLAGS_test_case == "client_compressed_unary") { + client.DoClientCompressedUnary(); + } else if (FLAGS_test_case == "client_streaming") { + client.DoRequestStreaming(); + } else if (FLAGS_test_case == "server_streaming") { + client.DoResponseStreaming(); + } else if (FLAGS_test_case == "server_compressed_streaming") { + client.DoServerCompressedStreaming(); + } else if (FLAGS_test_case == "client_compressed_streaming") { + client.DoClientCompressedStreaming(); + } else if (FLAGS_test_case == "slow_consumer") { + client.DoResponseStreamingWithSlowConsumer(); + } else if (FLAGS_test_case == "half_duplex") { + client.DoHalfDuplex(); + } else if (FLAGS_test_case == "ping_pong") { + client.DoPingPong(); + } else if (FLAGS_test_case == "cancel_after_begin") { + 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 == "empty_stream") { + client.DoEmptyStream(); + } else if (FLAGS_test_case == "compute_engine_creds") { + client.DoComputeEngineCreds(FLAGS_default_service_account, + FLAGS_oauth_scope); + } else if (FLAGS_test_case == "jwt_token_creds") { + grpc::string json_key = GetServiceAccountJsonKey(); + client.DoJwtTokenCreds(json_key); + } else if (FLAGS_test_case == "oauth2_auth_token") { + client.DoOauth2AuthToken(FLAGS_default_service_account, FLAGS_oauth_scope); + } else if (FLAGS_test_case == "per_rpc_creds") { + grpc::string json_key = GetServiceAccountJsonKey(); + client.DoPerRpcCreds(json_key); + } else if (FLAGS_test_case == "status_code_and_message") { + 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 == "unimplemented_service") { + client.DoUnimplementedService(); + } else if (FLAGS_test_case == "cacheable_unary") { + client.DoCacheableUnary(); + } else if (FLAGS_test_case == "all") { + client.DoEmpty(); + client.DoLargeUnary(); + client.DoClientCompressedUnary(); + client.DoServerCompressedUnary(); + client.DoRequestStreaming(); + client.DoResponseStreaming(); + client.DoClientCompressedStreaming(); + client.DoServerCompressedStreaming(); + client.DoHalfDuplex(); + client.DoPingPong(); + client.DoCancelAfterBegin(); + client.DoCancelAfterFirstResponse(); + client.DoTimeoutOnSleepingServer(); + client.DoEmptyStream(); + client.DoStatusWithMessage(); + client.DoCustomMetadata(); + client.DoUnimplementedMethod(); + client.DoUnimplementedService(); + client.DoCacheableUnary(); + // service_account_creds and jwt_token_creds can only run with ssl. + if (FLAGS_use_tls) { + grpc::string json_key = GetServiceAccountJsonKey(); + client.DoJwtTokenCreds(json_key); + client.DoOauth2AuthToken(FLAGS_default_service_account, + FLAGS_oauth_scope); + client.DoPerRpcCreds(json_key); } - } else if (actions.find(FLAGS_test_case) != actions.end()) { - actions.find(FLAGS_test_case)->second(); + // compute_engine_creds only runs in GCE. } else { - grpc::string test_cases; - for (const auto& action : actions) { - if (!test_cases.empty()) test_cases += "\n"; - test_cases += action.first; - } + const char* testcases[] = {"all", + "cacheable_unary", + "cancel_after_begin", + "cancel_after_first_response", + "client_compressed_streaming", + "client_compressed_unary", + "client_streaming", + "compute_engine_creds", + "custom_metadata", + "empty_stream", + "empty_unary", + "half_duplex", + "jwt_token_creds", + "large_unary", + "oauth2_auth_token", + "oauth2_auth_token", + "per_rpc_creds", + "per_rpc_creds", + "ping_pong", + "server_compressed_streaming", + "server_compressed_unary", + "server_streaming", + "status_code_and_message", + "timeout_on_sleeping_server", + "unimplemented_method", + "unimplemented_service"}; + char* joined_testcases = + gpr_strjoin_sep(testcases, GPR_ARRAY_SIZE(testcases), "\n", NULL); + gpr_log(GPR_ERROR, "Unsupported test case %s. Valid options are\n%s", - FLAGS_test_case.c_str(), test_cases.c_str()); + FLAGS_test_case.c_str(), joined_testcases); + gpr_free(joined_testcases); ret = 1; } diff --git a/test/cpp/interop/interop_client.cc b/test/cpp/interop/interop_client.cc index aa34d94f61..d1242627ef 100644 --- a/test/cpp/interop/interop_client.cc +++ b/test/cpp/interop/interop_client.cc @@ -109,10 +109,7 @@ TestService::Stub* InteropClient::ServiceStub::Get() { UnimplementedService::Stub* InteropClient::ServiceStub::GetUnimplementedServiceStub() { - if (unimplemented_service_stub_ == nullptr) { - unimplemented_service_stub_ = UnimplementedService::NewStub(channel_); - } - return unimplemented_service_stub_.get(); + return UnimplementedService::NewStub(channel_).get(); } void InteropClient::ServiceStub::Reset(std::shared_ptr<Channel> channel) { @@ -946,7 +943,7 @@ bool InteropClient::DoCustomMetadata() { const auto& server_initial_metadata = context.GetServerInitialMetadata(); auto iter = server_initial_metadata.find(kEchoInitialMetadataKey); GPR_ASSERT(iter != server_initial_metadata.end()); - GPR_ASSERT(iter->second == kInitialMetadataValue); + GPR_ASSERT(iter->second.data() == kInitialMetadataValue); const auto& server_trailing_metadata = context.GetServerTrailingMetadata(); iter = server_trailing_metadata.find(kEchoTrailingBinMetadataKey); GPR_ASSERT(iter != server_trailing_metadata.end()); @@ -997,7 +994,7 @@ bool InteropClient::DoCustomMetadata() { const auto& server_initial_metadata = context.GetServerInitialMetadata(); auto iter = server_initial_metadata.find(kEchoInitialMetadataKey); GPR_ASSERT(iter != server_initial_metadata.end()); - GPR_ASSERT(iter->second == kInitialMetadataValue); + GPR_ASSERT(iter->second.data() == kInitialMetadataValue); const auto& server_trailing_metadata = context.GetServerTrailingMetadata(); iter = server_trailing_metadata.find(kEchoTrailingBinMetadataKey); GPR_ASSERT(iter != server_trailing_metadata.end()); diff --git a/test/cpp/interop/interop_client.h b/test/cpp/interop/interop_client.h index 74f4db6b78..7ec7ebee20 100644 --- a/test/cpp/interop/interop_client.h +++ b/test/cpp/interop/interop_client.h @@ -107,7 +107,6 @@ class InteropClient { private: std::unique_ptr<TestService::Stub> stub_; - std::unique_ptr<UnimplementedService::Stub> unimplemented_service_stub_; std::shared_ptr<Channel> channel_; bool new_stub_every_call_; // If true, a new stub is returned by every // Get() call diff --git a/test/cpp/interop/interop_server.cc b/test/cpp/interop/interop_server.cc index 1810cd076f..956840ba70 100644 --- a/test/cpp/interop/interop_server.cc +++ b/test/cpp/interop/interop_server.cc @@ -91,9 +91,7 @@ void MaybeEchoMetadata(ServerContext* context) { auto iter = client_metadata.find(kEchoInitialMetadataKey); if (iter != client_metadata.end()) { - context->AddInitialMetadata( - kEchoInitialMetadataKey, - grpc::string(iter->second.begin(), iter->second.end())); + context->AddInitialMetadata(kEchoInitialMetadataKey, iter->second.data()); } iter = client_metadata.find(kEchoTrailingBinMetadataKey); if (iter != client_metadata.end()) { diff --git a/test/cpp/test/server_context_test_spouse_test.cc b/test/cpp/test/server_context_test_spouse_test.cc index eb279e2401..e0d6a2ff67 100644 --- a/test/cpp/test/server_context_test_spouse_test.cc +++ b/test/cpp/test/server_context_test_spouse_test.cc @@ -36,14 +36,11 @@ #include <cstring> #include <vector> -#include <grpc++/impl/grpc_library.h> #include <gtest/gtest.h> namespace grpc { namespace testing { -static internal::GrpcLibraryInitializer g_initializer; - const char key1[] = "metadata-key1"; const char key2[] = "metadata-key2"; const char val1[] = "metadata-val1"; |