@@ -668,8 +668,8 @@ func TestHeadroom(t *testing.T) {
668668 var res * resources.Resource
669669 res , err = resources .NewResourceFromConf (map [string ]string {"first" : "5" , "second" : "3" })
670670 assert .NilError (t , err , "failed to create resource" )
671- leaf1 .IncAllocatedResource (res )
672- leaf2 .IncAllocatedResource (res )
671+ leaf1 .IncAllocatedResource (res , false )
672+ leaf2 .IncAllocatedResource (res , false )
673673
674674 // headRoom root should be this (max 20-10 - alloc 10-6)
675675 res , err = resources .NewResourceFromConf (map [string ]string {"first" : "10" , "second" : "4" })
@@ -726,10 +726,10 @@ func TestHeadroomMerge(t *testing.T) {
726726 var res * resources.Resource
727727 res , err = resources .NewResourceFromConf (map [string ]string {"first" : "5" , "second" : "5" , "third" : "5" })
728728 assert .NilError (t , err , "failed to create resource" )
729- leaf1 .IncAllocatedResource (res )
729+ leaf1 .IncAllocatedResource (res , false )
730730 res , err = resources .NewResourceFromConf (map [string ]string {"third" : "5" , "fourth" : "5" })
731731 assert .NilError (t , err , "failed to create resource" )
732- leaf2 .IncAllocatedResource (res )
732+ leaf2 .IncAllocatedResource (res , false )
733733
734734 // root headroom should be nil
735735 headRoom := root .getHeadRoom ()
@@ -796,8 +796,8 @@ func TestMaxHeadroomNoMax(t *testing.T) {
796796 var res * resources.Resource
797797 res , err = resources .NewResourceFromConf (map [string ]string {"first" : "5" , "second" : "3" })
798798 assert .NilError (t , err , "failed to create resource" )
799- leaf1 .IncAllocatedResource (res )
800- leaf2 .IncAllocatedResource (res )
799+ leaf1 .IncAllocatedResource (res , false )
800+ leaf2 .IncAllocatedResource (res , false )
801801
802802 headRoom = root .getMaxHeadRoom ()
803803 assert .Assert (t , headRoom == nil , "headRoom of root should be nil because no max set for all queues" )
@@ -834,8 +834,8 @@ func TestMaxHeadroomMax(t *testing.T) {
834834 var res * resources.Resource
835835 res , err = resources .NewResourceFromConf (map [string ]string {"first" : "5" , "second" : "3" })
836836 assert .NilError (t , err , "failed to create resource" )
837- leaf1 .IncAllocatedResource (res )
838- leaf2 .IncAllocatedResource (res )
837+ leaf1 .IncAllocatedResource (res , false )
838+ leaf2 .IncAllocatedResource (res , false )
839839
840840 // root headroom should be nil
841841 headRoom := root .getMaxHeadRoom ()
@@ -1475,7 +1475,7 @@ func TestOutStandingRequestMultipleChildrenWithMax(t *testing.T) {
14751475 leaf1App := newApplication ("app-leaf1" , "default" , "root.parent.leaf1" )
14761476 leaf1App .SetQueue (leaf1 )
14771477 leaf1 .AddApplication (leaf1App )
1478- leaf1 .IncAllocatedResource (allocatedRes )
1478+ leaf1 .IncAllocatedResource (allocatedRes , false )
14791479 // use priority = 1000 for this ask to force ordering of queues when sorting
14801480 askLeaf1 := newAllocationAskAll ("ask-leaf1" , "app-leaf1" , "" , askRes , false , 1000 )
14811481 askLeaf1 .SetSchedulingAttempted (true )
@@ -1493,7 +1493,7 @@ func TestOutStandingRequestMultipleChildrenWithMax(t *testing.T) {
14931493 err = leaf2App .AddAllocationAsk (ask2Leaf2 )
14941494 assert .NilError (t , err , "could not add ask" )
14951495 leaf2 .AddApplication (leaf2App )
1496- leaf2 .IncAllocatedResource (allocatedRes )
1496+ leaf2 .IncAllocatedResource (allocatedRes , false )
14971497
14981498 outstanding := root .GetOutstandingRequests ()
14991499 assert .Equal (t , 2 , len (outstanding ), "expected 2 outstanding requests to be collected" )
@@ -2374,59 +2374,60 @@ func TestQuotaPreemptionSettings(t *testing.T) {
23742374 assert .NilError (t , err , "failed to create basic queue: %v" , err )
23752375
23762376 testCases := []struct {
2377- name string
2378- maxRes map [string ]string
2379- conf configs.QueueConfig
2380- oldDelay time.Duration
2381- timeChange bool
2377+ name string
2378+ maxRes map [string ]string
2379+ conf configs.QueueConfig
2380+ oldDelay time.Duration
2381+ timeChange bool
2382+ shouldApplyQuotaPreemption bool
23822383 }{
23832384 {"clearing max" ,
23842385 map [string ]string {"memory" : "500" },
23852386 configs.QueueConfig {
23862387 Resources : configs.Resources {
23872388 Max : nil ,
23882389 },
2389- }, 0 , false },
2390+ }, 0 , false , false },
23902391 {"clearing max with delay" ,
23912392 map [string ]string {"memory" : "500" },
23922393 configs.QueueConfig {
23932394 Resources : configs.Resources {
23942395 Max : nil ,
23952396 },
23962397 Properties : map [string ]string {configs .QuotaPreemptionDelay : "50ms" },
2397- }, 0 , false },
2398+ }, 0 , false , false },
23982399 {"incorrect delay" ,
23992400 map [string ]string {"memory" : "500" },
24002401 configs.QueueConfig {
24012402 Resources : configs.Resources {
24022403 Max : nil ,
24032404 },
24042405 Properties : map [string ]string {configs .QuotaPreemptionDelay : "-50s" },
2405- }, 0 , false },
2406+ }, 0 , false , false },
24062407 {"increase max with delay" ,
24072408 map [string ]string {"memory" : "500" },
24082409 configs.QueueConfig {
24092410 Resources : configs.Resources {
24102411 Max : map [string ]string {"memory" : "1000" },
24112412 },
24122413 Properties : map [string ]string {configs .QuotaPreemptionDelay : "50ms" },
2413- }, 50 * time .Millisecond , false },
2414+ }, 50 * time .Millisecond , false , false },
24142415 {"decrease max with delay" ,
24152416 map [string ]string {"memory" : "500" },
24162417 configs.QueueConfig {
24172418 Resources : configs.Resources {
24182419 Max : map [string ]string {"memory" : "100" },
24192420 },
24202421 Properties : map [string ]string {configs .QuotaPreemptionDelay : "50ms" },
2421- }, 50 * time .Millisecond , true },
2422+ }, 50 * time .Millisecond , true , true },
24222423 {"delay changed from 0 no max change" ,
24232424 map [string ]string {"memory" : "500" },
24242425 configs.QueueConfig {
24252426 Resources : configs.Resources {
24262427 Max : map [string ]string {"memory" : "500" },
24272428 },
24282429 Properties : map [string ]string {configs .QuotaPreemptionDelay : "50ms" },
2429- }, 0 , true },
2430+ }, 0 , true , true },
24302431 }
24312432
24322433 var oldMax * resources.Resource
@@ -3266,3 +3267,54 @@ func TestQueue_setPreemptionTime(t *testing.T) {
32663267 })
32673268 }
32683269}
3270+
3271+ func TestOverrideAndResetPreemptionTime (t * testing.T ) {
3272+ root , e := createRootQueue (nil )
3273+ assert .NilError (t , e , "failed to create basic root queue" )
3274+ tests := []struct {
3275+ name string
3276+ oldMaxResource * resources.Resource
3277+ maxRes map [string ]string
3278+ currentUsage * resources.Resource
3279+ delay time.Duration
3280+ timeChange bool
3281+ overrideTimeChange bool
3282+ }{
3283+ {"usage lesser than max res, so preemption time is not set. try to override" , resources .NewResourceFromMap (map [string ]resources.Quantity {"test" : 100 }), map [string ]string {"test" : "150" }, resources .NewResourceFromMap (map [string ]resources.Quantity {"test" : 80 }), 5 , false , false },
3284+ {"setting preemption time first, try to override" , resources .NewResourceFromMap (map [string ]resources.Quantity {"test" : 100 }), map [string ]string {"test" : "50" }, resources .NewResourceFromMap (map [string ]resources.Quantity {"test" : 80 }), 10 , true , false },
3285+ {"preemption time did not set first time, try to override" , resources .NewResourceFromMap (map [string ]resources.Quantity {"test" : 100 }), map [string ]string {"test" : "150" }, resources .NewResourceFromMap (map [string ]resources.Quantity {"test" : 180 }), 10 , false , true },
3286+ }
3287+ for _ , tt := range tests {
3288+ t .Run (tt .name , func (t * testing.T ) {
3289+ queue , err := createManagedQueue (root , "test" , false , tt .maxRes )
3290+ assert .NilError (t , err , "queue creation failed unexpectedly" )
3291+ queue .quotaPreemptionDelay = tt .delay
3292+ queue .allocatedResource = tt .currentUsage
3293+ before := queue .quotaPreemptionStartTime
3294+ queue .setPreemptionTime (tt .oldMaxResource , tt .delay )
3295+ after := queue .quotaPreemptionStartTime
3296+ if tt .timeChange {
3297+ assert .Assert (t , ! before .Equal (after ), "time change is expected" )
3298+ assert .Assert (t , ! queue .quotaPreemptionStartTime .IsZero (), "schedule is expected" )
3299+ }
3300+ queue .IncAllocatedResource (resources .NewResourceFromMap (map [string ]resources.Quantity {"test" : 1 }), true )
3301+ afterOverride := queue .quotaPreemptionStartTime
3302+ if tt .overrideTimeChange {
3303+ assert .Assert (t , ! after .Equal (afterOverride ), "time change is not expected" )
3304+ assert .Assert (t , ! queue .quotaPreemptionStartTime .IsZero (), "schedule is expected" )
3305+ }
3306+ if tt .timeChange && ! tt .overrideTimeChange {
3307+ assert .Assert (t , after .Equal (afterOverride ), "time change is not expected" )
3308+ assert .Assert (t , ! queue .quotaPreemptionStartTime .IsZero (), "schedule is expected" )
3309+ }
3310+ if tt .timeChange || tt .overrideTimeChange {
3311+ queue .ResetPreemptionTime ()
3312+ afterReset := queue .quotaPreemptionStartTime
3313+ assert .Assert (t , ! afterOverride .Equal (afterReset ), "time change is expected" )
3314+ assert .Assert (t , afterReset .IsZero (), "time change is expected" )
3315+ assert .Assert (t , queue .quotaPreemptionDelay == 0 , "time change is expected" )
3316+ assert .Assert (t , queue .quotaPreemptionStartTime .IsZero (), "schedule is not expected" )
3317+ }
3318+ })
3319+ }
3320+ }
0 commit comments