sigs.k8s.io/kueue@v0.6.2/pkg/scheduler/flavorassigner/podset_reducer_test.go (about) 1 package flavorassigner 2 3 import ( 4 "testing" 5 6 kueue "sigs.k8s.io/kueue/apis/kueue/v1beta1" 7 utiltesting "sigs.k8s.io/kueue/pkg/util/testing" 8 ) 9 10 func TestSearch(t *testing.T) { 11 cases := map[string]struct { 12 podSets []kueue.PodSet 13 countLimit int32 14 wantCount int32 15 wantFound bool 16 }{ 17 "empty": { 18 podSets: []kueue.PodSet{}, 19 countLimit: 10, 20 wantFound: false, 21 wantCount: 0, 22 }, 23 "partial not available": { 24 podSets: []kueue.PodSet{ 25 *utiltesting.MakePodSet("ps1", 1).Obj(), 26 *utiltesting.MakePodSet("ps2", 2).SetMinimumCount(2).Obj(), 27 }, 28 countLimit: 2, 29 wantFound: false, 30 wantCount: 0, 31 }, 32 "partial available": { 33 podSets: []kueue.PodSet{ 34 *utiltesting.MakePodSet("ps1", 5).SetMinimumCount(3).Obj(), 35 *utiltesting.MakePodSet("ps2", 5).SetMinimumCount(4).Obj(), 36 *utiltesting.MakePodSet("ps3", 5).SetMinimumCount(1).Obj(), 37 *utiltesting.MakePodSet("ps4", 5).SetMinimumCount(2).Obj(), 38 }, 39 countLimit: 15, 40 wantFound: true, 41 wantCount: 15, 42 }, 43 "one partial available": { 44 podSets: []kueue.PodSet{ 45 *utiltesting.MakePodSet("ps1", 5).SetMinimumCount(3).Obj(), 46 *utiltesting.MakePodSet("ps2", 5).Obj(), 47 *utiltesting.MakePodSet("ps3", 5).Obj(), 48 *utiltesting.MakePodSet("ps4", 5).Obj(), 49 }, 50 countLimit: 19, 51 wantFound: true, 52 wantCount: 19, 53 }, 54 "to min": { 55 podSets: []kueue.PodSet{ 56 *utiltesting.MakePodSet("ps1", 5).SetMinimumCount(3).Obj(), 57 *utiltesting.MakePodSet("ps2", 5).SetMinimumCount(4).Obj(), 58 *utiltesting.MakePodSet("ps3", 5).SetMinimumCount(1).Obj(), 59 *utiltesting.MakePodSet("ps4", 5).SetMinimumCount(2).Obj(), 60 }, 61 countLimit: 10, 62 wantFound: true, 63 wantCount: 10, 64 }, 65 "to max": { 66 podSets: []kueue.PodSet{ 67 *utiltesting.MakePodSet("ps1", 5).SetMinimumCount(3).Obj(), 68 *utiltesting.MakePodSet("ps2", 5).SetMinimumCount(4).Obj(), 69 *utiltesting.MakePodSet("ps3", 5).SetMinimumCount(1).Obj(), 70 *utiltesting.MakePodSet("ps4", 5).SetMinimumCount(2).Obj(), 71 }, 72 countLimit: 20, 73 wantFound: true, 74 wantCount: 20, 75 }, 76 "no overflow": { 77 podSets: []kueue.PodSet{ 78 *utiltesting.MakePodSet("ps1", 150_000).SetMinimumCount(1).Obj(), 79 *utiltesting.MakePodSet("ps2", 150_000).SetMinimumCount(1).Obj(), 80 *utiltesting.MakePodSet("ps3", 150_000).SetMinimumCount(1).Obj(), 81 *utiltesting.MakePodSet("ps4", 150_000).SetMinimumCount(1).Obj(), 82 *utiltesting.MakePodSet("ps5", 150_000).SetMinimumCount(1).Obj(), 83 *utiltesting.MakePodSet("ps6", 150_000).SetMinimumCount(1).Obj(), 84 *utiltesting.MakePodSet("ps7", 150_000).SetMinimumCount(1).Obj(), 85 *utiltesting.MakePodSet("ps8", 150_000).SetMinimumCount(1).Obj(), 86 }, 87 countLimit: 150_000, 88 wantFound: true, 89 wantCount: 150_000, 90 }, 91 "max pods on 1.27": { 92 podSets: []kueue.PodSet{ 93 *utiltesting.MakePodSet("ps1", 150_000).SetMinimumCount(1).Obj(), 94 *utiltesting.MakePodSet("ps2", 1).Obj(), 95 *utiltesting.MakePodSet("ps3", 1).Obj(), 96 *utiltesting.MakePodSet("ps4", 1).Obj(), 97 *utiltesting.MakePodSet("ps5", 1).Obj(), 98 *utiltesting.MakePodSet("ps6", 1).Obj(), 99 *utiltesting.MakePodSet("ps7", 1).Obj(), 100 *utiltesting.MakePodSet("ps8", 1).Obj(), 101 }, 102 countLimit: 150_000, 103 wantFound: true, 104 wantCount: 150_000, 105 }, 106 } 107 for name, tc := range cases { 108 t.Run(name, func(t *testing.T) { 109 red := NewPodSetReducer(tc.podSets, func(counts []int32) (int32, bool) { 110 total := int32(0) 111 for _, v := range counts { 112 total += v 113 } 114 return total, total <= tc.countLimit 115 116 }) 117 count, found := red.Search() 118 if count != tc.wantCount { 119 120 t.Errorf("Unexpected count:%d, want: %d", count, tc.wantCount) 121 } 122 123 if found != tc.wantFound { 124 t.Errorf("Unexpected found:%v, want: %v", found, tc.wantFound) 125 126 } 127 }) 128 } 129 130 }