Skip to content

Commit

Permalink
add checks for IsSynthesized per comments in PR ably#310
Browse files Browse the repository at this point in the history
  • Loading branch information
withakay committed Mar 21, 2019
1 parent 2885778 commit 34fe620
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/IO.Ably.Shared/Realtime/Presence.cs
Expand Up @@ -406,7 +406,7 @@ internal void OnPresence(PresenceMessage[] messages, string syncChannelSerial)
break;
case PresenceAction.Leave:
broadcast &= Map.Remove(message);
if (updateInternalPresence)
if (updateInternalPresence && !message.IsSynthesized())
{
InternalMap.Remove(message);
}
Expand Down
32 changes: 31 additions & 1 deletion src/IO.Ably.Tests.Shared/Realtime/PresenceSandboxSpecs.cs
Expand Up @@ -382,7 +382,7 @@ public async Task Presence_ShouldHaveInternalMapForCurrentConnectionId(Protocol
channelB.Presence.Map.Members.Should().HaveCount(2);
channelB.Presence.InternalMap.Members.Should().HaveCount(1);

// LEAVE
// LEAVE with synthesized message
msgA = null;
msgB = null;
await WaitForMultiple(2, partialDone =>
Expand Down Expand Up @@ -418,6 +418,36 @@ public async Task Presence_ShouldHaveInternalMapForCurrentConnectionId(Protocol
channelB.Presence.Map.Members.Should().HaveCount(1);
channelB.Presence.InternalMap.Members.Should().HaveCount(0);

msgA = null;
msgB = null;
await WaitForMultiple(2, partialDone =>
{
channelA.Presence.Subscribe(msg =>
{
msgA = msg;
channelA.Presence.Unsubscribe();
partialDone();
});
var synthesizedMsg = new PresenceMessage(PresenceAction.Leave, clientB.ClientId) { ConnectionId = null };
synthesizedMsg.IsSynthesized().Should().BeTrue();
channelB.Presence.OnPresence(new[] { synthesizedMsg }, null);
partialDone();
});

msgA.Should().NotBeNull();
msgA.Action.Should().Be(PresenceAction.Leave);
msgA.ConnectionId.Should().NotBe(clientA.Connection.Id);
msgA.Data.ToString().Should().Be("chB-leave");
channelA.Presence.Map.Members.Should().HaveCount(1);
channelA.Presence.InternalMap.Members.Should().HaveCount(1);

msgB.Should().BeNull();
channelB.Presence.Map.Members.Should().HaveCount(1);

// message was synthesized so should not have been removed (RTP17b)
channelB.Presence.InternalMap.Members.Should().HaveCount(1);

// clean up
clientA.Close();
clientB.Close();
Expand Down

0 comments on commit 34fe620

Please sign in to comment.