Skip to content

Commit

Permalink
cdsbalancer: test cleanup part 1/N (#6546)
Browse files Browse the repository at this point in the history
  • Loading branch information
easwars authored Aug 17, 2023
1 parent 33f9fa2 commit b07bf5d
Show file tree
Hide file tree
Showing 6 changed files with 953 additions and 549 deletions.
10 changes: 10 additions & 0 deletions internal/testutils/xds/e2e/clientresources.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,9 @@ type ClusterOptions struct {
Policy LoadBalancingPolicy
// SecurityLevel determines the security configuration for the Cluster.
SecurityLevel SecurityLevel
// EnableLRS adds a load reporting configuration with a config source
// pointing to self.
EnableLRS bool
}

// ClusterResourceWithOptions returns an xDS Cluster resource configured with
Expand Down Expand Up @@ -521,6 +524,13 @@ func ClusterResourceWithOptions(opts ClusterOptions) *v3clusterpb.Cluster {
},
}
}
if opts.EnableLRS {
cluster.LrsServer = &v3corepb.ConfigSource{
ConfigSourceSpecifier: &v3corepb.ConfigSource_Self{
Self: &v3corepb.SelfConfigSource{},
},
}
}
return cluster
}

Expand Down
17 changes: 12 additions & 5 deletions resolver/manual/manual.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ import (
// NewBuilderWithScheme creates a new test resolver builder with the given scheme.
func NewBuilderWithScheme(scheme string) *Resolver {
return &Resolver{
BuildCallback: func(resolver.Target, resolver.ClientConn, resolver.BuildOptions) {},
ResolveNowCallback: func(resolver.ResolveNowOptions) {},
CloseCallback: func() {},
scheme: scheme,
BuildCallback: func(resolver.Target, resolver.ClientConn, resolver.BuildOptions) {},
UpdateStateCallback: func(error) {},
ResolveNowCallback: func(resolver.ResolveNowOptions) {},
CloseCallback: func() {},
scheme: scheme,
}
}

Expand All @@ -42,6 +43,11 @@ type Resolver struct {
// BuildCallback is called when the Build method is called. Must not be
// nil. Must not be changed after the resolver may be built.
BuildCallback func(resolver.Target, resolver.ClientConn, resolver.BuildOptions)
// UpdateStateCallback is called when the UpdateState method is called on
// the resolver. The value passed as argument to this callback is the value
// returned by the resolver.ClientConn. Must not be nil. Must not be
// changed after the resolver may be built.
UpdateStateCallback func(err error)
// ResolveNowCallback is called when the ResolveNow method is called on the
// resolver. Must not be nil. Must not be changed after the resolver may
// be built.
Expand Down Expand Up @@ -93,8 +99,9 @@ func (r *Resolver) Close() {
// UpdateState calls CC.UpdateState.
func (r *Resolver) UpdateState(s resolver.State) {
r.mu.Lock()
r.CC.UpdateState(s)
err := r.CC.UpdateState(s)
r.mu.Unlock()
r.UpdateStateCallback(err)
}

// ReportError calls CC.ReportError.
Expand Down
2 changes: 1 addition & 1 deletion xds/internal/balancer/cdsbalancer/cdsbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ func (b *cdsBalancer) handleWatchUpdate(update clusterHandlerUpdate) {

var sc serviceconfig.LoadBalancingConfig
if sc, err = b.crParser.ParseConfig(crLBCfgJSON); err != nil {
b.logger.Errorf("cds_balancer: cluster_resolver config generated %v is invalid: %v", crLBCfgJSON, err)
b.logger.Errorf("cds_balancer: cluster_resolver config generated %v is invalid: %v", string(crLBCfgJSON), err)
return
}

Expand Down
Loading

0 comments on commit b07bf5d

Please sign in to comment.