@@ -129,7 +129,7 @@ func getUnschedulablePod(p *PriorityQueue, pod *v1.Pod) *v1.Pod {
129
129
}
130
130
131
131
func TestPriorityQueue_Add (t * testing.T ) {
132
- q := NewPriorityQueue ( nil , nil )
132
+ q := createAndRunPriorityQueue ( nil )
133
133
if err := q .Add (& medPriorityPod ); err != nil {
134
134
t .Errorf ("add failed: %v" , err )
135
135
}
@@ -259,7 +259,7 @@ func (*fakeFramework) SnapshotSharedLister() schedulerlisters.SharedLister {
259
259
}
260
260
261
261
func TestPriorityQueue_AddWithReversePriorityLessFunc (t * testing.T ) {
262
- q := NewPriorityQueue ( nil , & fakeFramework {})
262
+ q := createAndRunPriorityQueue ( & fakeFramework {})
263
263
if err := q .Add (& medPriorityPod ); err != nil {
264
264
t .Errorf ("add failed: %v" , err )
265
265
}
@@ -275,7 +275,7 @@ func TestPriorityQueue_AddWithReversePriorityLessFunc(t *testing.T) {
275
275
}
276
276
277
277
func TestPriorityQueue_AddUnschedulableIfNotPresent (t * testing.T ) {
278
- q := NewPriorityQueue ( nil , nil )
278
+ q := createAndRunPriorityQueue ( nil )
279
279
q .Add (& highPriNominatedPod )
280
280
q .AddUnschedulableIfNotPresent (newPodInfoNoTimestamp (& highPriNominatedPod ), q .SchedulingCycle ()) // Must not add anything.
281
281
q .AddUnschedulableIfNotPresent (newPodInfoNoTimestamp (& unschedulablePod ), q .SchedulingCycle ())
@@ -307,7 +307,7 @@ func TestPriorityQueue_AddUnschedulableIfNotPresent(t *testing.T) {
307
307
// Pods in and before current scheduling cycle will be put back to activeQueue
308
308
// if we were trying to schedule them when we received move request.
309
309
func TestPriorityQueue_AddUnschedulableIfNotPresent_Backoff (t * testing.T ) {
310
- q := NewPriorityQueue ( nil , nil , WithClock (clock .NewFakeClock (time .Now ())))
310
+ q := createAndRunPriorityQueue ( nil , WithClock (clock .NewFakeClock (time .Now ())))
311
311
totalNum := 10
312
312
expectedPods := make ([]v1.Pod , 0 , totalNum )
313
313
for i := 0 ; i < totalNum ; i ++ {
@@ -374,7 +374,7 @@ func TestPriorityQueue_AddUnschedulableIfNotPresent_Backoff(t *testing.T) {
374
374
}
375
375
376
376
func TestPriorityQueue_Pop (t * testing.T ) {
377
- q := NewPriorityQueue ( nil , nil )
377
+ q := createAndRunPriorityQueue ( nil )
378
378
wg := sync.WaitGroup {}
379
379
wg .Add (1 )
380
380
go func () {
@@ -391,7 +391,7 @@ func TestPriorityQueue_Pop(t *testing.T) {
391
391
}
392
392
393
393
func TestPriorityQueue_Update (t * testing.T ) {
394
- q := NewPriorityQueue ( nil , nil )
394
+ q := createAndRunPriorityQueue ( nil )
395
395
q .Update (nil , & highPriorityPod )
396
396
if _ , exists , _ := q .activeQ .Get (newPodInfoNoTimestamp (& highPriorityPod )); ! exists {
397
397
t .Errorf ("Expected %v to be added to activeQ." , highPriorityPod .Name )
@@ -427,7 +427,7 @@ func TestPriorityQueue_Update(t *testing.T) {
427
427
}
428
428
429
429
func TestPriorityQueue_Delete (t * testing.T ) {
430
- q := NewPriorityQueue ( nil , nil )
430
+ q := createAndRunPriorityQueue ( nil )
431
431
q .Update (& highPriorityPod , & highPriNominatedPod )
432
432
q .Add (& unschedulablePod )
433
433
if err := q .Delete (& highPriNominatedPod ); err != nil {
@@ -451,7 +451,7 @@ func TestPriorityQueue_Delete(t *testing.T) {
451
451
}
452
452
453
453
func TestPriorityQueue_MoveAllToActiveQueue (t * testing.T ) {
454
- q := NewPriorityQueue ( nil , nil )
454
+ q := createAndRunPriorityQueue ( nil )
455
455
q .Add (& medPriorityPod )
456
456
addOrUpdateUnschedulablePod (q , q .newPodInfo (& unschedulablePod ))
457
457
addOrUpdateUnschedulablePod (q , q .newPodInfo (& highPriorityPod ))
@@ -497,7 +497,7 @@ func TestPriorityQueue_AssignedPodAdded(t *testing.T) {
497
497
Spec : v1.PodSpec {NodeName : "machine1" },
498
498
}
499
499
500
- q := NewPriorityQueue ( nil , nil )
500
+ q := createAndRunPriorityQueue ( nil )
501
501
q .Add (& medPriorityPod )
502
502
// Add a couple of pods to the unschedulableQ.
503
503
addOrUpdateUnschedulablePod (q , q .newPodInfo (& unschedulablePod ))
@@ -518,7 +518,7 @@ func TestPriorityQueue_AssignedPodAdded(t *testing.T) {
518
518
}
519
519
520
520
func TestPriorityQueue_NominatedPodsForNode (t * testing.T ) {
521
- q := NewPriorityQueue ( nil , nil )
521
+ q := createAndRunPriorityQueue ( nil )
522
522
q .Add (& medPriorityPod )
523
523
q .Add (& unschedulablePod )
524
524
q .Add (& highPriorityPod )
@@ -543,7 +543,7 @@ func TestPriorityQueue_PendingPods(t *testing.T) {
543
543
return pendingSet
544
544
}
545
545
546
- q := NewPriorityQueue ( nil , nil )
546
+ q := createAndRunPriorityQueue ( nil )
547
547
q .Add (& medPriorityPod )
548
548
addOrUpdateUnschedulablePod (q , q .newPodInfo (& unschedulablePod ))
549
549
addOrUpdateUnschedulablePod (q , q .newPodInfo (& highPriorityPod ))
@@ -559,7 +559,7 @@ func TestPriorityQueue_PendingPods(t *testing.T) {
559
559
}
560
560
561
561
func TestPriorityQueue_UpdateNominatedPodForNode (t * testing.T ) {
562
- q := NewPriorityQueue ( nil , nil )
562
+ q := createAndRunPriorityQueue ( nil )
563
563
if err := q .Add (& medPriorityPod ); err != nil {
564
564
t .Errorf ("add failed: %v" , err )
565
565
}
@@ -628,8 +628,7 @@ func TestPriorityQueue_UpdateNominatedPodForNode(t *testing.T) {
628
628
}
629
629
630
630
func TestPriorityQueue_NewWithOptions (t * testing.T ) {
631
- q := NewPriorityQueue (
632
- nil ,
631
+ q := createAndRunPriorityQueue (
633
632
nil ,
634
633
WithPodInitialBackoffDuration (2 * time .Second ),
635
634
WithPodMaxBackoffDuration (20 * time .Second ),
@@ -802,7 +801,7 @@ func TestSchedulingQueue_Close(t *testing.T) {
802
801
}{
803
802
{
804
803
name : "PriorityQueue close" ,
805
- q : NewPriorityQueue ( nil , nil ),
804
+ q : createAndRunPriorityQueue ( nil ),
806
805
expectedErr : fmt .Errorf (queueClosed ),
807
806
},
808
807
}
@@ -831,7 +830,7 @@ func TestSchedulingQueue_Close(t *testing.T) {
831
830
// ensures that an unschedulable pod does not block head of the queue when there
832
831
// are frequent events that move pods to the active queue.
833
832
func TestRecentlyTriedPodsGoBack (t * testing.T ) {
834
- q := NewPriorityQueue ( nil , nil )
833
+ q := createAndRunPriorityQueue ( nil )
835
834
// Add a few pods to priority queue.
836
835
for i := 0 ; i < 5 ; i ++ {
837
836
p := v1.Pod {
@@ -885,7 +884,7 @@ func TestRecentlyTriedPodsGoBack(t *testing.T) {
885
884
// This behavior ensures that an unschedulable pod does not block head of the queue when there
886
885
// are frequent events that move pods to the active queue.
887
886
func TestPodFailedSchedulingMultipleTimesDoesNotBlockNewerPod (t * testing.T ) {
888
- q := NewPriorityQueue ( nil , nil )
887
+ q := createAndRunPriorityQueue ( nil )
889
888
890
889
// Add an unschedulable pod to a priority queue.
891
890
// This makes a situation that the pod was tried to schedule
@@ -976,7 +975,7 @@ func TestPodFailedSchedulingMultipleTimesDoesNotBlockNewerPod(t *testing.T) {
976
975
// TestHighPriorityBackoff tests that a high priority pod does not block
977
976
// other pods if it is unschedulable
978
977
func TestHighPriorityBackoff (t * testing.T ) {
979
- q := NewPriorityQueue ( nil , nil )
978
+ q := createAndRunPriorityQueue ( nil )
980
979
981
980
midPod := v1.Pod {
982
981
ObjectMeta : metav1.ObjectMeta {
@@ -1039,7 +1038,7 @@ func TestHighPriorityBackoff(t *testing.T) {
1039
1038
// TestHighPriorityFlushUnschedulableQLeftover tests that pods will be moved to
1040
1039
// activeQ after one minutes if it is in unschedulableQ
1041
1040
func TestHighPriorityFlushUnschedulableQLeftover (t * testing.T ) {
1042
- q := NewPriorityQueue ( nil , nil )
1041
+ q := createAndRunPriorityQueue ( nil )
1043
1042
midPod := v1.Pod {
1044
1043
ObjectMeta : metav1.ObjectMeta {
1045
1044
Name : "test-midpod" ,
@@ -1236,7 +1235,7 @@ func TestPodTimestamp(t *testing.T) {
1236
1235
1237
1236
for _ , test := range tests {
1238
1237
t .Run (test .name , func (t * testing.T ) {
1239
- queue := NewPriorityQueue ( nil , nil , WithClock (clock .NewFakeClock (timestamp )))
1238
+ queue := createAndRunPriorityQueue ( nil , WithClock (clock .NewFakeClock (timestamp )))
1240
1239
var podInfoList []* framework.PodInfo
1241
1240
1242
1241
for i , op := range test .operations {
@@ -1403,7 +1402,7 @@ scheduler_pending_pods{queue="unschedulable"} 0
1403
1402
for _ , test := range tests {
1404
1403
t .Run (test .name , func (t * testing.T ) {
1405
1404
resetMetrics ()
1406
- queue := NewPriorityQueue ( nil , nil , WithClock (clock .NewFakeClock (timestamp )))
1405
+ queue := createAndRunPriorityQueue ( nil , WithClock (clock .NewFakeClock (timestamp )))
1407
1406
for i , op := range test .operations {
1408
1407
for _ , pInfo := range test .operands [i ] {
1409
1408
op (queue , pInfo )
@@ -1432,7 +1431,7 @@ func TestPerPodSchedulingMetrics(t *testing.T) {
1432
1431
// Case 1: A pod is created and scheduled after 1 attempt. The queue operations are
1433
1432
// Add -> Pop.
1434
1433
c := clock .NewFakeClock (timestamp )
1435
- queue := NewPriorityQueue ( nil , nil , WithClock (c ))
1434
+ queue := createAndRunPriorityQueue ( nil , WithClock (c ))
1436
1435
queue .Add (pod )
1437
1436
pInfo , err := queue .Pop ()
1438
1437
if err != nil {
@@ -1443,7 +1442,7 @@ func TestPerPodSchedulingMetrics(t *testing.T) {
1443
1442
// Case 2: A pod is created and scheduled after 2 attempts. The queue operations are
1444
1443
// Add -> Pop -> AddUnschedulableIfNotPresent -> flushUnschedulableQLeftover -> Pop.
1445
1444
c = clock .NewFakeClock (timestamp )
1446
- queue = NewPriorityQueue ( nil , nil , WithClock (c ))
1445
+ queue = createAndRunPriorityQueue ( nil , WithClock (c ))
1447
1446
queue .Add (pod )
1448
1447
pInfo , err = queue .Pop ()
1449
1448
if err != nil {
@@ -1463,7 +1462,7 @@ func TestPerPodSchedulingMetrics(t *testing.T) {
1463
1462
// Case 3: Similar to case 2, but before the second pop, call update, the queue operations are
1464
1463
// Add -> Pop -> AddUnschedulableIfNotPresent -> flushUnschedulableQLeftover -> Update -> Pop.
1465
1464
c = clock .NewFakeClock (timestamp )
1466
- queue = NewPriorityQueue ( nil , nil , WithClock (c ))
1465
+ queue = createAndRunPriorityQueue ( nil , WithClock (c ))
1467
1466
queue .Add (pod )
1468
1467
pInfo , err = queue .Pop ()
1469
1468
if err != nil {
@@ -1561,9 +1560,9 @@ func TestIncomingPodsMetrics(t *testing.T) {
1561
1560
for _ , test := range tests {
1562
1561
t .Run (test .name , func (t * testing.T ) {
1563
1562
metrics .SchedulerQueueIncomingPods .Reset ()
1564
- stop := make ( chan struct {} )
1565
- close ( stop ) // Stop the periodic flush
1566
- queue := NewPriorityQueue ( stop , nil , WithClock ( clock . NewFakeClock ( timestamp )) )
1563
+ queue := NewPriorityQueue ( nil , WithClock ( clock . NewFakeClock ( timestamp )) )
1564
+ queue . Close ()
1565
+ queue . Run ( )
1567
1566
for _ , op := range test .operations {
1568
1567
for _ , pInfo := range pInfos {
1569
1568
op (queue , pInfo )
@@ -1586,3 +1585,9 @@ func checkPerPodSchedulingMetrics(name string, t *testing.T, pInfo *framework.Po
1586
1585
t .Errorf ("[%s] Pod initial schedule attempt timestamp unexpected, got %v, want %v" , name , pInfo .InitialAttemptTimestamp , wantInitialAttemptTs )
1587
1586
}
1588
1587
}
1588
+
1589
+ func createAndRunPriorityQueue (fwk framework.Framework , opts ... Option ) * PriorityQueue {
1590
+ q := NewPriorityQueue (fwk , opts ... )
1591
+ q .Run ()
1592
+ return q
1593
+ }
0 commit comments