Skip to content

Commit

Permalink
Fix e2e test panic when expected events not found (#5845)
Browse files Browse the repository at this point in the history
Generating events is asynchronous, e2e test should check it eventually
gets the event. It should check the length of events first before
accessing the index.

Signed-off-by: Quan Tian <[email protected]>
  • Loading branch information
tnqn authored Jan 5, 2024
1 parent fed260a commit 33e2abb
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions test/e2e/egress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,12 @@ func testEgressCRUD(t *testing.T, data *TestData) {
assert.True(t, exists, "Didn't find desired IP on Node")
// Testing the events recorded during creation of an Egress resource.
expectedMessage := fmt.Sprintf("Assigned Egress %s with IP %s on Node %v", egress.Name, tt.expectedEgressIP, egress.Status.EgressNode)
events, err := data.clientset.CoreV1().Events("").Search(scheme.Scheme, egress)
require.NoError(t, err)
assert.Contains(t, events.Items[0].Message, expectedMessage)
assert.EventuallyWithT(t, func(c *assert.CollectT) {
events, err := data.clientset.CoreV1().Events("").Search(scheme.Scheme, egress)
if assert.NoError(c, err) && assert.Len(c, events.Items, 1) {
assert.Contains(c, events.Items[0].Message, expectedMessage)
}
}, 2*time.Second, 200*time.Millisecond)
}

checkEIPStatus := func(expectedUsed int) {
Expand Down

0 comments on commit 33e2abb

Please sign in to comment.