Fix interop

reviewable/pr8842/r4
Craig Tiller 8 years ago
parent 296c7bb8fa
commit f3ed2bf8ca
  1. 178
      test/cpp/interop/client.cc
  2. 9
      test/cpp/interop/interop_client.cc
  3. 1
      test/cpp/interop/interop_client.h
  4. 2
      test/cpp/interop/interop_server.cc

@ -32,6 +32,7 @@
*/
#include <memory>
#include <unordered_map>
#include <unistd.h>
@ -107,119 +108,78 @@ int main(int argc, char** argv) {
grpc::testing::InteropClient client(CreateChannelForTestCase(FLAGS_test_case),
true,
FLAGS_do_not_abort_on_transient_failures);
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.
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) {
grpc::string json_key = GetServiceAccountJsonKey();
client.DoJwtTokenCreds(json_key);
client.DoOauth2AuthToken(FLAGS_default_service_account,
FLAGS_oauth_scope);
client.DoPerRpcCreds(json_key);
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());
}
// compute_engine_creds only runs in GCE.
} else {
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);
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();
}
} else if (actions.find(FLAGS_test_case) != actions.end()) {
actions.find(FLAGS_test_case)->second();
} else {
grpc::string test_cases;
for (const auto& action : actions) {
if (!test_cases.empty()) test_cases += "\n";
test_cases += action.first;
}
gpr_log(GPR_ERROR, "Unsupported test case %s. Valid options are\n%s",
FLAGS_test_case.c_str(), joined_testcases);
gpr_free(joined_testcases);
FLAGS_test_case.c_str(), test_cases.c_str());
ret = 1;
}

@ -109,7 +109,10 @@ TestService::Stub* InteropClient::ServiceStub::Get() {
UnimplementedService::Stub*
InteropClient::ServiceStub::GetUnimplementedServiceStub() {
return UnimplementedService::NewStub(channel_).get();
if (unimplemented_service_stub_ == nullptr) {
unimplemented_service_stub_ = UnimplementedService::NewStub(channel_);
}
return unimplemented_service_stub_.get();
}
void InteropClient::ServiceStub::Reset(std::shared_ptr<Channel> channel) {
@ -943,7 +946,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.data() == kInitialMetadataValue);
GPR_ASSERT(iter->second == kInitialMetadataValue);
const auto& server_trailing_metadata = context.GetServerTrailingMetadata();
iter = server_trailing_metadata.find(kEchoTrailingBinMetadataKey);
GPR_ASSERT(iter != server_trailing_metadata.end());
@ -994,7 +997,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.data() == kInitialMetadataValue);
GPR_ASSERT(iter->second == kInitialMetadataValue);
const auto& server_trailing_metadata = context.GetServerTrailingMetadata();
iter = server_trailing_metadata.find(kEchoTrailingBinMetadataKey);
GPR_ASSERT(iter != server_trailing_metadata.end());

@ -107,6 +107,7 @@ 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

@ -90,7 +90,7 @@ void MaybeEchoMetadata(ServerContext* context) {
auto iter = client_metadata.find(kEchoInitialMetadataKey);
if (iter != client_metadata.end()) {
context->AddInitialMetadata(kEchoInitialMetadataKey, iter->second.data());
context->AddInitialMetadata(kEchoInitialMetadataKey, grpc::string(iter->second.begin(), iter->second.end()));
}
iter = client_metadata.find(kEchoTrailingBinMetadataKey);
if (iter != client_metadata.end()) {

Loading…
Cancel
Save