Skip to content

Commit

Permalink
Do not request a Sync when an ATTACHED is received (see #349)
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardopereira committed Dec 20, 2017
1 parent 7235bdd commit 9e74493
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
3 changes: 2 additions & 1 deletion Source/ARTRealtime.m
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,8 @@ - (void)onConnected:(ARTProtocolMessage *)message {

for (ARTRealtimeChannel *channel in self.channels.nosyncIterable) {
if (channel.presenceMap.syncInProgress) {
[channel requestContinueSync];
// FIXME or not, regarding https://github.com/ably/docs/issues/349
//[channel requestContinueSync];
}
}
}
Expand Down
12 changes: 10 additions & 2 deletions Source/ARTRealtimeChannel.m
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,17 @@ - (void)internalPostMessages:(id)data callback:(void (^)(ARTErrorInfo *__art_nul

- (void)requestContinueSync {
ART_TRY_OR_MOVE_TO_FAILED_START(_realtime) {
[self.logger debug:__FILE__ line:__LINE__ message:@"R:%p C:%p ARTRealtime requesting to continue sync operation after reconnect", _realtime, self];
[self.logger debug:__FILE__ line:__LINE__ message:@"R:%p C:%p (%@) ARTRealtime requesting to continue sync operation after reconnect using msgSerial %lld and channelSerial %@", _realtime, self, self.name, self.presenceMap.syncMsgSerial, self.presenceMap.syncChannelSerial];

ARTProtocolMessage * msg = [[ARTProtocolMessage alloc] init];
msg.action = ARTProtocolMessageSync;
msg.msgSerial = [NSNumber numberWithLongLong:self.presenceMap.syncMsgSerial];
msg.channelSerial = self.presenceMap.syncChannelSerial;
msg.channel = self.name;

[self.realtime send:msg callback:^(ARTStatus *status) {}];
[self.realtime send:msg callback:^(ARTStatus *status) {
[self.logger debug:__FILE__ line:__LINE__ message:@"R:%p C:%p (%@) ARTRealtime continue sync status is %@", _realtime, self, self.name, status];
}];
} ART_TRY_OR_MOVE_TO_FAILED_END
}

Expand Down Expand Up @@ -586,6 +588,10 @@ - (void)setAttached:(ARTProtocolMessage *)message {
break;
}

if (message.resumed) {
[self.logger debug:__FILE__ line:__LINE__ message:@"R:%p C:%p channel has resumed", _realtime, self];
}

self.attachSerial = message.channelSerial;

if (message.hasPresence) {
Expand All @@ -597,6 +603,7 @@ - (void)setAttached:(ARTProtocolMessage *)message {
// When an ATTACHED message is received without a HAS_PRESENCE flag and PresenceMap has existing members
[self.presenceMap startSync];
[self.presenceMap endSync];
[self.logger debug:__FILE__ line:__LINE__ message:@"R:%p C:%p PresenceMap has been reset", _realtime, self];
}
}

Expand Down Expand Up @@ -753,6 +760,7 @@ - (void)onSync:(ARTProtocolMessage *)message {

if (!self.presenceMap.syncInProgress) {
[self.presenceMap startSync];
[self.logger debug:__FILE__ line:__LINE__ message:@"R:%p C:%p PresenceMap Sync started", _realtime, self];
}

for (int i=0; i<[message.presence count]; i++) {
Expand Down
12 changes: 7 additions & 5 deletions Spec/RealtimeClientPresence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class RealtimeClientPresence: QuickSpec {
lastSyncSerial = protocolMessage.channelSerial
client.onDisconnected()
partialDone()
transport.afterProcessingReceivedMessage = nil
}
}
channel.attach() { _ in
Expand All @@ -133,11 +134,12 @@ class RealtimeClientPresence: QuickSpec {
fail("TestProxyTransport is not set"); return
}

let syncSentProtocolMessages = transport.protocolMessagesSent.filter({ $0.action == .sync })
guard let syncSentMessage = syncSentProtocolMessages.last, syncSentProtocolMessages.count == 1 else {
fail("Should send one SYNC protocol message"); return
}
expect(syncSentMessage.channelSerial).to(equal(lastSyncSerial))
// FIXME or not, regarding https://github.com/ably/docs/issues/349
//let syncSentProtocolMessages = transport.protocolMessagesSent.filter({ $0.action == .sync })
//guard let syncSentMessage = syncSentProtocolMessages.last, syncSentProtocolMessages.count == 1 else {
// fail("Should send one SYNC protocol message"); return
//}
//expect(syncSentMessage.channelSerial).to(equal(lastSyncSerial))

expect(transport.protocolMessagesReceived.filter{ $0.action == .sync }).toEventually(haveCount(2), timeout: testTimeout)

Expand Down

0 comments on commit 9e74493

Please sign in to comment.