Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clusterimpl: use gsb.UpdateClientConnState instead of switchTo, on receipt of config update #7567

Merged
merged 5 commits into from
Sep 19, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: refactor and make the code clean
  • Loading branch information
aranjans committed Sep 18, 2024
commit 916db13e7a2c80066434f7bee37957d5be8a4651
25 changes: 4 additions & 21 deletions xds/internal/balancer/clusterimpl/balancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,6 @@ func (s) TestUpdateLRSServer(t *testing.T) {
// Test verifies that child policies was updated on receipt of
easwars marked this conversation as resolved.
Show resolved Hide resolved
// configuration update.
func (s) TestChildPolicyUpdatedOnConfigUpdate(t *testing.T) {
defer xdsclient.ClearCounterForTesting(testClusterName, testServiceName)
xdsC := fakeclient.NewClient()

builder := balancer.Get(Name)
Expand All @@ -864,19 +863,13 @@ func (s) TestChildPolicyUpdatedOnConfigUpdate(t *testing.T) {
stub.Register(childPolicyName1, stub.BalancerFuncs{
UpdateClientConnState: func(bd *stub.BalancerData, ccs balancer.ClientConnState) error {
updatedChildPolicy = childPolicyName1
bd.ClientConn.UpdateState(balancer.State{
Picker: base.NewErrPicker(errors.New("dummy error picker")),
})
return nil
},
})

stub.Register(childPolicyName2, stub.BalancerFuncs{
UpdateClientConnState: func(bd *stub.BalancerData, ccs balancer.ClientConnState) error {
updatedChildPolicy = childPolicyName2
bd.ClientConn.UpdateState(balancer.State{
Picker: base.NewErrPicker(errors.New("dummy error picker")),
})
return nil
},
})
Expand All @@ -885,8 +878,7 @@ func (s) TestChildPolicyUpdatedOnConfigUpdate(t *testing.T) {
if err := b.UpdateClientConnState(balancer.ClientConnState{
ResolverState: xdsclient.SetClient(resolver.State{Addresses: testBackendAddrs}, xdsC),
BalancerConfig: &LBConfig{
Cluster: testClusterName,
EDSServiceName: testServiceName,
Cluster: testClusterName,
ChildPolicy: &internalserviceconfig.BalancerConfig{
Name: childPolicyName1,
},
Expand All @@ -903,8 +895,7 @@ func (s) TestChildPolicyUpdatedOnConfigUpdate(t *testing.T) {
if err := b.UpdateClientConnState(balancer.ClientConnState{
easwars marked this conversation as resolved.
Show resolved Hide resolved
ResolverState: xdsclient.SetClient(resolver.State{Addresses: testBackendAddrs}, xdsC),
BalancerConfig: &LBConfig{
Cluster: testClusterName,
EDSServiceName: testServiceName,
Cluster: testClusterName,
ChildPolicy: &internalserviceconfig.BalancerConfig{
Name: childPolicyName2,
},
Expand All @@ -921,7 +912,6 @@ func (s) TestChildPolicyUpdatedOnConfigUpdate(t *testing.T) {
// Test verifies that config update fails if child policy config
// failed to parse.
func (s) TestFailedToParseChildPolicyConfig(t *testing.T) {
easwars marked this conversation as resolved.
Show resolved Hide resolved
defer xdsclient.ClearCounterForTesting(testClusterName, testServiceName)
xdsC := fakeclient.NewClient()

builder := balancer.Get(Name)
Expand All @@ -933,12 +923,6 @@ func (s) TestFailedToParseChildPolicyConfig(t *testing.T) {
const parseConfigError = "failed to parse config"
const childPolicyName = "stubBalancer-FailedToParseChildPolicyConfig"
stub.Register(childPolicyName, stub.BalancerFuncs{
UpdateClientConnState: func(bd *stub.BalancerData, ccs balancer.ClientConnState) error {
bd.ClientConn.UpdateState(balancer.State{
Picker: base.NewErrPicker(errors.New("dummy error picker")),
})
return nil
},
ParseConfig: func(lbCfg json.RawMessage) (serviceconfig.LoadBalancingConfig, error) {
return nil, errors.New(parseConfigError)
},
Expand All @@ -947,16 +931,15 @@ func (s) TestFailedToParseChildPolicyConfig(t *testing.T) {
err := b.UpdateClientConnState(balancer.ClientConnState{
ResolverState: xdsclient.SetClient(resolver.State{Addresses: testBackendAddrs}, xdsC),
BalancerConfig: &LBConfig{
Cluster: testClusterName,
EDSServiceName: testServiceName,
Cluster: testClusterName,
ChildPolicy: &internalserviceconfig.BalancerConfig{
Name: childPolicyName,
},
},
})

if err == nil || !strings.Contains(err.Error(), parseConfigError) {
t.Errorf("Got error: %v, want error: parsed config to fail.", err)
t.Fatalf("Got error: %v, want error: %s", err, parseConfigError)
}
}

Expand Down