Skip to content

Commit eea79f9

Browse files
committed
re-add logic to verify that config is pushed only after the cluster graph is completely resolved
1 parent e341aad commit eea79f9

File tree

1 file changed

+57
-7
lines changed

1 file changed

+57
-7
lines changed

xds/internal/balancer/cdsbalancer/cluster_handler_test.go

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"google.golang.org/grpc"
2828
"google.golang.org/grpc/codes"
2929
"google.golang.org/grpc/connectivity"
30+
"google.golang.org/grpc/internal/pretty"
3031
"google.golang.org/grpc/internal/stubserver"
3132
"google.golang.org/grpc/internal/testutils"
3233
"google.golang.org/grpc/internal/testutils/xds/e2e"
@@ -170,13 +171,13 @@ func (s) TestAggregateClusterSuccess_ThenUpdateChildClusters(t *testing.T) {
170171
mgmtServer, nodeID, _, _, _, _, _ := setupWithManagementServer(t)
171172

172173
// Configure the management server with the aggregate cluster resource
173-
// pointing to two child clusters.
174+
// pointing to two child clusters. But don't include resource corresponding
175+
// to the LogicalDNS cluster yet.
174176
resources := e2e.UpdateOptions{
175177
NodeID: nodeID,
176178
Clusters: []*v3clusterpb.Cluster{
177179
makeAggregateClusterResource(clusterName, []string{edsClusterName, dnsClusterName}),
178180
e2e.DefaultCluster(edsClusterName, serviceName, e2e.SecurityLevelNone),
179-
makeLogicalDNSClusterResource(dnsClusterName, dnsHostName, dnsPort),
180181
},
181182
SkipValidation: true,
182183
}
@@ -186,6 +187,21 @@ func (s) TestAggregateClusterSuccess_ThenUpdateChildClusters(t *testing.T) {
186187
t.Fatal(err)
187188
}
188189

190+
// Verify that no configuration is pushed to the child policy yet, because
191+
// not all clusters making up the aggregate cluster have been resolved yet.
192+
select {
193+
case cfg := <-lbCfgCh:
194+
t.Fatalf("Child policy received configuration when not expected to: %s", pretty.ToJSON(cfg))
195+
case <-time.After(defaultTestShortTimeout):
196+
}
197+
198+
// Now configure the LogicalDNS cluster in the management server. This
199+
// should result in configuration being pushed down to the child policy.
200+
resources.Clusters = append(resources.Clusters, makeLogicalDNSClusterResource(dnsClusterName, dnsHostName, dnsPort))
201+
if err := mgmtServer.Update(ctx, resources); err != nil {
202+
t.Fatal(err)
203+
}
204+
189205
wantChildCfg := &clusterresolver.LBConfig{
190206
DiscoveryMechanisms: []clusterresolver.DiscoveryMechanism{
191207
{
@@ -510,7 +526,9 @@ func (s) TestAggregatedClusterSuccess_DiamondDependency(t *testing.T) {
510526
mgmtServer, nodeID, _, _, _, _, _ := setupWithManagementServer(t)
511527

512528
// Configure the management server with an aggregate cluster resource having
513-
// a diamond dependency pattern.
529+
// a diamond dependency pattern. Don't configure the resource for cluster C
530+
// yet. This will help us verify that no configuration is pushed to the
531+
// child policy until the whole cluster graph is resolved.
514532
const (
515533
clusterNameA = clusterName // cluster name in cds LB policy config
516534
clusterNameB = clusterName + "-B"
@@ -522,7 +540,6 @@ func (s) TestAggregatedClusterSuccess_DiamondDependency(t *testing.T) {
522540
Clusters: []*v3clusterpb.Cluster{
523541
makeAggregateClusterResource(clusterNameA, []string{clusterNameB, clusterNameC}),
524542
makeAggregateClusterResource(clusterNameB, []string{clusterNameD}),
525-
makeAggregateClusterResource(clusterNameC, []string{clusterNameD}),
526543
e2e.DefaultCluster(clusterNameD, serviceName, e2e.SecurityLevelNone),
527544
},
528545
SkipValidation: true,
@@ -533,6 +550,22 @@ func (s) TestAggregatedClusterSuccess_DiamondDependency(t *testing.T) {
533550
t.Fatal(err)
534551
}
535552

553+
// Verify that no configuration is pushed to the child policy yet, because
554+
// not all clusters making up the aggregate cluster have been resolved yet.
555+
select {
556+
case cfg := <-lbCfgCh:
557+
t.Fatalf("Child policy received configuration when not expected to: %s", pretty.ToJSON(cfg))
558+
case <-time.After(defaultTestShortTimeout):
559+
}
560+
561+
// Now configure the resource for cluster C in the management server,
562+
// thereby completing the cluster graph. This should result in configuration
563+
// being pushed down to the child policy.
564+
resources.Clusters = append(resources.Clusters, makeAggregateClusterResource(clusterNameC, []string{clusterNameD}))
565+
if err := mgmtServer.Update(ctx, resources); err != nil {
566+
t.Fatal(err)
567+
}
568+
536569
wantChildCfg := &clusterresolver.LBConfig{
537570
DiscoveryMechanisms: []clusterresolver.DiscoveryMechanism{{
538571
Cluster: clusterNameD,
@@ -557,7 +590,9 @@ func (s) TestAggregatedClusterSuccess_IgnoreDups(t *testing.T) {
557590
mgmtServer, nodeID, _, _, _, _, _ := setupWithManagementServer(t)
558591

559592
// Configure the management server with an aggregate cluster resource that
560-
// has duplicates in the graph.
593+
// has duplicates in the graph. Don't configure the resource for cluster C
594+
// yet. This will help us verify that no configuration is pushed to the
595+
// child policy until the whole cluster graph is resolved.
561596
const (
562597
clusterNameA = clusterName // cluster name in cds LB policy config
563598
clusterNameB = clusterName + "-B"
@@ -569,7 +604,6 @@ func (s) TestAggregatedClusterSuccess_IgnoreDups(t *testing.T) {
569604
Clusters: []*v3clusterpb.Cluster{
570605
makeAggregateClusterResource(clusterNameA, []string{clusterNameB, clusterNameC}),
571606
makeAggregateClusterResource(clusterNameB, []string{clusterNameC, clusterNameD}),
572-
e2e.DefaultCluster(clusterNameC, serviceName, e2e.SecurityLevelNone),
573607
e2e.DefaultCluster(clusterNameD, serviceName, e2e.SecurityLevelNone),
574608
},
575609
SkipValidation: true,
@@ -580,6 +614,22 @@ func (s) TestAggregatedClusterSuccess_IgnoreDups(t *testing.T) {
580614
t.Fatal(err)
581615
}
582616

617+
// Verify that no configuration is pushed to the child policy yet, because
618+
// not all clusters making up the aggregate cluster have been resolved yet.
619+
select {
620+
case cfg := <-lbCfgCh:
621+
t.Fatalf("Child policy received configuration when not expected to: %s", pretty.ToJSON(cfg))
622+
case <-time.After(defaultTestShortTimeout):
623+
}
624+
625+
// Now configure the resource for cluster C in the management server,
626+
// thereby completing the cluster graph. This should result in configuration
627+
// being pushed down to the child policy.
628+
resources.Clusters = append(resources.Clusters, e2e.DefaultCluster(clusterNameC, serviceName, e2e.SecurityLevelNone))
629+
if err := mgmtServer.Update(ctx, resources); err != nil {
630+
t.Fatal(err)
631+
}
632+
583633
wantChildCfg := &clusterresolver.LBConfig{
584634
DiscoveryMechanisms: []clusterresolver.DiscoveryMechanism{
585635
{
@@ -631,7 +681,7 @@ func (s) TestAggregatedCluster_NodeChildOfItself(t *testing.T) {
631681

632682
select {
633683
case cfg := <-lbCfgCh:
634-
t.Fatalf("Unexpected configuration pushed to child policy: %v", cfg)
684+
t.Fatalf("Child policy received configuration when not expected to: %s", pretty.ToJSON(cfg))
635685
case <-time.After(defaultTestShortTimeout):
636686
}
637687

0 commit comments

Comments
 (0)