@@ -1343,18 +1343,18 @@ func TestEviction(t *testing.T) {
1343
1343
}()
1344
1344
1345
1345
// Eventually the controller should have synced it's informers.
1346
- require .Eventually (tCtx , func () bool {
1346
+ ktesting .Eventually (tCtx , func (tCtx ktesting. TContext ) bool {
1347
1347
return controller .hasSynced .Load () > 0
1348
- }, 30 * time .Second , time . Millisecond , "controller synced" )
1348
+ }). WithTimeout ( 30 * time .Second ). Should ( gomega . BeTrueBecause ( "controller synced" ) )
1349
1349
if tt .afterSync != nil {
1350
1350
tt .afterSync (tCtx )
1351
1351
}
1352
1352
1353
1353
// Eventually the pod gets deleted (= evicted).
1354
- assert .Eventually (tCtx , func () bool {
1354
+ ktesting .Eventually (tCtx , func (tCtx ktesting. TContext ) bool {
1355
1355
_ , err := fakeClientset .CoreV1 ().Pods (pod .Namespace ).Get (tCtx , pod .Name , metav1.GetOptions {})
1356
1356
return apierrors .IsNotFound (err )
1357
- }, 30 * time .Second , time . Millisecond , "pod evicted" )
1357
+ }). WithTimeout ( 30 * time .Second ). Should ( gomega . BeTrueBecause ( "pod evicted" ) )
1358
1358
1359
1359
pod := pod .DeepCopy ()
1360
1360
pod .Status .Conditions = []v1.PodCondition {{
@@ -1369,7 +1369,10 @@ func TestEviction(t *testing.T) {
1369
1369
1370
1370
// Shortly after deletion we should also see updated metrics.
1371
1371
// This is the last thing the controller does for a pod.
1372
+ // However, actually creating the event on the server is asynchronous,
1373
+ // so we also have to wait for that.
1372
1374
ktesting .Eventually (tCtx , func (tCtx ktesting.TContext ) error {
1375
+ gomega .NewWithT (tCtx ).Expect (listEvents (tCtx )).Should (matchDeletionEvent ())
1373
1376
return testPodDeletionsMetrics (controller , 1 )
1374
1377
}).WithTimeout (30 * time .Second ).Should (gomega .Succeed (), "pod eviction done" )
1375
1378
@@ -1547,11 +1550,11 @@ func TestParallelPodDeletion(t *testing.T) {
1547
1550
}()
1548
1551
1549
1552
// Eventually the pod gets deleted, in this test by us.
1550
- assert .Eventually (tCtx , func () bool {
1553
+ ktesting .Eventually (tCtx , func (tCtx ktesting. TContext ) bool {
1551
1554
mutex .Lock ()
1552
1555
defer mutex .Unlock ()
1553
1556
return podGets >= 1
1554
- }, 30 * time .Second , time . Millisecond , "pod eviction started" )
1557
+ }). WithTimeout ( 30 * time .Second ). Should ( gomega . BeTrueBecause ( "pod eviction started" ) )
1555
1558
1556
1559
// We don't want any events.
1557
1560
ktesting .Consistently (tCtx , func (tCtx ktesting.TContext ) error {
@@ -1625,8 +1628,9 @@ func TestRetry(t *testing.T) {
1625
1628
assert .NoError (tCtx , controller .Run (tCtx ), "eviction controller failed" )
1626
1629
}()
1627
1630
1628
- // Eventually the pod gets deleted.
1631
+ // Eventually the pod gets deleted and the event is recorded .
1629
1632
ktesting .Eventually (tCtx , func (tCtx ktesting.TContext ) error {
1633
+ gomega .NewWithT (tCtx ).Expect (listEvents (tCtx )).Should (matchDeletionEvent ())
1630
1634
return testPodDeletionsMetrics (controller , 1 )
1631
1635
}).WithTimeout (30 * time .Second ).Should (gomega .Succeed (), "pod eviction done" )
1632
1636
@@ -1698,11 +1702,11 @@ func TestEvictionFailure(t *testing.T) {
1698
1702
}()
1699
1703
1700
1704
// Eventually deletion is attempted a few times.
1701
- assert .Eventually (tCtx , func () bool {
1705
+ ktesting .Eventually (tCtx , func (tCtx ktesting. TContext ) int {
1702
1706
mutex .Lock ()
1703
1707
defer mutex .Unlock ()
1704
- return podDeletions >= retries
1705
- }, 30 * time .Second , time . Millisecond , "pod eviction failed" )
1708
+ return podDeletions
1709
+ }). WithTimeout ( 30 * time .Second ). Should ( gomega . BeNumerically ( ">=" , retries ) , "pod eviction failed" )
1706
1710
1707
1711
// Now we can check the API calls.
1708
1712
ktesting .Consistently (tCtx , func (tCtx ktesting.TContext ) error {
0 commit comments