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

RTP10b #337

Merged
merged 3 commits into from
Apr 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
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
66 changes: 65 additions & 1 deletion Spec/RealtimeClientPresence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ class RealtimeClientPresence: QuickSpec {
defer { client.close() }
let channel = client.channels.get("test")

channel.attach()
channel.attach()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Odd spacing here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 3200787.

channel.detach()

waitUntil(timeout: testTimeout) { done in
Expand Down Expand Up @@ -927,6 +927,70 @@ class RealtimeClientPresence: QuickSpec {
}
}
}
}

// RTP10
context("leave") {

// RTP10b
it("optionally a callback can be provided that is called for success") {
let options = AblyTests.commonAppSetup()
options.clientId = "john"
let client = ARTRealtime(options: options)
defer { client.close() }
let channel = client.channels.get("test")

waitUntil(timeout: testTimeout) { done in
channel.presence.enter("online") { error in
expect(error).to(beNil())
done()
}
}

waitUntil(timeout: testTimeout) { done in
channel.presence.leave("offline") { error in
expect(error).to(beNil())
done()
}
}
}

// RTP10b
it("optionally a callback can be provided that is called for failure") {
let options = AblyTests.commonAppSetup()
options.clientId = "john"
let client = AblyTests.newRealtime(options)
defer { client.close() }
let channel = client.channels.get("test")

waitUntil(timeout: testTimeout) { done in
channel.presence.enter("online") { error in
expect(error).to(beNil())
done()
}
}

waitUntil(timeout: testTimeout) { done in
let sentError = ARTErrorInfo.createWithCode(0, message: "test error")
let transport = client.transport as! TestProxyTransport
transport.replaceAcksWithNacks(sentError) { doneReplacing in
channel.presence.leave("offline") { error in
expect(error).to(beIdenticalTo(sentError))
doneReplacing()
done()
}
}
}
}

it("should raise an exception if client is not present") {
let options = AblyTests.commonAppSetup()
options.clientId = "john"
let client = ARTRealtime(options: options)
defer { client.close() }
let channel = client.channels.get("test")
expect(channel.presence.leave("offline")).to(raiseException())
}

}

Expand Down
12 changes: 11 additions & 1 deletion Spec/TestUtilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ class TestProxyTransport: ARTWebSocketTransport {

private(set) var rawDataSent = [NSData]()
private(set) var rawDataReceived = [NSData]()
private var replacingAcksWithNacks: ARTErrorInfo?

var beforeProcessingSentMessage: Optional<(ARTProtocolMessage)->()> = nil
var beforeProcessingReceivedMessage: Optional<(ARTProtocolMessage)->()> = nil
Expand Down Expand Up @@ -522,6 +523,12 @@ class TestProxyTransport: ARTWebSocketTransport {
}

override func receive(msg: ARTProtocolMessage) {
if msg.action == .Ack {
if let error = replacingAcksWithNacks {
msg.action = .Nack
msg.error = error
}
}
protocolMessagesReceived.append(msg)
if actionsIgnored.contains(msg.action) {
return
Expand All @@ -540,6 +547,10 @@ class TestProxyTransport: ARTWebSocketTransport {
super.receiveWithData(data)
}

func replaceAcksWithNacks(error: ARTErrorInfo, block: (() -> ()) -> ()) {
replacingAcksWithNacks = error
block({ self.replacingAcksWithNacks = nil })
}
}


Expand Down Expand Up @@ -687,7 +698,6 @@ extension ARTWebSocketTransport {
let webSocketDelegate = self as! WebSocketDelegate
webSocketDelegate.webSocketError(error)
}

}


Expand Down