MM-56948 Fix flaky TestUserHasJoinedChannel (#26359)

* MM-56948 Fix flaky TestUserHasJoinedChannel

* Add comment explaining flakiness
This commit is contained in:
Harrison Healey 2024-03-04 15:16:56 -05:00 committed by GitHub
parent 6ba3ac4a02
commit d5446cd25e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2018,12 +2018,23 @@ func TestUserHasJoinedChannel(t *testing.T) {
})
require.Nil(t, appErr)
assert.EventuallyWithT(t, func(t *assert.CollectT) {
posts, appErr := th.App.GetPosts(channel.Id, 0, 1)
expectedMessage := fmt.Sprintf("Test: User %s added to %s by %s", user2.Id, channel.Id, user1.Id)
assert.Eventually(t, func() bool {
// Typically, the post we're looking for will be the latest, but there's a race between the plugin and
// "User has joined the channel" post which means the plugin post may not the the latest one
posts, appErr := th.App.GetPosts(channel.Id, 0, 10)
require.Nil(t, appErr)
assert.Equal(t, fmt.Sprintf("Test: User %s added to %s by %s", user2.Id, channel.Id, user1.Id), posts.Posts[posts.Order[0]].Message)
for _, postId := range posts.Order {
post := posts.Posts[postId]
if post.Message == expectedMessage {
return true
}
}
return false
}, 1*time.Second, 10*time.Millisecond)
})