fix flaky test TestMarkMessagesSeenMarksNotificationsRead (#4781)

* fix flaky test TestMarkMessagesSeenMarksNotificationsRead

* address review feedback
This commit is contained in:
frank 2024-02-22 09:44:14 +08:00 committed by GitHub
parent f650915a49
commit 01b3f8ace4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 11 deletions

View File

@ -2,7 +2,6 @@ package protocol
import (
"context"
"errors"
"testing"
"github.com/stretchr/testify/suite"
@ -376,16 +375,16 @@ func (s *MessengerActivityCenterMessageSuite) prepareCommunityChannelWithMention
"no messages",
)
s.Require().NoError(err)
replyNotification := response.ActivityCenterNotifications()[0]
s.Require().False(response.ActivityCenterNotifications()[0].Read)
// There is an extra message with reply
if response.Messages()[0].ID == response.ActivityCenterNotifications()[0].Message.ID {
replyMessage = response.Messages()[0]
} else if response.Messages()[1].ID == response.ActivityCenterNotifications()[0].Message.ID {
replyMessage = response.Messages()[1]
} else {
s.Error(errors.New("can't find corresponding message in the response"))
}
// One message is the community message, the other is the reply to the community message
s.Require().Len(response.Messages(), 2)
replyMessage, ok := response.messages[replyNotification.Message.ID]
s.Require().True(ok)
s.Require().NotNil(replyMessage)
s.Require().Equal(replyMessage.ID, replyNotification.ID.String())
s.confirmMentionAndReplyNotificationsRead(alice, mentionMessage, replyMessage, false)
@ -412,9 +411,9 @@ func (s *MessengerActivityCenterMessageSuite) confirmMentionAndReplyNotification
s.Require().NoError(err)
s.Require().Len(notifResponse.Notifications, 1)
s.Require().Equal(read, notifResponse.Notifications[0].Read)
s.Require().Equal(mentionMessage.ID, notifResponse.Notifications[0].ID.String())
}
/*
func (s *MessengerActivityCenterMessageSuite) TestMarkMessagesSeenMarksNotificationsRead() {
alice, _, mentionMessage, replyMessage, _ := s.prepareCommunityChannelWithMentionAndReply()
@ -427,7 +426,6 @@ func (s *MessengerActivityCenterMessageSuite) TestMarkMessagesSeenMarksNotificat
s.confirmMentionAndReplyNotificationsRead(alice, mentionMessage, replyMessage, true)
}
*/
func (s *MessengerActivityCenterMessageSuite) TestMarkAllReadMarksNotificationsRead() {
alice, _, mentionMessage, replyMessage, _ := s.prepareCommunityChannelWithMentionAndReply()

View File

@ -687,6 +687,13 @@ func (r *MessengerResponse) DiscordMessageAttachments() []*protobuf.DiscordMessa
return attachments
}
// Messages extracts the messages from the response and returns them as a slice.
// Since 'r.messages' is a map, the order of messages in the resulting slice is not
// guaranteed and can vary with each call to this method. This is inherent to Go's map
// iteration behavior, which does not define a sequence for the order of map elements.
// Consumers should not depend on the ordering of messages in the slice for any logic
// that requires consistent ordering, as map iteration order can change when keys are
// added or deleted. Consider sorting the slice after retrieval if a specific order is needed.
func (r *MessengerResponse) Messages() []*common.Message {
var ms []*common.Message
for _, m := range r.messages {