@@ -1491,14 +1491,14 @@ func TestReplaceAllocationTracking(t *testing.T) {
1491
1491
}
1492
1492
1493
1493
func TestTimeoutPlaceholderSoft (t * testing.T ) {
1494
- runTimeoutPlaceholderTest (t , Resuming .String (), Soft , [] int { 1 , 2 } )
1494
+ runTimeoutPlaceholderTest (t , Resuming .String (), Soft )
1495
1495
}
1496
1496
1497
1497
func TestTimeoutPlaceholderHard (t * testing.T ) {
1498
- runTimeoutPlaceholderTest (t , Failing .String (), Hard , [] int { 1 , 2 } )
1498
+ runTimeoutPlaceholderTest (t , Failing .String (), Hard )
1499
1499
}
1500
1500
1501
- func runTimeoutPlaceholderTest (t * testing.T , expectedState string , gangSchedulingStyle string , expectedReleases [] int ) {
1501
+ func runTimeoutPlaceholderTest (t * testing.T , expectedState string , gangSchedulingStyle string ) {
1502
1502
const (
1503
1503
tg1 = "tg-1"
1504
1504
tg2 = "tg-2"
@@ -1530,16 +1530,16 @@ func runTimeoutPlaceholderTest(t *testing.T, expectedState string, gangSchedulin
1530
1530
assert .Assert (t , app .IsAccepted (), "Application should be in accepted state" )
1531
1531
1532
1532
// add the placeholder to the app
1533
- ph := newPlaceholderAlloc (appID1 , nodeID1 , res , tg2 )
1534
- app .AddAllocation (ph )
1535
- app .addPlaceholderDataWithLocking (ph )
1533
+ ph1 := newPlaceholderAlloc (appID1 , nodeID1 , res , tg2 )
1534
+ app .AddAllocation (ph1 )
1535
+ app .addPlaceholderDataWithLocking (ph1 )
1536
1536
assertPlaceholderData (t , app , tg2 , 1 , 0 , 0 , res )
1537
1537
assertUserGroupResource (t , getTestUserGroup (), res )
1538
1538
assert .Assert (t , app .getPlaceholderTimer () != nil , "Placeholder timer should be initiated after the first placeholder allocation" )
1539
1539
// add a second one to check the filter
1540
- ph = newPlaceholderAlloc (appID1 , nodeID1 , res , tg2 )
1541
- app .AddAllocation (ph )
1542
- app .addPlaceholderDataWithLocking (ph )
1540
+ ph2 : = newPlaceholderAlloc (appID1 , nodeID1 , res , tg2 )
1541
+ app .AddAllocation (ph2 )
1542
+ app .addPlaceholderDataWithLocking (ph2 )
1543
1543
assertPlaceholderData (t , app , tg2 , 2 , 0 , 0 , res )
1544
1544
assertUserGroupResource (t , getTestUserGroup (), resources .Multiply (res , 2 ))
1545
1545
assert .Assert (t , app .IsAccepted (), "Application should be in accepted state" )
@@ -1549,11 +1549,22 @@ func runTimeoutPlaceholderTest(t *testing.T, expectedState string, gangSchedulin
1549
1549
return app .placeholderTimer == nil
1550
1550
})
1551
1551
assert .NilError (t , err , "Placeholder timeout cleanup did not trigger unexpectedly" )
1552
- // When the app was in the accepted state, timeout should equal to count
1552
+ // pending updates immediately
1553
1553
assertPlaceholderData (t , app , tg1 , 1 , 1 , 0 , res )
1554
- assertPlaceholderData (t , app , tg2 , 2 , 2 , 0 , res )
1554
+ // No changes until the removals are confirmed
1555
+ assertPlaceholderData (t , app , tg2 , 2 , 0 , 0 , res )
1556
+
1555
1557
assert .Equal (t , app .stateMachine .Current (), expectedState , "Application did not progress into expected state" )
1558
+ log := app .GetStateLog ()
1559
+ assert .Equal (t , len (log ), 2 , "wrong number of app events" )
1560
+ assert .Equal (t , log [0 ].ApplicationState , Accepted .String ())
1561
+ assert .Equal (t , log [1 ].ApplicationState , expectedState )
1562
+
1556
1563
assertUserGroupResource (t , getTestUserGroup (), resources .Multiply (res , 2 ))
1564
+ // ordering of events is based on the order in which we call the release in the application
1565
+ // first are the allocated placeholders then the pending placeholders, always same values
1566
+ // See the timeoutPlaceholderProcessing() function
1567
+ expectedReleases := []int {2 , 1 }
1557
1568
events := testHandler .GetEvents ()
1558
1569
var found int
1559
1570
idx := 0
@@ -1572,10 +1583,15 @@ func runTimeoutPlaceholderTest(t *testing.T, expectedState string, gangSchedulin
1572
1583
assert .Assert (t , resources .Equals (app .GetPlaceholderResource (), resources .Multiply (res , 2 )), "Unexpected placeholder resources for the app" )
1573
1584
assertUserGroupResource (t , getTestUserGroup (), resources .Multiply (res , 2 ))
1574
1585
1575
- log := app .GetStateLog ()
1576
- assert .Equal (t , len (log ), 2 , "wrong number of app events" )
1577
- assert .Equal (t , log [0 ].ApplicationState , Accepted .String ())
1578
- assert .Equal (t , log [1 ].ApplicationState , expectedState )
1586
+ removed := app .RemoveAllocation (ph1 .allocationKey , si .TerminationType_TIMEOUT )
1587
+ assert .Assert (t , removed != nil , "expected allocation got nil" )
1588
+ assert .Equal (t , ph1 .allocationKey , removed .allocationKey , "expected placeholder to be returned" )
1589
+ removed = app .RemoveAllocation (ph2 .allocationKey , si .TerminationType_TIMEOUT )
1590
+ assert .Assert (t , removed != nil , "expected allocation got nil" )
1591
+ assert .Equal (t , ph2 .allocationKey , removed .allocationKey , "expected placeholder to be returned" )
1592
+
1593
+ // Removals are confirmed: timeout should equal to count
1594
+ assertPlaceholderData (t , app , tg2 , 2 , 2 , 0 , res )
1579
1595
}
1580
1596
1581
1597
func TestTimeoutPlaceholderAllocReleased (t * testing.T ) {
0 commit comments