Skip to content

Commit

Permalink
Merge pull request #18141 from markdroth/resolver_connectivity_state
Browse files Browse the repository at this point in the history
Transition into state CONNECTING when we start name resolution
  • Loading branch information
markdroth committed Feb 22, 2019
2 parents d6e8c4f + 428fa76 commit d7fe3b0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/core/ext/filters/client_channel/resolving_lb_policy.cc
Expand Up @@ -218,6 +218,9 @@ void ResolvingLoadBalancingPolicy::StartResolvingLocked() {
}
GPR_ASSERT(!started_resolving_);
started_resolving_ = true;
channel_control_helper()->UpdateState(
GRPC_CHANNEL_CONNECTING, GRPC_ERROR_NONE,
UniquePtr<SubchannelPicker>(New<QueuePicker>(Ref())));
Ref().release();
resolver_->NextLocked(&resolver_result_, &on_resolver_result_changed_);
}
Expand Down
21 changes: 21 additions & 0 deletions test/cpp/end2end/client_lb_end2end_test.cc
Expand Up @@ -402,6 +402,27 @@ class ClientLbEnd2endTest : public ::testing::Test {
std::shared_ptr<ChannelCredentials> creds_;
};

TEST_F(ClientLbEnd2endTest, ChannelStateConnectingWhenResolving) {
const int kNumServers = 3;
StartServers(kNumServers);
auto channel = BuildChannel("");
auto stub = BuildStub(channel);
// Initial state should be IDLE.
EXPECT_EQ(channel->GetState(false /* try_to_connect */), GRPC_CHANNEL_IDLE);
// Tell the channel to try to connect.
// Note that this call also returns IDLE, since the state change has
// not yet occurred; it just gets triggered by this call.
EXPECT_EQ(channel->GetState(true /* try_to_connect */), GRPC_CHANNEL_IDLE);
// Now that the channel is trying to connect, we should be in state
// CONNECTING.
EXPECT_EQ(channel->GetState(false /* try_to_connect */),
GRPC_CHANNEL_CONNECTING);
// Return a resolver result, which allows the connection attempt to proceed.
SetNextResolution(GetServersPorts());
// We should eventually transition into state READY.
EXPECT_TRUE(WaitForChannelReady(channel.get()));
}

TEST_F(ClientLbEnd2endTest, PickFirst) {
// Start servers and send one RPC per server.
const int kNumServers = 3;
Expand Down

0 comments on commit d7fe3b0

Please sign in to comment.