Skip to content

Commit

Permalink
Fix test for RTN15h2: "will transition to the DISCONNECTED"
Browse files Browse the repository at this point in the history
... not FAILED.

Also, make it faster.
  • Loading branch information
tcard committed Feb 16, 2020
1 parent 7a1f3bd commit 97d5c13
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions Spec/RealtimeClientConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3013,11 +3013,11 @@ class RealtimeClientConnection: QuickSpec {
it("should transition to disconnected when the token renewal fails and the error should be emitted") {
let options = AblyTests.commonAppSetup()
options.autoConnect = false
let tokenTtl = 5.0
let tokenTtl = 3.0
let tokenDetails = getTestTokenDetails(key: options.key, capability: nil, ttl: tokenTtl)!
options.token = tokenDetails.token
options.authCallback = { tokenParams, callback in
delay(1.0) {
delay(0.1) {
callback(tokenDetails, nil) // Return the same expired token again.
}
}
Expand All @@ -3029,30 +3029,27 @@ class RealtimeClientConnection: QuickSpec {
client.close()
}

client.connect()
expect(client.connection.state).toEventually(equal(ARTRealtimeConnectionState.connected), timeout: testTimeout)

waitUntil(timeout: testTimeout) { done in
// Wait for token to expire
client.connection.once(.disconnected) { stateChange in
expect(stateChange?.previous).to(equal(ARTRealtimeConnectionState.connected))
guard let error = stateChange?.reason else {
fail("Error is nil"); done(); return
}
expect(error.code) == 40142
done()
}
}

waitUntil(timeout: testTimeout) { done in
// Renewal will lead to a failed connection
client.connection.once(.failed) { stateChange in
guard let error = stateChange?.reason else {
fail("Error is nil"); done(); return

// Renewal will lead to another disconnection
client.connection.once(.disconnected) { stateChange in
guard let error = stateChange?.reason else {
fail("Error is nil"); done(); return
}
expect(error.code) == 40142
expect(client.connection.errorReason).to(beIdenticalTo(error))
done()
}
expect(error.code) == 40142
expect(client.connection.errorReason).to(beIdenticalTo(error))
done()
}

client.connect()
}
}

Expand Down

0 comments on commit 97d5c13

Please sign in to comment.