From 2e07f4c6e7b68d3911ec90d597ef90e11e9c2b82 Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Fri, 10 Nov 2023 01:02:21 +0530 Subject: [PATCH] Added test when message is synthesized, check newness by timestamp --- ably/proto_presence_message_test.go | 48 +++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/ably/proto_presence_message_test.go b/ably/proto_presence_message_test.go index fd3a8156..91405a88 100644 --- a/ably/proto_presence_message_test.go +++ b/ably/proto_presence_message_test.go @@ -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) {