@@ -42,7 +42,7 @@ func TestFilterAllocations(t *testing.T) {
4242 p := NewRequiredNodePreemptor (node , requiredAsk )
4343 asks := prepareAllocationAsks (t , node )
4444 result := p .filterAllocations ()
45- verifyFilterResult (t , 10 , 0 , 10 , 0 , 0 , result )
45+ verifyFilterResult (t , 10 , 0 , 10 , 0 , 0 , 0 , result )
4646 filteredAllocations := p .getAllocations ()
4747
4848 // allocations are not even considered as there is no match. of course, no victims
@@ -55,7 +55,7 @@ func TestFilterAllocations(t *testing.T) {
5555 p1 := NewRequiredNodePreemptor (node , requiredAsk1 )
5656 asks = prepareAllocationAsks (t , node )
5757 result = p1 .filterAllocations ()
58- verifyFilterResult (t , 10 , 0 , 0 , 10 , 0 , result )
58+ verifyFilterResult (t , 10 , 0 , 0 , 10 , 0 , 0 , result )
5959 filteredAllocations = p .getAllocations ()
6060
6161 // allocations are not even considered as there is no match. of course, no victims
@@ -68,38 +68,44 @@ func TestFilterAllocations(t *testing.T) {
6868 p2 := NewRequiredNodePreemptor (node , requiredAsk2 )
6969 asks = prepareAllocationAsks (t , node )
7070 result = p2 .filterAllocations ()
71- verifyFilterResult (t , 10 , 0 , 0 , 0 , 0 , result )
71+ verifyFilterResult (t , 10 , 0 , 0 , 0 , 0 , 0 , result )
7272 filteredAllocations = p2 .getAllocations ()
7373 assert .Equal (t , len (filteredAllocations ), 10 )
7474 removeAllocationAsks (node , asks )
7575
7676 // case 4: allocation has been preempted
77- requiredAsk3 := createAllocationAsk ("ask12" , "app1" , true , true , 20 ,
78- resources .NewResourceFromMap (map [string ]resources.Quantity {"first" : 5 }))
79- p3 := NewRequiredNodePreemptor (node , requiredAsk3 )
77+ p3 := NewRequiredNodePreemptor (node , requiredAsk2 )
8078 asks = prepareAllocationAsks (t , node )
8179 node .GetAllocation ("ask5" ).MarkPreempted () // "ask5" would be the first and only victim without this
8280 result = p3 .filterAllocations ()
8381 p3 .sortAllocations ()
8482
85- verifyFilterResult (t , 10 , 0 , 0 , 0 , 1 , result )
83+ verifyFilterResult (t , 10 , 0 , 0 , 0 , 1 , 0 , result )
8684 filteredAllocations = p3 .getAllocations ()
8785 assert .Equal (t , len (filteredAllocations ), 9 ) // "ask5" is no longer considered as a victim
8886 removeAllocationAsks (node , asks )
8987
9088 // case 5: existing required node allocation
91- requiredAsk4 := createAllocationAsk ("ask12" , "app1" , true , true , 20 ,
92- resources .NewResourceFromMap (map [string ]resources.Quantity {"first" : 5 }))
93- p4 := NewRequiredNodePreemptor (node , requiredAsk4 )
94- _ = prepareAllocationAsks (t , node )
95- allocReqNode := createAllocation ("ask11" , "app1" , node .NodeID , true , true , 5 , true ,
96- resources .NewResourceFromMap (map [string ]resources.Quantity {"first" : 5 }))
97- assert .Assert (t , node .TryAddAllocation (allocReqNode ))
89+ p4 := NewRequiredNodePreemptor (node , requiredAsk2 )
90+ results := prepareAllocationAsks (t , node )
91+ results [8 ].requiredNode = "node-3"
9892
9993 result = p4 .filterAllocations ()
100- verifyFilterResult (t , 11 , 1 , 0 , 0 , 0 , result )
94+ verifyFilterResult (t , 10 , 1 , 0 , 0 , 0 , 0 , result )
10195 filteredAllocations = p4 .getAllocations ()
102- assert .Equal (t , len (filteredAllocations ), 10 )
96+ assert .Equal (t , len (filteredAllocations ), 9 )
97+ removeAllocationAsks (node , asks )
98+
99+ // case 6: release ph allocation
100+ p5 := NewRequiredNodePreemptor (node , requiredAsk2 )
101+ results = prepareAllocationAsks (t , node )
102+ results [9 ].released = true
103+
104+ result = p5 .filterAllocations ()
105+ verifyFilterResult (t , 10 , 0 , 0 , 0 , 0 , 1 , result )
106+ filteredAllocations = p5 .getAllocations ()
107+ assert .Equal (t , len (filteredAllocations ), 9 )
108+ removeAllocationAsks (node , asks )
103109}
104110
105111func TestGetVictims (t * testing.T ) {
@@ -160,11 +166,12 @@ func TestGetVictims(t *testing.T) {
160166 removeAllocationAsks (node , asks )
161167}
162168
163- func verifyFilterResult (t * testing.T , totalAllocations , requiredNodeAllocations , resourceNotEnough , higherPriorityAllocations , alreadyPreemptedAllocations int , result filteringResult ) {
169+ func verifyFilterResult (t * testing.T , totalAllocations , requiredNodeAllocations , resourceNotEnough , higherPriorityAllocations , alreadyPreemptedAllocations int , releasedPhAllocations int , result filteringResult ) {
164170 t .Helper ()
165171 assert .Equal (t , totalAllocations , result .totalAllocations )
166172 assert .Equal (t , requiredNodeAllocations , result .requiredNodeAllocations )
167173 assert .Equal (t , resourceNotEnough , result .atLeastOneResNotMatched )
168174 assert .Equal (t , higherPriorityAllocations , result .higherPriorityAllocations )
169175 assert .Equal (t , alreadyPreemptedAllocations , result .alreadyPreemptedAllocations )
176+ assert .Equal (t , releasedPhAllocations , result .releasedPhAllocations )
170177}
0 commit comments