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