@@ -310,34 +310,42 @@ func TestPriorityQueue_Pop(t *testing.T) {
310
310
func TestPriorityQueue_Update (t * testing.T ) {
311
311
q := createAndRunPriorityQueue (newDefaultFramework ())
312
312
q .Update (nil , & highPriorityPod )
313
+ q .lock .RLock ()
313
314
if _ , exists , _ := q .activeQ .Get (newPodInfoNoTimestamp (& highPriorityPod )); ! exists {
314
315
t .Errorf ("Expected %v to be added to activeQ." , highPriorityPod .Name )
315
316
}
317
+ q .lock .RUnlock ()
316
318
if len (q .nominatedPods .nominatedPods ) != 0 {
317
319
t .Errorf ("Expected nomindatePods to be empty: %v" , q .nominatedPods )
318
320
}
319
321
// Update highPriorityPod and add a nominatedNodeName to it.
320
322
q .Update (& highPriorityPod , & highPriNominatedPod )
323
+ q .lock .RLock ()
321
324
if q .activeQ .Len () != 1 {
322
325
t .Error ("Expected only one item in activeQ." )
323
326
}
327
+ q .lock .RUnlock ()
324
328
if len (q .nominatedPods .nominatedPods ) != 1 {
325
329
t .Errorf ("Expected one item in nomindatePods map: %v" , q .nominatedPods )
326
330
}
327
331
// Updating an unschedulable pod which is not in any of the two queues, should
328
332
// add the pod to activeQ.
329
333
q .Update (& unschedulablePod , & unschedulablePod )
334
+ q .lock .RLock ()
330
335
if _ , exists , _ := q .activeQ .Get (newPodInfoNoTimestamp (& unschedulablePod )); ! exists {
331
336
t .Errorf ("Expected %v to be added to activeQ." , unschedulablePod .Name )
332
337
}
338
+ q .lock .RUnlock ()
333
339
// Updating a pod that is already in activeQ, should not change it.
334
340
q .Update (& unschedulablePod , & unschedulablePod )
335
341
if len (q .unschedulableQ .podInfoMap ) != 0 {
336
342
t .Error ("Expected unschedulableQ to be empty." )
337
343
}
344
+ q .lock .RLock ()
338
345
if _ , exists , _ := q .activeQ .Get (newPodInfoNoTimestamp (& unschedulablePod )); ! exists {
339
346
t .Errorf ("Expected: %v to be added to activeQ." , unschedulablePod .Name )
340
347
}
348
+ q .lock .RUnlock ()
341
349
if p , err := q .Pop (); err != nil || p .Pod != & highPriNominatedPod {
342
350
t .Errorf ("Expected: %v after Pop, but got: %v" , highPriorityPod .Name , p .Pod .Name )
343
351
}
@@ -362,12 +370,14 @@ func TestPriorityQueue_Delete(t *testing.T) {
362
370
if err := q .Delete (& highPriNominatedPod ); err != nil {
363
371
t .Errorf ("delete failed: %v" , err )
364
372
}
373
+ q .lock .RLock ()
365
374
if _ , exists , _ := q .activeQ .Get (newPodInfoNoTimestamp (& unschedulablePod )); ! exists {
366
375
t .Errorf ("Expected %v to be in activeQ." , unschedulablePod .Name )
367
376
}
368
377
if _ , exists , _ := q .activeQ .Get (newPodInfoNoTimestamp (& highPriNominatedPod )); exists {
369
378
t .Errorf ("Didn't expect %v to be in activeQ." , highPriorityPod .Name )
370
379
}
380
+ q .lock .RUnlock ()
371
381
if len (q .nominatedPods .nominatedPods ) != 1 {
372
382
t .Errorf ("Expected nomindatePods to have only 'unschedulablePod': %v" , q .nominatedPods .nominatedPods )
373
383
}
@@ -385,6 +395,8 @@ func TestPriorityQueue_MoveAllToActiveOrBackoffQueue(t *testing.T) {
385
395
q .AddUnschedulableIfNotPresent (q .newPodInfo (& unschedulablePod ), q .SchedulingCycle ())
386
396
q .AddUnschedulableIfNotPresent (q .newPodInfo (& highPriorityPod ), q .SchedulingCycle ())
387
397
q .MoveAllToActiveOrBackoffQueue ("test" )
398
+ q .lock .RLock ()
399
+ defer q .lock .RUnlock ()
388
400
if q .activeQ .Len () != 1 {
389
401
t .Error ("Expected 1 item to be in activeQ" )
390
402
}
@@ -444,9 +456,11 @@ func TestPriorityQueue_AssignedPodAdded(t *testing.T) {
444
456
if getUnschedulablePod (q , affinityPod ) != nil {
445
457
t .Error ("affinityPod is still in the unschedulableQ." )
446
458
}
459
+ q .lock .RLock ()
447
460
if _ , exists , _ := q .activeQ .Get (newPodInfoNoTimestamp (affinityPod )); ! exists {
448
461
t .Error ("affinityPod is not moved to activeQ." )
449
462
}
463
+ q .lock .RUnlock ()
450
464
// Check that the other pod is still in the unschedulableQ.
451
465
if getUnschedulablePod (q , & unschedulablePod ) == nil {
452
466
t .Error ("unschedulablePod is not in the unschedulableQ." )
@@ -1175,13 +1189,15 @@ func TestPodTimestamp(t *testing.T) {
1175
1189
op (queue , test .operands [i ])
1176
1190
}
1177
1191
1192
+ queue .lock .Lock ()
1178
1193
for i := 0 ; i < len (test .expected ); i ++ {
1179
1194
if pInfo , err := queue .activeQ .Pop (); err != nil {
1180
1195
t .Errorf ("Error while popping the head of the queue: %v" , err )
1181
1196
} else {
1182
1197
podInfoList = append (podInfoList , pInfo .(* framework.PodInfo ))
1183
1198
}
1184
1199
}
1200
+ queue .lock .Unlock ()
1185
1201
1186
1202
if ! reflect .DeepEqual (test .expected , podInfoList ) {
1187
1203
t .Errorf ("Unexpected PodInfo list. Expected: %v, got: %v" ,
@@ -1559,9 +1575,11 @@ func TestBackOffFlow(t *testing.T) {
1559
1575
// An event happens.
1560
1576
q .MoveAllToActiveOrBackoffQueue ("deleted pod" )
1561
1577
1578
+ q .lock .RLock ()
1562
1579
if _ , ok , _ := q .podBackoffQ .Get (podInfo ); ! ok {
1563
1580
t .Errorf ("pod %v is not in the backoff queue" , podID )
1564
1581
}
1582
+ q .lock .RUnlock ()
1565
1583
1566
1584
// Check backoff duration.
1567
1585
deadline := q .getBackoffTime (podInfo )
@@ -1574,15 +1592,19 @@ func TestBackOffFlow(t *testing.T) {
1574
1592
cl .Step (time .Millisecond )
1575
1593
q .flushBackoffQCompleted ()
1576
1594
// Still in backoff queue after an early flush.
1595
+ q .lock .RLock ()
1577
1596
if _ , ok , _ := q .podBackoffQ .Get (podInfo ); ! ok {
1578
1597
t .Errorf ("pod %v is not in the backoff queue" , podID )
1579
1598
}
1599
+ q .lock .RUnlock ()
1580
1600
// Moved out of the backoff queue after timeout.
1581
1601
cl .Step (backoff )
1582
1602
q .flushBackoffQCompleted ()
1603
+ q .lock .RLock ()
1583
1604
if _ , ok , _ := q .podBackoffQ .Get (podInfo ); ok {
1584
1605
t .Errorf ("pod %v is still in the backoff queue" , podID )
1585
1606
}
1607
+ q .lock .RUnlock ()
1586
1608
})
1587
1609
}
1588
1610
}
0 commit comments