@ -14,6 +14,8 @@
// limitations under the License.
//
# include "src/core/load_balancing/pick_first/pick_first.h"
# include <stddef.h>
# include <algorithm>
@ -54,7 +56,8 @@ namespace {
class PickFirstTest : public LoadBalancingPolicyTest {
protected :
PickFirstTest ( ) : LoadBalancingPolicyTest ( " pick_first " ) { }
explicit PickFirstTest ( ChannelArgs channel_args = ChannelArgs ( ) )
: LoadBalancingPolicyTest ( " pick_first " , channel_args ) { }
void SetUp ( ) override {
LoadBalancingPolicyTest : : SetUp ( ) ;
@ -1103,6 +1106,49 @@ TEST_F(PickFirstTest, ShufflingDisabled) {
EXPECT_THAT ( address_order , : : testing : : ElementsAreArray ( kAddresses ) ) ;
}
}
class PickFirstHealthCheckingEnabledTest : public PickFirstTest {
protected :
PickFirstHealthCheckingEnabledTest ( )
: PickFirstTest ( ChannelArgs ( ) . Set (
GRPC_ARG_INTERNAL_PICK_FIRST_ENABLE_HEALTH_CHECKING , true ) ) { }
} ;
TEST_F ( PickFirstHealthCheckingEnabledTest , UpdateWithReadyChannel ) {
constexpr absl : : string_view kAddress = " ipv4:127.0.0.1:443 " ;
LoadBalancingPolicy : : UpdateArgs update =
BuildUpdate ( { kAddress } , MakePickFirstConfig ( ) ) ;
absl : : Status status = ApplyUpdate ( update , lb_policy ( ) ) ;
EXPECT_TRUE ( status . ok ( ) ) < < status ;
// LB policy should have created a subchannel for the address.
auto * subchannel = FindSubchannel ( kAddress ) ;
ASSERT_NE ( subchannel , nullptr ) ;
// When the LB policy receives the first subchannel's initial connectivity
// state notification (IDLE), it will request a connection.
EXPECT_TRUE ( subchannel - > ConnectionRequested ( ) ) ;
// This causes the subchannel to start to connect, so it reports CONNECTING.
subchannel - > SetConnectivityState ( GRPC_CHANNEL_CONNECTING ) ;
// LB policy should have reported CONNECTING state.
ExpectConnectingUpdate ( ) ;
// When the subchannel becomes connected, it reports READY.
subchannel - > SetConnectivityState ( GRPC_CHANNEL_READY ) ;
// The LB policy will report CONNECTING some number of times (doesn't
// matter how many) and then report READY.
auto picker = WaitForConnected ( ) ;
ASSERT_NE ( picker , nullptr ) ;
EXPECT_EQ ( ExpectPickComplete ( picker . get ( ) ) , kAddress ) ;
// Reapply the same update we did before. The the underlying
// subchannel will immediately become ready.
status =
ApplyUpdate ( BuildUpdate ( { kAddress } , MakePickFirstConfig ( ) ) , lb_policy ( ) ) ;
EXPECT_TRUE ( status . ok ( ) ) < < status ;
picker = ExpectState ( GRPC_CHANNEL_READY ) ;
EXPECT_EQ ( ExpectPickComplete ( picker . get ( ) ) , kAddress ) ;
// At this point, NumWatchers() should account for our
// subchannel connectivity watcher and our health watcher.
EXPECT_EQ ( subchannel - > NumWatchers ( ) , 2 ) ;
}
} // namespace
} // namespace testing
} // namespace grpc_core