@@ -866,3 +866,53 @@ func (s) TestAggregatedCluster_CycleWithLeafNode(t *testing.T) {
866866 t .Fatalf ("EmptyCall() failed: %v" , err )
867867 }
868868}
869+
870+ // Tests the scenario where the cluster tree changes, and verifies that the
871+ // watchers for the cds balancer are updated accordingly. That is the cluster
872+ // removed from the tree no longer has a watcher and the new cluster added has a
873+ // new watcher.
874+ func (s ) TestWatchers (t * testing.T ) {
875+ mgmtServer , nodeID , _ , _ , _ , cdsResourceRequestedCh , _ := setupWithManagementServer (t )
876+
877+ ctx , cancel := context .WithTimeout (context .Background (), defaultTestTimeout )
878+ defer cancel ()
879+
880+ const (
881+ clusterA = clusterName
882+ clusterB = clusterName + "-B"
883+ clusterC = clusterName + "-C"
884+ clusterD = clusterName + "-D"
885+ )
886+
887+ // Initial CDS resources: A -> B, C
888+ initialResources := e2e.UpdateOptions {
889+ NodeID : nodeID ,
890+ Clusters : []* v3clusterpb.Cluster {
891+ makeAggregateClusterResource (clusterA , []string {clusterB , clusterC }),
892+ },
893+ SkipValidation : true ,
894+ }
895+ if err := mgmtServer .Update (ctx , initialResources ); err != nil {
896+ t .Fatalf ("Update failed: %v" , err )
897+ }
898+ wantNames := []string {clusterA , clusterB , clusterC }
899+ if err := waitForResourceNames (ctx , cdsResourceRequestedCh , wantNames ); err != nil {
900+ t .Fatal (err )
901+ }
902+
903+ // Update the CDS resources to remove cluster C and add cluster D.
904+ updatedResources := e2e.UpdateOptions {
905+ NodeID : nodeID ,
906+ Clusters : []* v3clusterpb.Cluster {
907+ makeAggregateClusterResource (clusterA , []string {clusterB , clusterD }),
908+ },
909+ SkipValidation : true ,
910+ }
911+ if err := mgmtServer .Update (ctx , updatedResources ); err != nil {
912+ t .Fatalf ("Update failed: %v" , err )
913+ }
914+ wantNames = []string {clusterA , clusterB , clusterD }
915+ if err := waitForResourceNames (ctx , cdsResourceRequestedCh , wantNames ); err != nil {
916+ t .Fatal (err )
917+ }
918+ }
0 commit comments