@@ -1217,7 +1217,7 @@ func TestPermitPlugins(t *testing.T) {
1217
1217
inj : injectedResult {PermitStatus : int (Unschedulable )},
1218
1218
},
1219
1219
},
1220
- want : NewStatus (Unschedulable , `rejected by "TestPlugin" at permit: injected status` ),
1220
+ want : NewStatus (Unschedulable , `rejected pod "" by permit plugin "TestPlugin" : injected status` ),
1221
1221
},
1222
1222
{
1223
1223
name : "ErrorPermitPlugin" ,
@@ -1237,7 +1237,7 @@ func TestPermitPlugins(t *testing.T) {
1237
1237
inj : injectedResult {PermitStatus : int (UnschedulableAndUnresolvable )},
1238
1238
},
1239
1239
},
1240
- want : NewStatus (UnschedulableAndUnresolvable , `rejected by "TestPlugin" at permit: injected status` ),
1240
+ want : NewStatus (UnschedulableAndUnresolvable , `rejected pod "" by permit plugin "TestPlugin" : injected status` ),
1241
1241
},
1242
1242
{
1243
1243
name : "WaitPermitPlugin" ,
@@ -1247,7 +1247,7 @@ func TestPermitPlugins(t *testing.T) {
1247
1247
inj : injectedResult {PermitStatus : int (Wait )},
1248
1248
},
1249
1249
},
1250
- want : NewStatus (Unschedulable , `pod "" rejected while waiting at permit: rejected due to timeout after waiting 0s at plugin TestPlugin ` ),
1250
+ want : NewStatus (Wait , `one or more plugins asked to wait and no plugin rejected pod "" ` ),
1251
1251
},
1252
1252
{
1253
1253
name : "SuccessSuccessPermitPlugin" ,
@@ -1425,6 +1425,13 @@ func TestRecordingMetrics(t *testing.T) {
1425
1425
wantExtensionPoint : "Permit" ,
1426
1426
wantStatus : Error ,
1427
1427
},
1428
+ {
1429
+ name : "Permit - Wait" ,
1430
+ action : func (f Framework ) { f .RunPermitPlugins (context .Background (), state , pod , "" ) },
1431
+ inject : injectedResult {PermitStatus : int (Wait )},
1432
+ wantExtensionPoint : "Permit" ,
1433
+ wantStatus : Wait ,
1434
+ },
1428
1435
}
1429
1436
1430
1437
for _ , tt := range tests {
@@ -1578,17 +1585,17 @@ func TestRunBindPlugins(t *testing.T) {
1578
1585
}
1579
1586
}
1580
1587
1581
- func TestPermitWaitingMetric (t * testing.T ) {
1588
+ func TestPermitWaitDurationMetric (t * testing.T ) {
1582
1589
tests := []struct {
1583
1590
name string
1584
1591
inject injectedResult
1585
1592
wantRes string
1586
1593
}{
1587
1594
{
1588
- name : "Permit - Success " ,
1595
+ name : "WaitOnPermit - No Wait " ,
1589
1596
},
1590
1597
{
1591
- name : "Permit - Wait Timeout" ,
1598
+ name : "WaitOnPermit - Wait Timeout" ,
1592
1599
inject : injectedResult {PermitStatus : int (Wait )},
1593
1600
wantRes : "Unschedulable" ,
1594
1601
},
@@ -1617,47 +1624,80 @@ func TestPermitWaitingMetric(t *testing.T) {
1617
1624
}
1618
1625
1619
1626
f .RunPermitPlugins (context .TODO (), nil , pod , "" )
1627
+ f .WaitOnPermit (context .TODO (), pod )
1620
1628
1621
1629
collectAndComparePermitWaitDuration (t , tt .wantRes )
1622
1630
})
1623
1631
}
1624
1632
}
1625
1633
1626
- func TestRejectWaitingPod (t * testing.T ) {
1634
+ func TestWaitOnPermit (t * testing.T ) {
1627
1635
pod := & v1.Pod {
1628
1636
ObjectMeta : metav1.ObjectMeta {
1629
1637
Name : "pod" ,
1630
1638
UID : types .UID ("pod" ),
1631
1639
},
1632
1640
}
1633
1641
1634
- testPermitPlugin := & TestPermitPlugin {}
1635
- r := make (Registry )
1636
- r .Register (permitPlugin ,
1637
- func (_ * runtime.Unknown , fh FrameworkHandle ) (Plugin , error ) {
1638
- return testPermitPlugin , nil
1639
- })
1640
- plugins := & config.Plugins {
1641
- Permit : & config.PluginSet {Enabled : []config.Plugin {{Name : permitPlugin , Weight : 1 }}},
1642
+ tests := []struct {
1643
+ name string
1644
+ action func (f Framework )
1645
+ wantStatus Code
1646
+ wantMessage string
1647
+ }{
1648
+ {
1649
+ name : "Reject Waiting Pod" ,
1650
+ action : func (f Framework ) {
1651
+ f .GetWaitingPod (pod .UID ).Reject ("reject message" )
1652
+ },
1653
+ wantStatus : Unschedulable ,
1654
+ wantMessage : "pod \" pod\" rejected while waiting on permit: reject message" ,
1655
+ },
1656
+ {
1657
+ name : "Allow Waiting Pod" ,
1658
+ action : func (f Framework ) {
1659
+ f .GetWaitingPod (pod .UID ).Allow (permitPlugin )
1660
+ },
1661
+ wantStatus : Success ,
1662
+ wantMessage : "" ,
1663
+ },
1642
1664
}
1643
1665
1644
- f , err := newFrameworkWithQueueSortAndBind (r , plugins , emptyArgs )
1645
- if err != nil {
1646
- t .Fatalf ("Failed to create framework for testing: %v" , err )
1647
- }
1666
+ for _ , tt := range tests {
1667
+ t .Run (tt .name , func (t * testing.T ) {
1668
+ testPermitPlugin := & TestPermitPlugin {}
1669
+ r := make (Registry )
1670
+ r .Register (permitPlugin ,
1671
+ func (_ * runtime.Unknown , fh FrameworkHandle ) (Plugin , error ) {
1672
+ return testPermitPlugin , nil
1673
+ })
1674
+ plugins := & config.Plugins {
1675
+ Permit : & config.PluginSet {Enabled : []config.Plugin {{Name : permitPlugin , Weight : 1 }}},
1676
+ }
1648
1677
1649
- go func () {
1650
- for {
1651
- waitingPod := f .GetWaitingPod (pod .UID )
1652
- if waitingPod != nil {
1653
- break
1678
+ f , err := newFrameworkWithQueueSortAndBind (r , plugins , emptyArgs )
1679
+ if err != nil {
1680
+ t .Fatalf ("Failed to create framework for testing: %v" , err )
1654
1681
}
1655
- }
1656
- f .RejectWaitingPod (pod .UID )
1657
- }()
1658
- permitStatus := f .RunPermitPlugins (context .Background (), nil , pod , "" )
1659
- if permitStatus .Message () != "pod \" pod\" rejected while waiting at permit: removed" {
1660
- t .Fatalf ("RejectWaitingPod failed, permitStatus: %v" , permitStatus )
1682
+
1683
+ runPermitPluginsStatus := f .RunPermitPlugins (context .Background (), nil , pod , "" )
1684
+ if runPermitPluginsStatus .Code () != Wait {
1685
+ t .Fatalf ("Expected RunPermitPlugins to return status %v, but got %v" ,
1686
+ Wait , runPermitPluginsStatus .Code ())
1687
+ }
1688
+
1689
+ go tt .action (f )
1690
+
1691
+ waitOnPermitStatus := f .WaitOnPermit (context .Background (), pod )
1692
+ if waitOnPermitStatus .Code () != tt .wantStatus {
1693
+ t .Fatalf ("Expected WaitOnPermit to return status %v, but got %v" ,
1694
+ tt .wantStatus , waitOnPermitStatus .Code ())
1695
+ }
1696
+ if waitOnPermitStatus .Message () != tt .wantMessage {
1697
+ t .Fatalf ("Expected WaitOnPermit to return status with message %q, but got %q" ,
1698
+ tt .wantMessage , waitOnPermitStatus .Message ())
1699
+ }
1700
+ })
1661
1701
}
1662
1702
}
1663
1703
0 commit comments