Skip to content

Commit

Permalink
Merge pull request #100 from ably/RTN8
Browse files Browse the repository at this point in the history
RTN8
  • Loading branch information
mattheworiordan committed Dec 2, 2015
2 parents 1d2fa42 + b193b60 commit 246dda7
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ably-ios/ARTConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@class ARTRealtime;
@class ARTEventEmitter;

ART_ASSUME_NONNULL_BEGIN

@interface ARTConnection: NSObject

@property (readonly, getter=getId) NSString *id;
Expand All @@ -28,3 +30,5 @@
- (void)ping:(ARTRealtimePingCb)cb;

@end

ART_ASSUME_NONNULL_END
46 changes: 46 additions & 0 deletions ablySpec/RealtimeClient.connection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,52 @@ class RealtimeClientConnection: QuickSpec {
expect(errorInfo).toNot(beNil())
}
}

// RTN8
context("connection#id") {

// RTN8a
it("should be null until connected") {
let options = AblyTests.commonAppSetup()
let client = ARTRealtime(options: options)
let connection = client.connection()

expect(connection.id).to(beEmpty())

waitUntil(timeout: testTimeout) { done in
connection.eventEmitter.on { state, errorInfo in
if state == .Connected && errorInfo == nil {
expect(connection.id).toNot(beEmpty())
done()
}
else if state == .Connecting {
expect(connection.id).to(beEmpty())
}
}
}
}

// RTN8b
it("should have unique IDs") {
let options = AblyTests.commonAppSetup()
var disposable = [ARTRealtime]()
var ids = [String]()
let max = 25

for _ in 1...max {
disposable.append(ARTRealtime(options: options))
let currentConnection = disposable.last?.connection()
currentConnection?.eventEmitter.on { state, errorInfo in
if state == .Connected {
expect(ids).toNot(contain(currentConnection?.id))
ids.append(currentConnection?.id ?? "")
}
}
}

expect(ids).toEventually(haveCount(max))
}
}
}
}
}

0 comments on commit 246dda7

Please sign in to comment.