@@ -958,6 +958,32 @@ func TestOrderedByPriorityMemory(t *testing.T) {
958
958
}
959
959
}
960
960
961
+ // TestOrderedByPriorityProcess ensures we order by priority and then process consumption relative to request.
962
+ func TestOrderedByPriorityProcess (t * testing.T ) {
963
+ pod1 := newPod ("low-priority-high-usage" , lowPriority , nil , nil )
964
+ pod2 := newPod ("low-priority-low-usage" , lowPriority , nil , nil )
965
+ pod3 := newPod ("high-priority-high-usage" , highPriority , nil , nil )
966
+ pod4 := newPod ("high-priority-low-usage" , highPriority , nil , nil )
967
+ stats := map [* v1.Pod ]statsapi.PodStats {
968
+ pod1 : newPodProcessStats (pod1 , 20 ),
969
+ pod2 : newPodProcessStats (pod2 , 6 ),
970
+ pod3 : newPodProcessStats (pod3 , 20 ),
971
+ pod4 : newPodProcessStats (pod4 , 5 ),
972
+ }
973
+ statsFn := func (pod * v1.Pod ) (statsapi.PodStats , bool ) {
974
+ result , found := stats [pod ]
975
+ return result , found
976
+ }
977
+ pods := []* v1.Pod {pod4 , pod3 , pod2 , pod1 }
978
+ expected := []* v1.Pod {pod1 , pod2 , pod3 , pod4 }
979
+ orderedBy (priority , process (statsFn )).Sort (pods )
980
+ for i := range expected {
981
+ if pods [i ] != expected [i ] {
982
+ t .Errorf ("Expected pod[%d]: %s, but got: %s" , i , expected [i ].Name , pods [i ].Name )
983
+ }
984
+ }
985
+ }
986
+
961
987
func TestSortByEvictionPriority (t * testing.T ) {
962
988
for _ , tc := range []struct {
963
989
name string
@@ -1884,6 +1910,17 @@ func newPodMemoryStats(pod *v1.Pod, workingSet resource.Quantity) statsapi.PodSt
1884
1910
}
1885
1911
}
1886
1912
1913
+ func newPodProcessStats (pod * v1.Pod , num uint64 ) statsapi.PodStats {
1914
+ return statsapi.PodStats {
1915
+ PodRef : statsapi.PodReference {
1916
+ Name : pod .Name , Namespace : pod .Namespace , UID : string (pod .UID ),
1917
+ },
1918
+ ProcessStats : & statsapi.ProcessStats {
1919
+ ProcessCount : & num ,
1920
+ },
1921
+ }
1922
+ }
1923
+
1887
1924
func newResourceList (cpu , memory , disk string ) v1.ResourceList {
1888
1925
res := v1.ResourceList {}
1889
1926
if cpu != "" {
0 commit comments