Skip to content

Commit

Permalink
Added has presence flag test for RTP1
Browse files Browse the repository at this point in the history
  • Loading branch information
sacOO7 committed Nov 12, 2023
1 parent 2c088ac commit 1d587d0
Showing 1 changed file with 66 additions and 9 deletions.
75 changes: 66 additions & 9 deletions ably/proto_presence_message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,24 +619,18 @@ func Test_Presence_server_initiated_sync_RTP18(t *testing.T) {
c *ably.Realtime,
channel *ably.RealtimeChannel,
stateChanges ably.ChannelStateChanges,
afterCalls chan ablytest.AfterCall,
presenceMsgCh chan *ably.PresenceMessage,
) {
in = make(chan *ably.ProtocolMessage, 1)
out = make(chan *ably.ProtocolMessage, 16)
presenceMsgCh = make(chan *ably.PresenceMessage, 16)

afterCalls = make(chan ablytest.AfterCall, 1)
now, after := ablytest.TimeFuncs(afterCalls)

c, _ = ably.NewRealtime(
ably.WithToken("fake:token"),
ably.WithAutoConnect(false),
ably.WithChannelRetryTimeout(channelRetryTimeout),
ably.WithRealtimeRequestTimeout(realtimeRequestTimeout),
ably.WithDial(MessagePipe(in, out)),
ably.WithNow(now),
ably.WithAfter(after),
)

in <- &ably.ProtocolMessage{
Expand Down Expand Up @@ -670,7 +664,7 @@ func Test_Presence_server_initiated_sync_RTP18(t *testing.T) {
}

t.Run("RTP18a: client determines a new sync started with <sync sequence id>:<cursor value>", func(t *testing.T) {
in, _, _, channel, _, _, presenceMsgCh := setup(t)
in, _, _, channel, _, presenceMsgCh := setup(t)

initialMembers := channel.Presence.GetMembers()
assert.Empty(t, initialMembers)
Expand Down Expand Up @@ -730,7 +724,7 @@ func Test_Presence_server_initiated_sync_RTP18(t *testing.T) {
})

t.Run("RTP18b: client determines sync ended with <sync sequence id>:", func(t *testing.T) {
in, _, _, channel, _, _, presenceMsgCh := setup(t)
in, _, _, channel, _, presenceMsgCh := setup(t)

initialMembers := channel.Presence.GetMembers()
assert.Empty(t, initialMembers)
Expand Down Expand Up @@ -797,7 +791,7 @@ func Test_Presence_server_initiated_sync_RTP18(t *testing.T) {
})

t.Run("RTP18: client determines sync started and ended with <sync sequence id>:", func(t *testing.T) {
in, _, _, channel, _, _, presenceMsgCh := setup(t)
in, _, _, channel, _, presenceMsgCh := setup(t)

initialMembers := channel.Presence.GetMembers()
assert.Empty(t, initialMembers)
Expand Down Expand Up @@ -857,6 +851,69 @@ func Test_Presence_server_initiated_sync_RTP18(t *testing.T) {
})
}

func Test_RTP1_attach_with_presence_flag(t *testing.T) {
const channelRetryTimeout = 123 * time.Millisecond
const realtimeRequestTimeout = 2 * time.Second

in := make(chan *ably.ProtocolMessage, 1)
out := make(chan *ably.ProtocolMessage, 16)

c, _ := ably.NewRealtime(
ably.WithToken("fake:token"),
ably.WithAutoConnect(false),
ably.WithChannelRetryTimeout(channelRetryTimeout),
ably.WithRealtimeRequestTimeout(realtimeRequestTimeout),
ably.WithDial(MessagePipe(in, out)),
)

in <- &ably.ProtocolMessage{
Action: ably.ActionConnected,
ConnectionID: "connection-id",
ConnectionDetails: &ably.ConnectionDetails{},
}

err := ablytest.Wait(ablytest.ConnWaiter(c, c.Connect, ably.ConnectionEventConnected), nil)
assert.NoError(t, err)

channel := c.Channels.Get("test")
stateChanges := make(ably.ChannelStateChanges, 10)
channel.OnAll(stateChanges.Receive)

assert.True(t, channel.Presence.SyncInitial())
assert.False(t, channel.Presence.SyncInProgress())
assert.False(t, channel.Presence.SyncComplete())

in <- &ably.ProtocolMessage{
Action: ably.ActionAttached,
Channel: channel.Name,
}

var change ably.ChannelStateChange

ablytest.Instantly.Recv(t, &change, stateChanges, t.Fatalf)
assert.Equal(t, ably.ChannelStateAttached, change.Current,
"expected %v; got %v (event: %+v)", ably.ChannelStateAttached, change.Current)

assert.False(t, channel.Presence.SyncInitial())
assert.False(t, channel.Presence.SyncInProgress())
assert.True(t, channel.Presence.SyncComplete())

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

in <- &ably.ProtocolMessage{
Action: ably.ActionAttached,
Flags: ably.FlagHasPresence,
Channel: channel.Name,
}

ablytest.Instantly.Recv(t, nil, stateChanges, t.Fatalf)

assert.False(t, channel.Presence.SyncInitial())
assert.True(t, channel.Presence.SyncInProgress())
assert.False(t, channel.Presence.SyncComplete())
}

func Test_internal_presencemap_RTP17(t *testing.T) {
t.Run("RTP17: presence object should have second presencemap containing only currentConnectionId", func(t *testing.T) {

Expand Down

0 comments on commit 1d587d0

Please sign in to comment.