add pick_first_unary

pull/19482/head
Qixuan Li 6 years ago
parent 60ed718209
commit 0e85762b67
  1. 7
      src/proto/grpc/testing/messages.proto
  2. 2
      test/cpp/interop/client.cc
  3. 7
      test/cpp/interop/client_helper.cc
  4. 23
      test/cpp/interop/interop_client.cc
  5. 2
      test/cpp/interop/interop_client.h

@ -77,6 +77,9 @@ message SimpleRequest {
// Whether the server should expect this request to be compressed.
BoolValue expect_compressed = 8;
// Whether SimpleResponse should include server_id.
bool fill_server_id = 9;
}
// Unary response, as configured by the request.
@ -88,6 +91,10 @@ message SimpleResponse {
string username = 2;
// OAuth scope.
string oauth_scope = 3;
// Server ID. This must be unique among different server instances,
// but the same across all RPC's made to a particular server instance.
string server_id = 4;
}
// Client-streaming request.

@ -222,6 +222,8 @@ int main(int argc, char** argv) {
&grpc::testing::InteropClient::DoTimeoutOnSleepingServer, &client);
actions["empty_stream"] =
std::bind(&grpc::testing::InteropClient::DoEmptyStream, &client);
actions["pick_first_unary"] =
std::bind(&grpc::testing::InteropClient::DoPickFirstUnary, &client);
if (FLAGS_use_tls) {
actions["compute_engine_creds"] =
std::bind(&grpc::testing::InteropClient::DoComputeEngineCreds, &client,

@ -105,6 +105,13 @@ std::shared_ptr<Channel> CreateChannelForTestCase(
creds = FLAGS_custom_credentials_type == "google_default_credentials"
? nullptr
: AccessTokenCredentials(GetOauth2AccessToken());
} else if (test_case == "pick_first_unary") {
ChannelArguments channel_args;
// force using pick first policy
channel_args.SetInt(GRPC_ARG_SERVICE_CONFIG_DISABLE_RESOLUTION, 0);
return CreateTestChannel(host_port, FLAGS_custom_credentials_type,
FLAGS_server_host_override, !FLAGS_use_test_ca,
creds, channel_args);
}
if (FLAGS_custom_credentials_type.empty()) {
transport_security security_type =

@ -948,6 +948,29 @@ bool InteropClient::DoCacheableUnary() {
return true;
}
bool InteropClient::DoPickFirstUnary() {
const int rpcCount = 100;
SimpleRequest request;
SimpleResponse response;
std::string first_server_id;
request.set_fill_server_id(true);
for (int i = 0; i < rpcCount; i++) {
ClientContext context;
Status s = serviceStub_.Get()->UnaryCall(&context, request, &response);
if (!AssertStatusOk(s, context.debug_error_string())) {
return false;
}
if (i == 0) {
first_server_id = response.server_id();
gpr_log(GPR_DEBUG, "first_user_id is %s", first_server_id.c_str());
continue;
}
GPR_ASSERT(response.server_id() == first_server_id);
}
gpr_log(GPR_DEBUG, "pick first unary successfully finished");
return true;
}
bool InteropClient::DoCustomMetadata() {
const grpc::string kEchoInitialMetadataKey("x-grpc-test-echo-initial");
const grpc::string kInitialMetadataValue("test_initial_metadata_value");

@ -69,6 +69,8 @@ class InteropClient {
bool DoUnimplementedMethod();
bool DoUnimplementedService();
bool DoCacheableUnary();
// all requests are sent to one server despite multiple servers are resolved
bool DoPickFirstUnary();
// The following interop test are not yet part of the interop spec, and are
// not implemented cross-language. They are considered experimental for now,

Loading…
Cancel
Save