@@ -504,7 +504,7 @@ func TestReconciler_ProcessEvent(t *testing.T) {
504504 assert .Error (t , err )
505505 assert .Contains (t , err .Error (), "waiting for pods to complete" )
506506
507- nodeEvent := requireSingleNodeEvent (t , client , ctx , nodeName )
507+ nodeEvent := requireSingleNodeEvent (t , client , ctx , nodeName , 5 )
508508 require .Equal (t , v1 .EventTypeNormal , nodeEvent .Type )
509509 require .Equal (t , "AwaitingPodCompletion" , nodeEvent .Reason )
510510 expectedMessage := "Waiting for following pods to finish: [completion-test/running-pod-1]"
@@ -660,7 +660,7 @@ func TestReconciler_ProcessEvent(t *testing.T) {
660660 assert .Error (t , err )
661661 assert .Contains (t , err .Error (), "failed timeout eviction for node test-node: waiting for 1 pods to complete or timeout" )
662662
663- nodeEvent := requireSingleNodeEvent (t , client , ctx , nodeName )
663+ nodeEvent := requireSingleNodeEvent (t , client , ctx , nodeName , 1 )
664664 require .Equal (t , v1 .EventTypeNormal , nodeEvent .Type )
665665 require .Equal (t , "WaitingBeforeForceDelete" , nodeEvent .Reason )
666666 expectedMessage := "Waiting for following pods to finish: [pod-1] in namespace: [timeout-test] or they will be force deleted on:"
@@ -890,7 +890,7 @@ func TestReconciler_ProcessEvent(t *testing.T) {
890890 assert .Error (t , err )
891891 assert .Contains (t , err .Error (), "waiting for pods to complete" )
892892
893- nodeEvent := requireSingleNodeEvent (t , client , ctx , nodeName )
893+ nodeEvent := requireSingleNodeEvent (t , client , ctx , nodeName , 5 )
894894 require .Equal (t , v1 .EventTypeNormal , nodeEvent .Type )
895895 require .Equal (t , "AwaitingPodCompletion" , nodeEvent .Reason )
896896 expectedMessage := "Waiting for following pods to finish: [completion-test/running-pod-1 completion-test/running-pod-2 completion-test/running-pod-3]"
@@ -1396,6 +1396,7 @@ func requireSingleNodeEvent(
13961396 client kubernetes.Interface ,
13971397 ctx context.Context ,
13981398 nodeName string ,
1399+ expectedCount int32 ,
13991400) v1.Event {
14001401 t .Helper ()
14011402
@@ -1404,12 +1405,13 @@ func requireSingleNodeEvent(
14041405 }
14051406 require .Eventually (t , func () bool {
14061407 nodeEvents , err := client .CoreV1 ().Events (metav1 .NamespaceDefault ).List (ctx , eventListOptions )
1407- return err == nil && len (nodeEvents .Items ) == 1
1408- }, 5 * time .Second , 50 * time .Millisecond , "node event should be recorded asynchronously" )
1408+ return err == nil && len (nodeEvents .Items ) == 1 && nodeEvents . Items [ 0 ]. Count == expectedCount
1409+ }, 5 * time .Second , 50 * time .Millisecond , "node event should be recorded asynchronously with count %d" , expectedCount )
14091410
14101411 nodeEvents , err := client .CoreV1 ().Events (metav1 .NamespaceDefault ).List (ctx , eventListOptions )
14111412 require .NoError (t , err )
14121413 require .Len (t , nodeEvents .Items , 1 , "only one event should be created despite multiple reconciliations" )
1414+ require .Equal (t , expectedCount , nodeEvents .Items [0 ].Count )
14131415
14141416 return nodeEvents .Items [0 ]
14151417}
0 commit comments