|
|
@ -42,6 +42,9 @@ |
|
|
|
#include "src/core/lib/gprpp/debug_location.h" |
|
|
|
#include "src/core/lib/gprpp/debug_location.h" |
|
|
|
#include "src/core/lib/gprpp/ref_counted_ptr.h" |
|
|
|
#include "src/core/lib/gprpp/ref_counted_ptr.h" |
|
|
|
#include "src/core/lib/iomgr/tcp_client.h" |
|
|
|
#include "src/core/lib/iomgr/tcp_client.h" |
|
|
|
|
|
|
|
#include "src/core/lib/security/credentials/fake/fake_credentials.h" |
|
|
|
|
|
|
|
#include "src/cpp/client/secure_credentials.h" |
|
|
|
|
|
|
|
#include "src/cpp/server/secure_server_credentials.h" |
|
|
|
|
|
|
|
|
|
|
|
#include "src/proto/grpc/testing/echo.grpc.pb.h" |
|
|
|
#include "src/proto/grpc/testing/echo.grpc.pb.h" |
|
|
|
#include "test/core/util/port.h" |
|
|
|
#include "test/core/util/port.h" |
|
|
@ -207,19 +210,22 @@ class ClientLbEnd2endTest : public ::testing::Test { |
|
|
|
} // else, default to pick first
|
|
|
|
} // else, default to pick first
|
|
|
|
args.SetPointer(GRPC_ARG_FAKE_RESOLVER_RESPONSE_GENERATOR, |
|
|
|
args.SetPointer(GRPC_ARG_FAKE_RESOLVER_RESPONSE_GENERATOR, |
|
|
|
response_generator_.get()); |
|
|
|
response_generator_.get()); |
|
|
|
return CreateCustomChannel("fake:///", InsecureChannelCredentials(), args); |
|
|
|
std::shared_ptr<ChannelCredentials> creds(new SecureChannelCredentials( |
|
|
|
|
|
|
|
grpc_fake_transport_security_credentials_create())); |
|
|
|
|
|
|
|
return CreateCustomChannel("fake:///", std::move(creds), args); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool SendRpc( |
|
|
|
bool SendRpc( |
|
|
|
const std::unique_ptr<grpc::testing::EchoTestService::Stub>& stub, |
|
|
|
const std::unique_ptr<grpc::testing::EchoTestService::Stub>& stub, |
|
|
|
EchoResponse* response = nullptr, int timeout_ms = 1000, |
|
|
|
EchoResponse* response = nullptr, int timeout_ms = 1000, |
|
|
|
Status* result = nullptr) { |
|
|
|
Status* result = nullptr, bool wait_for_ready = false) { |
|
|
|
const bool local_response = (response == nullptr); |
|
|
|
const bool local_response = (response == nullptr); |
|
|
|
if (local_response) response = new EchoResponse; |
|
|
|
if (local_response) response = new EchoResponse; |
|
|
|
EchoRequest request; |
|
|
|
EchoRequest request; |
|
|
|
request.set_message(kRequestMessage_); |
|
|
|
request.set_message(kRequestMessage_); |
|
|
|
ClientContext context; |
|
|
|
ClientContext context; |
|
|
|
context.set_deadline(grpc_timeout_milliseconds_to_deadline(timeout_ms)); |
|
|
|
context.set_deadline(grpc_timeout_milliseconds_to_deadline(timeout_ms)); |
|
|
|
|
|
|
|
if (wait_for_ready) context.set_wait_for_ready(true); |
|
|
|
Status status = stub->Echo(&context, request, response); |
|
|
|
Status status = stub->Echo(&context, request, response); |
|
|
|
if (result != nullptr) *result = status; |
|
|
|
if (result != nullptr) *result = status; |
|
|
|
if (local_response) delete response; |
|
|
|
if (local_response) delete response; |
|
|
@ -228,10 +234,11 @@ class ClientLbEnd2endTest : public ::testing::Test { |
|
|
|
|
|
|
|
|
|
|
|
void CheckRpcSendOk( |
|
|
|
void CheckRpcSendOk( |
|
|
|
const std::unique_ptr<grpc::testing::EchoTestService::Stub>& stub, |
|
|
|
const std::unique_ptr<grpc::testing::EchoTestService::Stub>& stub, |
|
|
|
const grpc_core::DebugLocation& location) { |
|
|
|
const grpc_core::DebugLocation& location, bool wait_for_ready = false) { |
|
|
|
EchoResponse response; |
|
|
|
EchoResponse response; |
|
|
|
Status status; |
|
|
|
Status status; |
|
|
|
const bool success = SendRpc(stub, &response, 2000, &status); |
|
|
|
const bool success = |
|
|
|
|
|
|
|
SendRpc(stub, &response, 2000, &status, wait_for_ready); |
|
|
|
ASSERT_TRUE(success) << "From " << location.file() << ":" << location.line() |
|
|
|
ASSERT_TRUE(success) << "From " << location.file() << ":" << location.line() |
|
|
|
<< "\n" |
|
|
|
<< "\n" |
|
|
|
<< "Error: " << status.error_message() << " " |
|
|
|
<< "Error: " << status.error_message() << " " |
|
|
@ -275,8 +282,9 @@ class ClientLbEnd2endTest : public ::testing::Test { |
|
|
|
std::ostringstream server_address; |
|
|
|
std::ostringstream server_address; |
|
|
|
server_address << server_host << ":" << port_; |
|
|
|
server_address << server_host << ":" << port_; |
|
|
|
ServerBuilder builder; |
|
|
|
ServerBuilder builder; |
|
|
|
builder.AddListeningPort(server_address.str(), |
|
|
|
std::shared_ptr<ServerCredentials> creds(new SecureServerCredentials( |
|
|
|
InsecureServerCredentials()); |
|
|
|
grpc_fake_transport_security_server_credentials_create())); |
|
|
|
|
|
|
|
builder.AddListeningPort(server_address.str(), std::move(creds)); |
|
|
|
builder.RegisterService(&service_); |
|
|
|
builder.RegisterService(&service_); |
|
|
|
server_ = builder.BuildAndStart(); |
|
|
|
server_ = builder.BuildAndStart(); |
|
|
|
std::lock_guard<std::mutex> lock(*mu); |
|
|
|
std::lock_guard<std::mutex> lock(*mu); |
|
|
@ -306,7 +314,7 @@ class ClientLbEnd2endTest : public ::testing::Test { |
|
|
|
if (ignore_failure) { |
|
|
|
if (ignore_failure) { |
|
|
|
SendRpc(stub); |
|
|
|
SendRpc(stub); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
CheckRpcSendOk(stub, location); |
|
|
|
CheckRpcSendOk(stub, location, true); |
|
|
|
} |
|
|
|
} |
|
|
|
} while (servers_[server_idx]->service_.request_count() == 0); |
|
|
|
} while (servers_[server_idx]->service_.request_count() == 0); |
|
|
|
ResetCounters(); |
|
|
|
ResetCounters(); |
|
|
@ -518,7 +526,7 @@ TEST_F(ClientLbEnd2endTest, PickFirstUpdates) { |
|
|
|
do { |
|
|
|
do { |
|
|
|
channel_state = channel->GetState(true /* try to connect */); |
|
|
|
channel_state = channel->GetState(true /* try to connect */); |
|
|
|
} while (channel_state == GRPC_CHANNEL_READY); |
|
|
|
} while (channel_state == GRPC_CHANNEL_READY); |
|
|
|
GPR_ASSERT(channel_state != GRPC_CHANNEL_READY); |
|
|
|
ASSERT_NE(channel_state, GRPC_CHANNEL_READY); |
|
|
|
servers_[0]->service_.ResetCounters(); |
|
|
|
servers_[0]->service_.ResetCounters(); |
|
|
|
|
|
|
|
|
|
|
|
// Next update introduces servers_[1], making the channel recover.
|
|
|
|
// Next update introduces servers_[1], making the channel recover.
|
|
|
@ -835,7 +843,7 @@ TEST_F(ClientLbEnd2endTest, RoundRobinUpdates) { |
|
|
|
do { |
|
|
|
do { |
|
|
|
channel_state = channel->GetState(true /* try to connect */); |
|
|
|
channel_state = channel->GetState(true /* try to connect */); |
|
|
|
} while (channel_state == GRPC_CHANNEL_READY); |
|
|
|
} while (channel_state == GRPC_CHANNEL_READY); |
|
|
|
GPR_ASSERT(channel_state != GRPC_CHANNEL_READY); |
|
|
|
ASSERT_NE(channel_state, GRPC_CHANNEL_READY); |
|
|
|
servers_[0]->service_.ResetCounters(); |
|
|
|
servers_[0]->service_.ResetCounters(); |
|
|
|
|
|
|
|
|
|
|
|
// Next update introduces servers_[1], making the channel recover.
|
|
|
|
// Next update introduces servers_[1], making the channel recover.
|
|
|
@ -844,7 +852,7 @@ TEST_F(ClientLbEnd2endTest, RoundRobinUpdates) { |
|
|
|
SetNextResolution(ports); |
|
|
|
SetNextResolution(ports); |
|
|
|
WaitForServer(stub, 1, DEBUG_LOCATION); |
|
|
|
WaitForServer(stub, 1, DEBUG_LOCATION); |
|
|
|
channel_state = channel->GetState(false /* try to connect */); |
|
|
|
channel_state = channel->GetState(false /* try to connect */); |
|
|
|
GPR_ASSERT(channel_state == GRPC_CHANNEL_READY); |
|
|
|
ASSERT_EQ(channel_state, GRPC_CHANNEL_READY); |
|
|
|
|
|
|
|
|
|
|
|
// Check LB policy name for the channel.
|
|
|
|
// Check LB policy name for the channel.
|
|
|
|
EXPECT_EQ("round_robin", channel->GetLoadBalancingPolicyName()); |
|
|
|
EXPECT_EQ("round_robin", channel->GetLoadBalancingPolicyName()); |
|
|
@ -954,7 +962,7 @@ TEST_F(ClientLbEnd2endTest, RoundRobinReresolve) { |
|
|
|
if (SendRpc(stub)) break; |
|
|
|
if (SendRpc(stub)) break; |
|
|
|
now = gpr_now(GPR_CLOCK_MONOTONIC); |
|
|
|
now = gpr_now(GPR_CLOCK_MONOTONIC); |
|
|
|
} |
|
|
|
} |
|
|
|
GPR_ASSERT(gpr_time_cmp(deadline, now) > 0); |
|
|
|
ASSERT_GT(gpr_time_cmp(deadline, now), 0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST_F(ClientLbEnd2endTest, RoundRobinSingleReconnect) { |
|
|
|
TEST_F(ClientLbEnd2endTest, RoundRobinSingleReconnect) { |
|
|
|