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

RTN15g #250

Merged
merged 2 commits into from
Mar 2, 2016
Merged
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
113 changes: 65 additions & 48 deletions ablySpec/RealtimeClientConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1310,6 +1310,61 @@ class RealtimeClientConnection: QuickSpec {
// RTN15
context("connection failures once CONNECTED") {

// RTN15a
it("should not receive published messages until the connection reconnects successfully") {
let options = AblyTests.commonAppSetup()
options.autoConnect = false
options.disconnectedRetryTimeout = 1.0

let client1 = ARTRealtime(options: options)
defer { client1.close() }
let channel1 = client1.channels.get("test")

var states = [ARTRealtimeConnectionState]()
client1.connection.on() { stateChange in
states = states + [stateChange!.current]
}
client1.connect()

let client2 = ARTRealtime(options: options)
client2.connect()
defer { client2.close() }
let channel2 = client2.channels.get("test")

channel1.subscribe { message in
fail("Shouldn't receive the messsage")
}

expect(channel1.state).toEventually(equal(ARTRealtimeChannelState.Attached), timeout: testTimeout)

let firstConnection: (id: String, key: String) = (client1.connection.id!, client1.connection.key!)

// Connection state cannot be resumed
client1.simulateLostConnectionAndState()

channel2.publish(nil, data: "message") { errorInfo in
expect(errorInfo).to(beNil())
}

waitUntil(timeout: testTimeout) { done in
client1.connection.once(.Connecting) { _ in
expect(client1.resuming).to(beTrue())
done()
}
}

waitUntil(timeout: testTimeout) { done in
client1.connection.once(.Connected) { _ in
expect(client1.resuming).to(beFalse())
expect(client1.connection.id).toNot(equal(firstConnection.id))
expect(client1.connection.key).toNot(equal(firstConnection.key))
done()
}
}

expect(states).to(equal([.Connecting, .Connected, .Disconnected, .Connecting, .Connected]))
}

// RTN15d
it("should recover from disconnection and messages should be delivered once the connection is resumed") {
let options = AblyTests.commonAppSetup()
Expand Down Expand Up @@ -1391,64 +1446,26 @@ class RealtimeClientConnection: QuickSpec {

}

}

// RTN15
context("connection failures once CONNECTED") {

// RTN15a
it("should not receive published messages until the connection reconnects successfully") {
// RTN15g
it("when the connection resume has failed, all channels should be detached with an error reason") {
let options = AblyTests.commonAppSetup()
options.autoConnect = false
options.disconnectedRetryTimeout = 1.0

let client1 = ARTRealtime(options: options)
defer { client1.close() }
let channel1 = client1.channels.get("test")

var states = [ARTRealtimeConnectionState]()
client1.connection.on() { stateChange in
states = states + [stateChange!.current]
}
client1.connect()

let client2 = ARTRealtime(options: options)
client2.connect()
defer { client2.close() }
let channel2 = client2.channels.get("test")

channel1.subscribe { message in
fail("Shouldn't receive the messsage")
}

expect(channel1.state).toEventually(equal(ARTRealtimeChannelState.Attached), timeout: testTimeout)

let firstConnection: (id: String, key: String) = (client1.connection.id!, client1.connection.key!)

// Connection state cannot be resumed
client1.simulateLostConnectionAndState()

channel2.publish(nil, data: "message") { errorInfo in
expect(errorInfo).to(beNil())
}
let client = ARTRealtime(options: options)
defer { client.close() }
let channel = client.channels.get("test")

waitUntil(timeout: testTimeout) { done in
client1.connection.once(.Connecting) { _ in
expect(client1.resuming).to(beTrue())
channel.attach() { errorInfo in
expect(errorInfo).to(beNil())
done()
}
}

waitUntil(timeout: testTimeout) { done in
client1.connection.once(.Connected) { _ in
expect(client1.resuming).to(beFalse())
expect(client1.connection.id).toNot(equal(firstConnection.id))
expect(client1.connection.key).toNot(equal(firstConnection.key))
done()
}
}
client.simulateLostConnectionAndState()

expect(states).to(equal([.Connecting, .Connected, .Disconnected, .Connecting, .Connected]))
expect(channel.state).toEventually(equal(ARTRealtimeChannelState.Detached), timeout: testTimeout)
expect(channel.errorReason!.message).to(contain("Unable to recover connection"))
}

}
Expand Down