|
|
|
@ -129,12 +129,24 @@ class ClientLbEnd2endTest : public ::testing::Test { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void StartServers(size_t num_servers, |
|
|
|
|
std::vector<int> ports = std::vector<int>()) { |
|
|
|
|
void CreateServers(size_t num_servers, |
|
|
|
|
std::vector<int> ports = std::vector<int>()) { |
|
|
|
|
for (size_t i = 0; i < num_servers; ++i) { |
|
|
|
|
int port = 0; |
|
|
|
|
if (ports.size() == num_servers) port = ports[i]; |
|
|
|
|
servers_.emplace_back(new ServerData(server_host_, port)); |
|
|
|
|
servers_.emplace_back(new ServerData(port)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void StartServer(size_t index) { |
|
|
|
|
servers_[index]->Start(server_host_); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void StartServers(size_t num_servers, |
|
|
|
|
std::vector<int> ports = std::vector<int>()) { |
|
|
|
|
if (servers_.empty()) CreateServers(num_servers, ports); |
|
|
|
|
for (size_t i = 0; i < num_servers; ++i) { |
|
|
|
|
StartServer(i); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -240,20 +252,23 @@ class ClientLbEnd2endTest : public ::testing::Test { |
|
|
|
|
std::unique_ptr<std::thread> thread_; |
|
|
|
|
bool server_ready_ = false; |
|
|
|
|
|
|
|
|
|
explicit ServerData(const grpc::string& server_host, int port = 0) { |
|
|
|
|
explicit ServerData(int port = 0) { |
|
|
|
|
port_ = port > 0 ? port : grpc_pick_unused_port_or_die(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Start(const grpc::string& server_host) { |
|
|
|
|
gpr_log(GPR_INFO, "starting server on port %d", port_); |
|
|
|
|
std::mutex mu; |
|
|
|
|
std::unique_lock<std::mutex> lock(mu); |
|
|
|
|
std::condition_variable cond; |
|
|
|
|
thread_.reset(new std::thread( |
|
|
|
|
std::bind(&ServerData::Start, this, server_host, &mu, &cond))); |
|
|
|
|
std::bind(&ServerData::Serve, this, server_host, &mu, &cond))); |
|
|
|
|
cond.wait(lock, [this] { return server_ready_; }); |
|
|
|
|
server_ready_ = false; |
|
|
|
|
gpr_log(GPR_INFO, "server startup complete"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Start(const grpc::string& server_host, std::mutex* mu, |
|
|
|
|
void Serve(const grpc::string& server_host, std::mutex* mu, |
|
|
|
|
std::condition_variable* cond) { |
|
|
|
|
std::ostringstream server_address; |
|
|
|
|
server_address << server_host << ":" << port_; |
|
|
|
@ -601,6 +616,26 @@ TEST_F(ClientLbEnd2endTest, PickFirstReconnectWithoutNewResolverResult) { |
|
|
|
|
WaitForServer(stub, 0, DEBUG_LOCATION); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(ClientLbEnd2endTest, |
|
|
|
|
PickFirstReconnectWithoutNewResolverResultStartsFromTopOfList) { |
|
|
|
|
std::vector<int> ports = {grpc_pick_unused_port_or_die(), |
|
|
|
|
grpc_pick_unused_port_or_die()}; |
|
|
|
|
CreateServers(2, ports); |
|
|
|
|
StartServer(1); |
|
|
|
|
auto channel = BuildChannel("pick_first"); |
|
|
|
|
auto stub = BuildStub(channel); |
|
|
|
|
SetNextResolution(ports); |
|
|
|
|
gpr_log(GPR_INFO, "****** INITIAL CONNECTION *******"); |
|
|
|
|
WaitForServer(stub, 1, DEBUG_LOCATION); |
|
|
|
|
gpr_log(GPR_INFO, "****** STOPPING SERVER ******"); |
|
|
|
|
servers_[1]->Shutdown(); |
|
|
|
|
EXPECT_TRUE(WaitForChannelNotReady(channel.get())); |
|
|
|
|
gpr_log(GPR_INFO, "****** STARTING SERVER 0 ******"); |
|
|
|
|
servers_.clear(); |
|
|
|
|
StartServers(2, ports); |
|
|
|
|
WaitForServer(stub, 0, DEBUG_LOCATION); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(ClientLbEnd2endTest, PickFirstCheckStateBeforeStartWatch) { |
|
|
|
|
std::vector<int> ports = {grpc_pick_unused_port_or_die()}; |
|
|
|
|
StartServers(1, ports); |
|
|
|
@ -921,7 +956,8 @@ TEST_F(ClientLbEnd2endTest, RoundRobinSingleReconnect) { |
|
|
|
|
// No requests have gone to the deceased server.
|
|
|
|
|
EXPECT_EQ(pre_death, post_death); |
|
|
|
|
// Bring the first server back up.
|
|
|
|
|
servers_[0].reset(new ServerData(server_host_, ports[0])); |
|
|
|
|
servers_[0].reset(new ServerData(ports[0])); |
|
|
|
|
StartServer(0); |
|
|
|
|
// Requests should start arriving at the first server either right away (if
|
|
|
|
|
// the server managed to start before the RR policy retried the subchannel) or
|
|
|
|
|
// after the subchannel retry delay otherwise (RR's subchannel retried before
|
|
|
|
|