Skip to content

Commit

Permalink
Added test when message is synthesized, check newness by timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
sacOO7 committed Nov 9, 2023
1 parent 9dfe0ae commit 2e07f4c
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions ably/proto_presence_message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,55 @@ func Test_PresenceMap_RTP2(t *testing.T) {
})

t.Run("RTP2b1: check for newness by timestamp is synthesized", func(t *testing.T) {
in, _, _, channel, _, _, presenceMsgCh := setup(t)

initialMembers := channel.Presence.GetMembers()
assert.Empty(t, initialMembers)

presenceMsg1 := &ably.PresenceMessage{
Action: ably.PresenceActionPresent,
Message: ably.Message{
ID: "987:12:1",
Timestamp: 125,
ConnectionID: "987",
ClientID: "999",
},
}

presenceMsg2 := &ably.PresenceMessage{
Action: ably.PresenceActionPresent,
Message: ably.Message{
ID: "989:12:2",
Timestamp: 128,
ConnectionID: "987",
ClientID: "999",
},
}

msg := &ably.ProtocolMessage{
Action: ably.ActionPresence,
Channel: channel.Name,
Presence: []*ably.PresenceMessage{presenceMsg1},
}

in <- msg
ablytest.Soon.Recv(t, nil, presenceMsgCh, t.Fatalf)
presenceMembers := channel.Presence.GetMembers()

assert.Equal(t, 1, len(presenceMembers))
member := presenceMembers[presenceMsg1.ConnectionID+presenceMsg1.ClientID]
assert.Equal(t, ably.PresenceActionPresent, member.Action)
assert.Equal(t, "987:12:1", member.ID)

msg.Presence = []*ably.PresenceMessage{presenceMsg2}
in <- msg

ablytest.Soon.Recv(t, nil, presenceMsgCh, t.Fatalf)
presenceMembers = channel.Presence.GetMembers()
assert.Equal(t, 1, len(presenceMembers))
member = presenceMembers[presenceMsg1.ConnectionID+presenceMsg1.ClientID]
assert.Equal(t, ably.PresenceActionPresent, member.Action)
assert.Equal(t, "989:12:2", member.ID)
})

t.Run("RTP2b2: check for newness by timestamp is not synthesized", func(t *testing.T) {
Expand Down

0 comments on commit 2e07f4c

Please sign in to comment.