@@ -2255,7 +2255,7 @@ func TestPriorityQueue_initPodMaxInUnschedulablePodsDuration(t *testing.T) {
2255
2255
var podInfoList []* framework.QueuedPodInfo
2256
2256
2257
2257
for i , op := range test .operations {
2258
- op (logger , queue , test .operands [i ])
2258
+ op (t , logger , queue , test .operands [i ])
2259
2259
}
2260
2260
2261
2261
expectedLen := len (test .expected )
@@ -2278,31 +2278,58 @@ func TestPriorityQueue_initPodMaxInUnschedulablePodsDuration(t *testing.T) {
2278
2278
}
2279
2279
}
2280
2280
2281
- type operation func (logger klog.Logger , queue * PriorityQueue , pInfo * framework.QueuedPodInfo )
2281
+ type operation func (t * testing. T , logger klog.Logger , queue * PriorityQueue , pInfo * framework.QueuedPodInfo )
2282
2282
2283
2283
var (
2284
- add = func (logger klog.Logger , queue * PriorityQueue , pInfo * framework.QueuedPodInfo ) {
2285
- queue .Add (logger , pInfo .Pod )
2284
+ add = func (t * testing.T , logger klog.Logger , queue * PriorityQueue , pInfo * framework.QueuedPodInfo ) {
2285
+ if err := queue .Add (logger , pInfo .Pod ); err != nil {
2286
+ t .Fatalf ("Unexpected error during Add: %v" , err )
2287
+ }
2286
2288
}
2287
- addUnschedulablePodBackToUnschedulablePods = func (logger klog.Logger , queue * PriorityQueue , pInfo * framework.QueuedPodInfo ) {
2289
+ popAndRequeueAsUnschedulable = func (t * testing. T , logger klog.Logger , queue * PriorityQueue , pInfo * framework.QueuedPodInfo ) {
2288
2290
// To simulate the pod is failed in scheduling in the real world, Pop() the pod from activeQ before AddUnschedulableIfNotPresent() below.
2289
- queue .activeQ .Add (queue .newQueuedPodInfo (pInfo .Pod ))
2290
- if p , err := queue .Pop (); err != nil || p .Pod != pInfo .Pod {
2291
- panic (fmt .Sprintf ("Expected: %v after Pop, but got: %v" , pInfo .Pod .Name , p .Pod .Name ))
2291
+ // UnschedulablePlugins will get cleared by Pop, so make a copy first.
2292
+ unschedulablePlugins := pInfo .UnschedulablePlugins .Clone ()
2293
+ if err := queue .activeQ .Add (queue .newQueuedPodInfo (pInfo .Pod )); err != nil {
2294
+ t .Fatalf ("Unexpected error during Add: %v" , err )
2295
+ }
2296
+ p , err := queue .Pop ()
2297
+ if err != nil {
2298
+ t .Fatalf ("Unexpected error during Pop: %v" , err )
2299
+ }
2300
+ if p .Pod != pInfo .Pod {
2301
+ t .Fatalf ("Expected: %v after Pop, but got: %v" , pInfo .Pod .Name , p .Pod .Name )
2302
+ }
2303
+ // Simulate plugins that are waiting for some events.
2304
+ p .UnschedulablePlugins = unschedulablePlugins
2305
+ if err := queue .AddUnschedulableIfNotPresent (logger , p , 1 ); err != nil {
2306
+ t .Fatalf ("Unexpected error during AddUnschedulableIfNotPresent: %v" , err )
2292
2307
}
2293
-
2294
- queue .AddUnschedulableIfNotPresent (logger , pInfo , 1 )
2295
2308
}
2296
- addUnschedulablePodBackToBackoffQ = func (logger klog.Logger , queue * PriorityQueue , pInfo * framework.QueuedPodInfo ) {
2297
- queue .AddUnschedulableIfNotPresent (logger , pInfo , 1 )
2309
+ popAndRequeueAsBackoff = func (t * testing.T , logger klog.Logger , queue * PriorityQueue , pInfo * framework.QueuedPodInfo ) {
2310
+ // To simulate the pod is failed in scheduling in the real world, Pop() the pod from activeQ before AddUnschedulableIfNotPresent() below.
2311
+ if err := queue .activeQ .Add (queue .newQueuedPodInfo (pInfo .Pod )); err != nil {
2312
+ t .Fatalf ("Unexpected error during Add: %v" , err )
2313
+ }
2314
+ p , err := queue .Pop ()
2315
+ if err != nil {
2316
+ t .Fatalf ("Unexpected error during Pop: %v" , err )
2317
+ }
2318
+ if p .Pod != pInfo .Pod {
2319
+ t .Fatalf ("Expected: %v after Pop, but got: %v" , pInfo .Pod .Name , p .Pod .Name )
2320
+ }
2321
+ // When there is no known unschedulable plugin, pods always go to the backoff queue.
2322
+ if err := queue .AddUnschedulableIfNotPresent (logger , p , 1 ); err != nil {
2323
+ t .Fatalf ("Unexpected error during AddUnschedulableIfNotPresent: %v" , err )
2324
+ }
2298
2325
}
2299
- addPodActiveQ = func (logger klog.Logger , queue * PriorityQueue , pInfo * framework.QueuedPodInfo ) {
2326
+ addPodActiveQ = func (t * testing. T , logger klog.Logger , queue * PriorityQueue , pInfo * framework.QueuedPodInfo ) {
2300
2327
queue .activeQ .Add (pInfo )
2301
2328
}
2302
- updatePodActiveQ = func (logger klog.Logger , queue * PriorityQueue , pInfo * framework.QueuedPodInfo ) {
2329
+ updatePodActiveQ = func (t * testing. T , logger klog.Logger , queue * PriorityQueue , pInfo * framework.QueuedPodInfo ) {
2303
2330
queue .activeQ .Update (pInfo )
2304
2331
}
2305
- addPodUnschedulablePods = func (logger klog.Logger , queue * PriorityQueue , pInfo * framework.QueuedPodInfo ) {
2332
+ addPodUnschedulablePods = func (t * testing. T , logger klog.Logger , queue * PriorityQueue , pInfo * framework.QueuedPodInfo ) {
2306
2333
if ! pInfo .Gated {
2307
2334
// Update pod condition to unschedulable.
2308
2335
podutil .UpdatePodCondition (& pInfo .Pod .Status , & v1.PodCondition {
@@ -2314,28 +2341,28 @@ var (
2314
2341
}
2315
2342
queue .unschedulablePods .addOrUpdate (pInfo )
2316
2343
}
2317
- deletePod = func (_ klog.Logger , queue * PriorityQueue , pInfo * framework.QueuedPodInfo ) {
2344
+ deletePod = func (t * testing. T , _ klog.Logger , queue * PriorityQueue , pInfo * framework.QueuedPodInfo ) {
2318
2345
queue .Delete (pInfo .Pod )
2319
2346
}
2320
- updatePodQueueable = func (logger klog.Logger , queue * PriorityQueue , pInfo * framework.QueuedPodInfo ) {
2347
+ updatePodQueueable = func (t * testing. T , logger klog.Logger , queue * PriorityQueue , pInfo * framework.QueuedPodInfo ) {
2321
2348
newPod := pInfo .Pod .DeepCopy ()
2322
2349
newPod .Labels = map [string ]string {"queueable" : "" }
2323
2350
queue .Update (logger , pInfo .Pod , newPod )
2324
2351
}
2325
- addPodBackoffQ = func (logger klog.Logger , queue * PriorityQueue , pInfo * framework.QueuedPodInfo ) {
2352
+ addPodBackoffQ = func (t * testing. T , logger klog.Logger , queue * PriorityQueue , pInfo * framework.QueuedPodInfo ) {
2326
2353
queue .podBackoffQ .Add (pInfo )
2327
2354
}
2328
- moveAllToActiveOrBackoffQ = func (logger klog.Logger , queue * PriorityQueue , _ * framework.QueuedPodInfo ) {
2355
+ moveAllToActiveOrBackoffQ = func (t * testing. T , logger klog.Logger , queue * PriorityQueue , _ * framework.QueuedPodInfo ) {
2329
2356
queue .MoveAllToActiveOrBackoffQueue (logger , UnschedulableTimeout , nil , nil , nil )
2330
2357
}
2331
- flushBackoffQ = func (logger klog.Logger , queue * PriorityQueue , _ * framework.QueuedPodInfo ) {
2358
+ flushBackoffQ = func (t * testing. T , logger klog.Logger , queue * PriorityQueue , _ * framework.QueuedPodInfo ) {
2332
2359
queue .clock .(* testingclock.FakeClock ).Step (2 * time .Second )
2333
2360
queue .flushBackoffQCompleted (logger )
2334
2361
}
2335
- moveClockForward = func (logger klog.Logger , queue * PriorityQueue , _ * framework.QueuedPodInfo ) {
2362
+ moveClockForward = func (t * testing. T , logger klog.Logger , queue * PriorityQueue , _ * framework.QueuedPodInfo ) {
2336
2363
queue .clock .(* testingclock.FakeClock ).Step (2 * time .Second )
2337
2364
}
2338
- flushUnschedulerQ = func (logger klog.Logger , queue * PriorityQueue , _ * framework.QueuedPodInfo ) {
2365
+ flushUnschedulerQ = func (t * testing. T , logger klog.Logger , queue * PriorityQueue , _ * framework.QueuedPodInfo ) {
2339
2366
queue .clock .(* testingclock.FakeClock ).Step (queue .podMaxInUnschedulablePodsDuration )
2340
2367
queue .flushUnschedulablePodsLeftover (logger )
2341
2368
}
@@ -2413,7 +2440,7 @@ func TestPodTimestamp(t *testing.T) {
2413
2440
var podInfoList []* framework.QueuedPodInfo
2414
2441
2415
2442
for i , op := range test .operations {
2416
- op (logger , queue , test .operands [i ])
2443
+ op (t , logger , queue , test .operands [i ])
2417
2444
}
2418
2445
2419
2446
expectedLen := len (test .expected )
@@ -2698,7 +2725,7 @@ scheduler_plugin_execution_duration_seconds_count{extension_point="PreEnqueue",p
2698
2725
queue := NewTestQueue (ctx , newDefaultQueueSort (), WithClock (testingclock .NewFakeClock (timestamp )), WithPreEnqueuePluginMap (m ), WithPluginMetricsSamplePercent (test .pluginMetricsSamplePercent ), WithMetricsRecorder (* recorder ))
2699
2726
for i , op := range test .operations {
2700
2727
for _ , pInfo := range test .operands [i ] {
2701
- op (logger , queue , pInfo )
2728
+ op (t , logger , queue , pInfo )
2702
2729
}
2703
2730
}
2704
2731
@@ -2856,7 +2883,7 @@ func TestIncomingPodsMetrics(t *testing.T) {
2856
2883
{
2857
2884
name : "add pods to unschedulablePods" ,
2858
2885
operations : []operation {
2859
- addUnschedulablePodBackToUnschedulablePods ,
2886
+ popAndRequeueAsUnschedulable ,
2860
2887
},
2861
2888
want : `
2862
2889
scheduler_queue_incoming_pods_total{event="ScheduleAttemptFailure",queue="unschedulable"} 3
@@ -2865,7 +2892,7 @@ func TestIncomingPodsMetrics(t *testing.T) {
2865
2892
{
2866
2893
name : "add pods to unschedulablePods and then move all to backoffQ" ,
2867
2894
operations : []operation {
2868
- addUnschedulablePodBackToUnschedulablePods ,
2895
+ popAndRequeueAsUnschedulable ,
2869
2896
moveAllToActiveOrBackoffQ ,
2870
2897
},
2871
2898
want : ` scheduler_queue_incoming_pods_total{event="ScheduleAttemptFailure",queue="unschedulable"} 3
@@ -2875,7 +2902,7 @@ func TestIncomingPodsMetrics(t *testing.T) {
2875
2902
{
2876
2903
name : "add pods to unschedulablePods and then move all to activeQ" ,
2877
2904
operations : []operation {
2878
- addUnschedulablePodBackToUnschedulablePods ,
2905
+ popAndRequeueAsUnschedulable ,
2879
2906
moveClockForward ,
2880
2907
moveAllToActiveOrBackoffQ ,
2881
2908
},
@@ -2886,7 +2913,7 @@ func TestIncomingPodsMetrics(t *testing.T) {
2886
2913
{
2887
2914
name : "make some pods subject to backoff and add them to backoffQ, then flush backoffQ" ,
2888
2915
operations : []operation {
2889
- addUnschedulablePodBackToBackoffQ ,
2916
+ popAndRequeueAsBackoff ,
2890
2917
moveClockForward ,
2891
2918
flushBackoffQ ,
2892
2919
},
@@ -2905,7 +2932,7 @@ func TestIncomingPodsMetrics(t *testing.T) {
2905
2932
queue := NewTestQueue (ctx , newDefaultQueueSort (), WithClock (testingclock .NewFakeClock (timestamp )))
2906
2933
for _ , op := range test .operations {
2907
2934
for _ , pInfo := range pInfos {
2908
- op (logger , queue , pInfo )
2935
+ op (t , logger , queue , pInfo )
2909
2936
}
2910
2937
}
2911
2938
metricName := metrics .SchedulerSubsystem + "_" + metrics .SchedulerQueueIncomingPods .Name
0 commit comments