@@ -2009,6 +2009,7 @@ func TestTryAllocatePreemptQueue(t *testing.T) {
2009
2009
result3 := app2 .tryAllocate (resources .NewResourceFromMap (map [string ]resources.Quantity {"first" : 0 }), true , 30 * time .Second , & preemptionAttemptsRemaining , iterator , iterator , getNode )
2010
2010
assert .Assert (t , result3 == nil , "result3 not expected" )
2011
2011
assert .Assert (t , ! alloc2 .IsPreempted (), "alloc2 should not have been preempted" )
2012
+ assertAllocationLog (t , ask3 )
2012
2013
2013
2014
// pass the time and try again
2014
2015
ask3 .createTime = ask3 .createTime .Add (- 30 * time .Second )
@@ -2068,28 +2069,25 @@ func TestTryAllocatePreemptNode(t *testing.T) {
2068
2069
preemptionAttemptsRemaining := 10
2069
2070
2070
2071
// consume capacity with 'unlimited' app
2071
- result00 := app0 .tryAllocate (resources .NewResourceFromMap (map [string ]resources.Quantity {"first" : 40 }), true , 30 * time .Second , & preemptionAttemptsRemaining , iterator , iterator , getNode )
2072
- assert .Assert (t , result00 != nil , "result00 expected" )
2073
- alloc00 := result00 .Request
2074
- assert .Assert (t , alloc00 != nil , "alloc00 expected" )
2075
- alloc00 .SetNodeID (result00 .NodeID )
2076
- result01 := app0 .tryAllocate (resources .NewResourceFromMap (map [string ]resources.Quantity {"first" : 39 }), true , 30 * time .Second , & preemptionAttemptsRemaining , iterator , iterator , getNode )
2077
- assert .Assert (t , result01 != nil , "result01 expected" )
2078
- alloc01 := result01 .Request
2079
- assert .Assert (t , alloc01 != nil , "alloc01 expected" )
2080
- alloc01 .SetNodeID (result01 .NodeID )
2072
+ for _ , r := range []* resources.Resource {resources .NewResourceFromMap (map [string ]resources.Quantity {"first" : 40 }), resources .NewResourceFromMap (map [string ]resources.Quantity {"first" : 39 })} {
2073
+ result0 := app0 .tryAllocate (r , true , 30 * time .Second , & preemptionAttemptsRemaining , iterator , iterator , getNode )
2074
+ assert .Assert (t , result0 != nil , "result0 expected" )
2075
+ alloc0 := result0 .Request
2076
+ assert .Assert (t , alloc0 != nil , "alloc0 expected" )
2077
+ alloc0 .SetNodeID (result0 .NodeID )
2078
+ }
2081
2079
2082
2080
// consume remainder of space but not quota
2083
- result1 := app1 . tryAllocate ( resources . NewResourceFromMap ( map [ string ]resources. Quantity { "first" : 28 }), true , 30 * time . Second , & preemptionAttemptsRemaining , iterator , iterator , getNode )
2084
- assert . Assert ( t , result1 != nil , "result1 expected" )
2085
- alloc1 := result1 . Request
2086
- assert . Assert ( t , alloc1 != nil , "alloc1 expected" )
2087
- alloc1 . SetNodeID ( result1 . NodeID )
2088
- result2 := app1 . tryAllocate ( resources . NewResourceFromMap ( map [ string ]resources. Quantity { "first" : 23 }), true , 30 * time . Second , & preemptionAttemptsRemaining , iterator , iterator , getNode )
2089
- assert .Assert (t , result2 != nil , "result2 expected" )
2090
- alloc2 := result2 . Request
2091
- assert . Assert ( t , alloc2 != nil , "alloc2 expected" )
2092
- alloc2 . SetNodeID ( result2 . NodeID )
2081
+ allocs := make ([] * Allocation , 0 )
2082
+ for _ , r := range [] * resources. Resource { resources . NewResourceFromMap ( map [ string ]resources. Quantity { "first" : 28 }), resources . NewResourceFromMap ( map [ string ]resources. Quantity { "first" : 23 })} {
2083
+ var alloc1 * Allocation
2084
+ result1 := app1 . tryAllocate ( r , true , 30 * time . Second , & preemptionAttemptsRemaining , iterator , iterator , getNode )
2085
+ assert . Assert ( t , result1 != nil , "result1 expected" )
2086
+ alloc1 = result1 . Request
2087
+ assert .Assert (t , result1 . Request != nil , "alloc1 expected" )
2088
+ alloc1 . SetNodeID ( result1 . NodeID )
2089
+ allocs = append ( allocs , alloc1 )
2090
+ }
2093
2091
2094
2092
// on first attempt, should see a reservation since we're after the reservation timeout
2095
2093
ask3 .createTime = ask3 .createTime .Add (- 10 * time .Second )
@@ -2099,18 +2097,24 @@ func TestTryAllocatePreemptNode(t *testing.T) {
2099
2097
assert .Assert (t , alloc3 != nil , "alloc3 not expected" )
2100
2098
assert .Equal (t , "node1" , result3 .NodeID , "wrong node assignment" )
2101
2099
assert .Equal (t , Reserved , result3 .ResultType , "expected reservation" )
2102
- assert .Assert (t , ! alloc2 .IsPreempted (), "alloc2 should not have been preempted" )
2100
+ assert .Assert (t , ! allocs [ 1 ] .IsPreempted (), "alloc2 should not have been preempted" )
2103
2101
err = node1 .Reserve (app2 , ask3 )
2104
2102
assert .NilError (t , err )
2105
2103
2104
+ // preemption delay not yet passed, so preemption should fail
2105
+ result3 = app2 .tryAllocate (resources .NewResourceFromMap (map [string ]resources.Quantity {"first" : 18 }), true , 30 * time .Second , & preemptionAttemptsRemaining , iterator , iterator , getNode )
2106
+ assert .Assert (t , result3 == nil , "result3 expected" )
2107
+ assert .Assert (t , ! allocs [1 ].IsPreempted (), "alloc1 should have been preempted" )
2108
+ assertAllocationLog (t , ask3 )
2109
+
2106
2110
// pass the time and try again
2107
2111
ask3 .createTime = ask3 .createTime .Add (- 30 * time .Second )
2108
2112
result3 = app2 .tryAllocate (resources .NewResourceFromMap (map [string ]resources.Quantity {"first" : 18 }), true , 30 * time .Second , & preemptionAttemptsRemaining , iterator , iterator , getNode )
2109
2113
assert .Assert (t , result3 != nil , "result3 expected" )
2110
2114
assert .Equal (t , Reserved , result3 .ResultType , "expected reservation" )
2111
2115
alloc3 = result3 .Request
2112
2116
assert .Assert (t , alloc3 != nil , "alloc3 expected" )
2113
- assert .Assert (t , alloc1 .IsPreempted (), "alloc1 should have been preempted" )
2117
+ assert .Assert (t , allocs [ 0 ] .IsPreempted (), "alloc1 should have been preempted" )
2114
2118
}
2115
2119
2116
2120
func TestMaxAskPriority (t * testing.T ) {
0 commit comments