Skip to content

Commit

Permalink
TR4i (#562)
Browse files Browse the repository at this point in the history
* ARTProtocolMessageFlag enum: use NS_OPTIONS to define a bitmask

* TR4i

* Fix: should indicate that the channel has been resumed or not (RESUMED flag)
  • Loading branch information
ricardopereira authored Jan 9, 2017
1 parent 4668815 commit 992bc58
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 8 deletions.
11 changes: 9 additions & 2 deletions Source/ARTProtocolMessage+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
// Copyright (c) 2014 Ably. All rights reserved.
//

NSString *__art_nonnull ARTProtocolMessageActionToStr(ARTProtocolMessageAction action);
/// ARTProtocolMessageFlag bitmask
typedef NS_OPTIONS(NSUInteger, ARTProtocolMessageFlag) {
ARTProtocolMessageFlagHasPresence = (1UL << 0), //1
ARTProtocolMessageFlagHasBacklog = (1UL << 1), //2
ARTProtocolMessageFlagResumed = (1UL << 2) //4
};

ART_ASSUME_NONNULL_BEGIN

Expand All @@ -15,7 +20,9 @@ ART_ASSUME_NONNULL_BEGIN
@property (readwrite, assign, nonatomic) BOOL hasConnectionSerial;
@property (readonly, assign, nonatomic) BOOL ackRequired;

- (BOOL)isSyncEnabled;
@property (readonly, assign, nonatomic) BOOL hasPresence;
@property (readonly, assign, nonatomic) BOOL hasBacklog;
@property (readonly, assign, nonatomic) BOOL resumed;

- (BOOL)mergeFrom:(ARTProtocolMessage *)msg;

Expand Down
12 changes: 10 additions & 2 deletions Source/ARTProtocolMessage.m
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,16 @@ - (BOOL)ackRequired {
return self.action == ARTProtocolMessageMessage || self.action == ARTProtocolMessagePresence;
}

- (BOOL)isSyncEnabled {
return self.flags & 0x1;
- (BOOL)hasPresence {
return self.flags & ARTProtocolMessageFlagHasPresence;
}

- (BOOL)hasBacklog {
return self.flags & ARTProtocolMessageFlagHasBacklog;
}

- (BOOL)resumed {
return self.flags & ARTProtocolMessageFlagResumed;
}

- (ARTConnectionDetails *)getConnectionDetails {
Expand Down
4 changes: 2 additions & 2 deletions Source/ARTRealtimeChannel.m
Original file line number Diff line number Diff line change
Expand Up @@ -419,12 +419,12 @@ - (void)setAttached:(ARTProtocolMessage *)message {
if (message.error != nil) {
_errorReason = message.error;
}
ARTChannelStateChange *stateChange = [[ARTChannelStateChange alloc] initWithCurrent:self.state previous:self.state event:ARTChannelEventUpdate reason:message.error];
ARTChannelStateChange *stateChange = [[ARTChannelStateChange alloc] initWithCurrent:self.state previous:self.state event:ARTChannelEventUpdate reason:message.error resumed:message.resumed];
[self emit:stateChange.event with:stateChange];
return;
}

if ([message isSyncEnabled]) {
if (message.hasPresence) {
[self.presenceMap startSync];
[self.logger debug:__FILE__ line:__LINE__ message:@"R:%p C:%p PresenceMap Sync started", _realtime, self];
}
Expand Down
39 changes: 39 additions & 0 deletions Spec/RealtimeClientChannel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,45 @@ class RealtimeClientChannel: QuickSpec {
}
}

// RTL2f, TR4i
it("bit flag RESUMED was included") {
let options = AblyTests.commonAppSetup()
let client = ARTRealtime(options: options)
defer { client.dispose(); client.close() }
let channel = client.channels.get("test")

waitUntil(timeout: testTimeout) { done in
channel.once(.Attached) { stateChange in
guard let stateChange = stateChange else {
fail("ChannelStageChange is nil"); done(); return
}
expect(stateChange.resumed).to(beFalse())
expect(stateChange.reason).to(beNil())
done()
}
channel.attach()
}

let attachedMessage = ARTProtocolMessage()
attachedMessage.action = .Attached
attachedMessage.channel = "test"
attachedMessage.flags = 4 //Resumed

waitUntil(timeout: testTimeout) { done in
channel.once(.Update) { stateChange in
guard let stateChange = stateChange else {
fail("ChannelStageChange is nil"); done(); return
}
expect(stateChange.resumed).to(beTrue())
expect(stateChange.reason).to(beNil())
expect(stateChange.current).to(equal(ARTRealtimeChannelState.Attached))
expect(stateChange.previous).to(equal(ARTRealtimeChannelState.Attached))
done()
}
client.transport?.receive(attachedMessage)
}
}

}

// RTL3
Expand Down
4 changes: 2 additions & 2 deletions Spec/RealtimeClientPresence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class RealtimeClientPresence: QuickSpec {
let attached = transport.protocolMessagesReceived.filter({ $0.action == .Attached })[0]

expect(attached.flags & 0x1).to(equal(0))
expect(attached.isSyncEnabled()).to(beFalse())
expect(attached.hasPresence).to(beFalse())
expect(channel.presence.syncComplete).to(beFalse())
expect(channel.presenceMap.syncComplete).to(beFalse())
}
Expand Down Expand Up @@ -71,7 +71,7 @@ class RealtimeClientPresence: QuickSpec {

// There are members present on the channel
expect(attached.flags & 0x1).to(equal(1))
expect(attached.isSyncEnabled()).to(beTrue())
expect(attached.hasPresence).to(beTrue())

expect(channel.presence.syncComplete).toEventually(beTrue(), timeout: testTimeout)

Expand Down

0 comments on commit 992bc58

Please sign in to comment.