Skip to content

Commit

Permalink
Merge pull request #154 from ably/RTN7c
Browse files Browse the repository at this point in the history
RTN7c
  • Loading branch information
ricardopereira committed Jan 29, 2016
2 parents e172cd9 + 4a74600 commit 232f398
Showing 1 changed file with 91 additions and 0 deletions.
91 changes: 91 additions & 0 deletions ablySpec/RealtimeClient.connection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,97 @@ class RealtimeClientConnection: QuickSpec {
expect(nacks[0].msgSerial).to(equal(6))
expect(nacks[0].count).to(equal(1))
}
}

// RTN7c
pending("should trigger the failure callback for the remaining pending messages if") {

it("connection is closed") {
client.connect()
defer {
client.dispose()
client.close()
}

let channel = client.channel("channel")
let transport = client.transport as! TestProxyTransport
transport.actionsIgnored += [.Ack, .Nack]

waitUntil(timeout: testTimeout) { done in
channel.subscribeToStateChanges { state, status in
if state == .Attached {
channel.publish("message", cb: { status in
expect(status.state).to(equal(ARTState.Error))
done()
})
// Wait until the message is pushed to Ably first
delay(1.0) {
transport.simulateIncomingNormalClose()
}
}
}
channel.attach()
}
}

it("connection state enters FAILED") {
client.connect()
defer {
client.dispose()
client.close()
}

let channel = client.channel("channel")
let transport = client.transport as! TestProxyTransport
transport.actionsIgnored += [.Ack, .Nack]

waitUntil(timeout: testTimeout) { done in
channel.subscribeToStateChanges { state, status in
if state == .Attached {
channel.publish("message", cb: { status in
expect(status.state).to(equal(ARTState.Error))
done()
})
// Wait until the message is pushed to Ably first
delay(1.0) {
transport.simulateIncomingError()
}
}
}
channel.attach()
}
}

it("lost connection state") {
let options = AblyTests.commonAppSetup()
options.autoConnect = false
let client = ARTRealtimeExtended(options: options)
client.setTransportClass(TestProxyTransport.self)
client.connect()
defer { client.close() }

let channel = client.channel("channel")

let transport = client.transport as! TestProxyTransport
transport.actionsIgnored += [.Ack, .Nack]

waitUntil(timeout: testTimeout + options.disconnectedRetryTimeout) { done in
channel.subscribeToStateChanges { state, status in
if state == .Attached {
channel.publish("message", cb: { status in
expect(status.state).to(equal(ARTState.Error))
done()
})
// Wait until the message is pushed to Ably first
delay(1.0) {
client.simulateLostConnection()
expect(client.connection().state).toEventually(equal(ARTRealtimeConnectionState.Connecting), timeout: options.disconnectedRetryTimeout)
}
}
}
channel.attach()
}
}

}

Expand Down

0 comments on commit 232f398

Please sign in to comment.