Skip to content

[v15] Fix flaky opsgenie recipients test#45271

Closed
EdwardDowling wants to merge 1 commit into
branch/v15from
edwarddowling/flaky-opsgenie-test
Closed

[v15] Fix flaky opsgenie recipients test#45271
EdwardDowling wants to merge 1 commit into
branch/v15from
edwarddowling/flaky-opsgenie-test

Conversation

@EdwardDowling
Copy link
Copy Markdown
Contributor

Fixes flaky test mentioned in #40653

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Aug 8, 2024

The PR changelog entry failed validation: Changelog entry not found in the PR body. Please add a "no-changelog" label to the PR, or changelog lines starting with changelog: followed by the changelog entries for the PR.

@EdwardDowling EdwardDowling added the no-changelog Indicates that a PR does not require a changelog entry label Aug 8, 2024
@zmb3 zmb3 changed the title Fix flaky opsgenie recipients test [v15] Fix flaky opsgenie recipients test Aug 8, 2024
@zmb3
Copy link
Copy Markdown
Collaborator

zmb3 commented Aug 8, 2024

I don't see how this changes the test, can you clarify?

Comment on lines -103 to +113
require.ElementsMatch(t, tt.expectedRecipients, recipients)

got := make(map[string]string, len(recipients))
for _, r := range recipients {
got[r.Name] = r.ID
}
want := make(map[string]string, len(tt.expectedRecipients))
for _, r := range tt.expectedRecipients {
want[r.Name] = r.ID
}

require.Equal(t, want, got)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this fixes the issue, it's probably because we were getting duplicates in recipients.

We should look into why we get them, instead of ignoring them by using a set.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue wasn't the duplicated recipients, it was that the test assumed an order to the return values. Added the results to a map just to compare without order mattering.

Copy link
Copy Markdown
Contributor

@marcoandredinis marcoandredinis Aug 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the docs, require.ElementsMatch does not care about the order:

https://pkg.go.dev/github.com/stretchr/testify/require#ElementsMatch

ElementsMatch asserts that the specified listA(array, slice...) is equal to specified listB(array, slice...) ignoring the order of the elements. If there are duplicate elements, the number of appearances of each of them in both lists should match.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sorry, you are right.
I am confused then by the message in the ticket then
expected: []common.Recipient{common.Recipient{Name:"foo", ID:"foo", Kind:"", Data:interface {}(nil)}, common.Recipient{Name:"bar", ID:"bar", Kind:"", Data:interface {}(nil)}} actual : []common.Recipient{common.Recipient{Name:"bar", ID:"bar", Kind:"", Data:interface {}(nil)}, common.Recipient{Name:"foo", ID:"foo", Kind:"", Data:interface {}(nil)}}
As it looks like the only difference is the order.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔
That error message comes from the fact that we were using require.Equals
However, it was fixed in this PR #40777
This PR was created 4 days after the flaky test was reported (in April).

I think we can close this PR, unless I'm missing something

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport no-changelog Indicates that a PR does not require a changelog entry size/sm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants