Skip to content

Commit

Permalink
RTL14
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardopereira committed Nov 30, 2016
1 parent 5728e01 commit c90dbec
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions Spec/RealtimeClientChannel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2325,6 +2325,48 @@ class RealtimeClientChannel: QuickSpec {
expect(channel.state).to(equal(ARTRealtimeChannelState.Attached))
}

// RTL14
it("If an ERROR ProtocolMessage is received for this channel then the channel should immediately transition to the FAILED state, the errorReason should be set and an error should be emitted on the channel") {
let client = ARTRealtime(options: AblyTests.commonAppSetup())
defer { client.dispose(); client.close() }
let channel = client.channels.get("foo")
waitUntil(timeout: testTimeout) { done in
channel.attach() { error in
expect(error).to(beNil())
done()
}
}

waitUntil(timeout: testTimeout) { done in
let errorProtocolMessage = AblyTests.newErrorProtocolMessage()
errorProtocolMessage.action = .Error
errorProtocolMessage.channel = "foo"

let partialDone = AblyTests.splitDone(2, done: done)

channel.once(.Error) { stateChange in
guard let error = stateChange?.reason else {
fail("Reason error is nil"); partialDone(); return
}
expect(error).to(beIdenticalTo(errorProtocolMessage.error))
expect(channel.errorReason).to(beIdenticalTo(error))
partialDone()
}

channel.once(.Failed) { stateChange in
guard let error = stateChange?.reason else {
fail("Reason error is nil"); partialDone(); return
}
expect(error).to(beIdenticalTo(errorProtocolMessage.error))
expect(channel.errorReason).to(beIdenticalTo(error))
partialDone()
}

client.transport.receive(errorProtocolMessage)
}

expect(channel.state).to(equal(ARTRealtimeChannelState.Failed))
}
}

context("crypto") {
Expand Down

0 comments on commit c90dbec

Please sign in to comment.