@@ -656,6 +656,46 @@ func (s) TestPriorityType(t *testing.T) {
656
656
}
657
657
}
658
658
659
+ func (s ) TestPriorityTypeEqual (t * testing.T ) {
660
+ tests := []struct {
661
+ name string
662
+ p1 , p2 priorityType
663
+ want bool
664
+ }{
665
+ {
666
+ name : "equal" ,
667
+ p1 : newPriorityType (12 ),
668
+ p2 : newPriorityType (12 ),
669
+ want : true ,
670
+ },
671
+ {
672
+ name : "not equal" ,
673
+ p1 : newPriorityType (12 ),
674
+ p2 : newPriorityType (34 ),
675
+ want : false ,
676
+ },
677
+ {
678
+ name : "one not set" ,
679
+ p1 : newPriorityType (1 ),
680
+ p2 : newPriorityTypeUnset (),
681
+ want : false ,
682
+ },
683
+ {
684
+ name : "both not set" ,
685
+ p1 : newPriorityTypeUnset (),
686
+ p2 : newPriorityTypeUnset (),
687
+ want : true ,
688
+ },
689
+ }
690
+ for _ , tt := range tests {
691
+ t .Run (tt .name , func (t * testing.T ) {
692
+ if got := tt .p1 .equal (tt .p2 ); got != tt .want {
693
+ t .Errorf ("equal() = %v, want %v" , got , tt .want )
694
+ }
695
+ })
696
+ }
697
+ }
698
+
659
699
// Test the case where the high priority contains no backends. The low priority
660
700
// will be used.
661
701
func (s ) TestEDSPriority_HighPriorityNoEndpoints (t * testing.T ) {
@@ -775,3 +815,28 @@ func (s) TestEDSPriority_HighPriorityAllUnhealthy(t *testing.T) {
775
815
t .Fatalf ("want %v, got %v" , want , err )
776
816
}
777
817
}
818
+
819
+ // Test the case where the first and only priority is removed.
820
+ func (s ) TestEDSPriority_FirstPriorityUnavailable (t * testing.T ) {
821
+ const testPriorityInitTimeout = time .Second
822
+ defer func (t time.Duration ) {
823
+ defaultPriorityInitTimeout = t
824
+ }(defaultPriorityInitTimeout )
825
+ defaultPriorityInitTimeout = testPriorityInitTimeout
826
+
827
+ cc := testutils .NewTestClientConn (t )
828
+ edsb := newEDSBalancerImpl (cc , nil , nil , nil )
829
+ edsb .enqueueChildBalancerStateUpdate = edsb .updateState
830
+
831
+ // One localities, with priorities [0], each with one backend.
832
+ clab1 := xdsclient .NewClusterLoadAssignmentBuilder (testClusterNames [0 ], nil )
833
+ clab1 .AddLocality (testSubZones [0 ], 1 , 0 , testEndpointAddrs [:1 ], nil )
834
+ edsb .handleEDSResponse (xdsclient .ParseEDSRespProtoForTesting (clab1 .Build ()))
835
+
836
+ // Remove the only localities.
837
+ clab2 := xdsclient .NewClusterLoadAssignmentBuilder (testClusterNames [0 ], nil )
838
+ edsb .handleEDSResponse (xdsclient .ParseEDSRespProtoForTesting (clab2 .Build ()))
839
+
840
+ // Wait after double the init timer timeout, to ensure it doesn't fail.
841
+ time .Sleep (testPriorityInitTimeout * 2 )
842
+ }
0 commit comments