Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pending tests. #371

Merged
merged 5 commits into from
Apr 5, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix RTP6c.
  • Loading branch information
tcard committed Apr 5, 2016
commit 11021b81ddcdaa65dbbf71edb2497989e1678d94
10 changes: 5 additions & 5 deletions Source/ARTRealtimeChannel.m
Original file line number Diff line number Diff line change
Expand Up @@ -283,17 +283,17 @@ - (void)emit:(ARTChannelEvent)event with:(ARTErrorInfo *)data {
- (void)transition:(ARTRealtimeChannelState)state status:(ARTStatus *)status {
[self cancelAttachTimer];
[self cancelDetachTimer];
if (state == ARTRealtimeChannelFailed) {
[_attachedEventEmitter emit:[NSNull null] with:status.errorInfo];
[_detachedEventEmitter emit:[NSNull null] with:status.errorInfo];
}
if (self.state == state) {
return;
}

self.state = state;
_errorReason = status.errorInfo;

if (state == ARTRealtimeChannelFailed) {
[_attachedEventEmitter emit:[NSNull null] with:status.errorInfo];
[_detachedEventEmitter emit:[NSNull null] with:status.errorInfo];
}

[self emit:(ARTChannelEvent)state with:status.errorInfo];
}

Expand Down
7 changes: 5 additions & 2 deletions Source/ARTRealtimePresence.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ ART_ASSUME_NONNULL_BEGIN
- (void)leaveClient:(NSString *)clientId data:(id __art_nullable)data;
- (void)leaveClient:(NSString *)clientId data:(id __art_nullable)data callback:(art_nullable void (^)(ARTErrorInfo *__art_nullable))cb;

- (__GENERIC(ARTEventListener, ARTPresenceMessage *) *)subscribe:(void (^)(ARTPresenceMessage *message))callback;
- (__GENERIC(ARTEventListener, ARTPresenceMessage *) *)subscribe:(ARTPresenceAction)action callback:(void (^)(ARTPresenceMessage *message))cb;
- (__GENERIC(ARTEventListener, ARTPresenceMessage *) *__art_nullable)subscribe:(void (^)(ARTPresenceMessage *message))callback;
- (__GENERIC(ARTEventListener, ARTPresenceMessage *) *__art_nullable)subscribeWithAttachCallback:(art_nullable void (^)(ARTErrorInfo *__art_nullable))onAttach callback:(void (^)(ARTPresenceMessage *message))cb;
- (__GENERIC(ARTEventListener, ARTPresenceMessage *) *__art_nullable)subscribe:(ARTPresenceAction)action callback:(void (^)(ARTPresenceMessage *message))cb;
- (__GENERIC(ARTEventListener, ARTPresenceMessage *) *__art_nullable)subscribe:(ARTPresenceAction)action onAttach:(art_nullable void (^)(ARTErrorInfo *__art_nullable))onAttach callback:(void (^)(ARTPresenceMessage *message))cb;

- (void)unsubscribe;
- (void)unsubscribe:(__GENERIC(ARTEventListener, ARTPresenceMessage *) *)listener;
- (void)unsubscribe:(ARTPresenceAction)action listener:(__GENERIC(ARTEventListener, ARTPresenceMessage *) *)listener;
Expand Down
22 changes: 19 additions & 3 deletions Source/ARTRealtimePresence.m
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,28 @@ - (BOOL)getSyncComplete {
}

- (ARTEventListener<ARTPresenceMessage *> *)subscribe:(void (^)(ARTPresenceMessage * _Nonnull))callback {
[self.channel attach];
return [self.channel.presenceEventEmitter on:callback];
return [self subscribeWithAttachCallback:nil callback:callback];
}

- (ARTEventListener<ARTPresenceMessage *> *)subscribeWithAttachCallback:(void (^)(ARTErrorInfo * _Nullable))onAttach callback:(void (^)(ARTPresenceMessage * _Nonnull))cb {
if (self.channel.state == ARTRealtimeChannelFailed) {
if (onAttach) onAttach([ARTErrorInfo createWithCode:0 message:@"attempted to subscribe while channel is in Failed state."]);
return nil;
}
[self.channel attach:onAttach];
return [self.channel.presenceEventEmitter on:cb];
}

- (ARTEventListener<ARTPresenceMessage *> *)subscribe:(ARTPresenceAction)action callback:(void (^)(ARTPresenceMessage * _Nonnull))cb {
[self.channel attach];
return [self subscribe:action onAttach:nil callback:cb];
}

- (ARTEventListener<ARTPresenceMessage *> *)subscribe:(ARTPresenceAction)action onAttach:(void (^)(ARTErrorInfo * _Nullable))onAttach callback:(void (^)(ARTPresenceMessage * _Nonnull))cb {
if (self.channel.state == ARTRealtimeChannelFailed) {
if (onAttach) onAttach([ARTErrorInfo createWithCode:0 message:@"attempted to subscribe while channel is in Failed state."]);
return nil;
}
[self.channel attach:onAttach];
return [self.channel.presenceEventEmitter on:[NSNumber numberWithUnsignedInteger:action] call:cb];
}

Expand Down
37 changes: 22 additions & 15 deletions Spec/RealtimeClientPresence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ class RealtimeClientPresence: QuickSpec {
defer { client.close() }
let channel = client.channels.get("test")

let listener = channel.presence.subscribe { _ in }
let listener = channel.presence.subscribe { _ in }!
expect(channel.presenceEventEmitter.anyListeners).to(haveCount(1))
channel.presence.unsubscribe(listener)
expect(channel.presenceEventEmitter.anyListeners).to(haveCount(0))
Expand Down Expand Up @@ -318,7 +318,7 @@ class RealtimeClientPresence: QuickSpec {
defer { client.close() }
let channel = client.channels.get("test")

let listener = channel.presence.subscribe(.Present) { _ in }
let listener = channel.presence.subscribe(.Present) { _ in }!
expect(channel.presenceEventEmitter.listeners).to(haveCount(1))
channel.presence.unsubscribe(.Present, listener: listener)
expect(channel.presenceEventEmitter.listeners).to(haveCount(0))
Expand Down Expand Up @@ -348,37 +348,44 @@ class RealtimeClientPresence: QuickSpec {
}

// RTP6c
pending("should result in an error if the channel is in the FAILED state") {
it("should result in an error if the channel is in the FAILED state") {
let client = ARTRealtime(options: AblyTests.commonAppSetup())
defer { client.close() }
let channel = client.channels.get("test")

let channel = client.channels.get("test")
channel.onError(AblyTests.newErrorProtocolMessage())
expect(channel.state).to(equal(ARTRealtimeChannelState.Failed))

waitUntil(timeout: testTimeout) { done in
channel.presence.subscribe { member in
// TODO: missing error
done()
}
channel.presence.subscribeWithAttachCallback({ errorInfo in
expect(errorInfo).toNot(beNil())

channel.presence.subscribe(.Enter, onAttach: { errorInfo in
expect(errorInfo).toNot(beNil())
done()
}) { _ in }
}) { _ in }
}
expect(channel.presenceEventEmitter.anyListeners).to(haveCount(0))
}

// RTP6c
pending("should result in an error if the channel moves to the FAILED state") {
it("should result in an error if the channel moves to the FAILED state") {
let client = ARTRealtime(options: AblyTests.commonAppSetup())
defer { client.close() }
let channel = client.channels.get("test")

waitUntil(timeout: testTimeout) { done in
let error = AblyTests.newErrorProtocolMessage()
channel.presence.subscribe { _ in
// TODO: missing error
done()
}
channel.presence.subscribeWithAttachCallback({ errorInfo in
expect(errorInfo).toNot(beNil())

channel.presence.subscribe(.Enter, onAttach: { errorInfo in
expect(errorInfo).toNot(beNil())
done()
}) { _ in }
}) {_ in }
channel.onError(error)
}
expect(channel.presenceEventEmitter.anyListeners).to(haveCount(0))
}

}
Expand Down