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 RTL1 #286

Merged
merged 2 commits into from
Mar 9, 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
23 changes: 10 additions & 13 deletions Spec/RealtimeClientChannel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ class RealtimeClientChannel: QuickSpec {
// RTL1
it("should process all incoming messages and presence messages as soon as a Channel becomes attached") {
let options = AblyTests.commonAppSetup()
let client1 = ARTRealtime(options: options)
let client1 = AblyTests.newRealtime(options)
defer { client1.close() }

let channel1 = client1.channels.get("room")
channel1.attach()

waitUntil(timeout: testTimeout) { done in
channel1.presence.enterClient("Client 1", data: nil) { errorInfo in
Expand All @@ -33,10 +31,14 @@ class RealtimeClientChannel: QuickSpec {
}

options.clientId = "Client 2"
let client2 = ARTRealtime(options: options)
let client2 = AblyTests.newRealtime(options)
defer { client2.close() }

let channel2 = client2.channels.get(channel1.name)

channel2.subscribe("Client 1") { message in
expect(message.data as? String).to(equal("message"))
}

channel2.attach()

expect(channel2.presence.syncComplete).to(beFalse())
Expand All @@ -49,12 +51,7 @@ class RealtimeClientChannel: QuickSpec {
expect(channel2.presence.syncComplete).toEventually(beTrue(), timeout: testTimeout)

expect(channel1.presenceMap.members).to(haveCount(1))
expect(channel2.presenceMap.members).to(haveCount(1))

// Check if receives incoming messages
channel2.subscribe("Client 1") { message in
expect(message.data as? String).to(equal("message"))
}
expect(channel2.presenceMap.members).toEventually(haveCount(1), timeout: testTimeout)

waitUntil(timeout: testTimeout) { done in
channel1.publish("message", data: nil) { errorInfo in
Expand All @@ -70,11 +67,11 @@ class RealtimeClientChannel: QuickSpec {
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think line 49 above (can't comment on it) also needs a toEventually, or a wait until for the channel2.attach() callback.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, the subscribe on line 52 should be moved above the channel2.attach(), to make sure it happens before it is attached.

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 60b1ef1. Thanks.

}

expect(channel1.presenceMap.members).to(haveCount(2))
expect(channel1.presenceMap.members).toEventually(haveCount(2), timeout: testTimeout)
expect(channel1.presenceMap.members).to(allKeysPass({ $0.hasPrefix("Client") }))
expect(channel1.presenceMap.members).to(allValuesPass({ $0.action == .Enter }))

expect(channel2.presenceMap.members).to(haveCount(2))
expect(channel2.presenceMap.members).toEventually(haveCount(2), timeout: testTimeout)
expect(channel2.presenceMap.members).to(allKeysPass({ $0.hasPrefix("Client") }))
expect(channel2.presenceMap.members["Client 1"]!.action).to(equal(ARTPresenceAction.Present))
expect(channel2.presenceMap.members["Client 2"]!.action).to(equal(ARTPresenceAction.Enter))
Expand Down
8 changes: 8 additions & 0 deletions Spec/TestUtilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@ class AblyTests {
return protocolMessage
}

class func newRealtime(options: ARTClientOptions) -> ARTRealtime {
options.autoConnect = false
let realtime = ARTRealtime(options: options)
realtime.setTransportClass(TestProxyTransport.self)
realtime.connect()
return realtime
}

struct CryptoTestItem {

struct TestMessage {
Expand Down