add test for transport open calling connect

This commit is contained in:
Erik Little 2017-10-03 20:06:55 -04:00
parent cd2454373a
commit 5c0bbde77b
No known key found for this signature in database
GPG Key ID: 4930B7C5FBC1A69D

View File

@ -252,6 +252,7 @@ class SocketSideEffectTest: XCTestCase {
let expect = expectation(description: "The client should call the timeout function") let expect = expectation(description: "The client should call the timeout function")
socket.setTestStatus(.notConnected) socket.setTestStatus(.notConnected)
socket.nsp = "/someNamespace"
socket.engine = TestEngine(client: socket, url: socket.socketURL, options: nil) socket.engine = TestEngine(client: socket, url: socket.socketURL, options: nil)
socket.connect(timeoutAfter: 0.5, withHandler: { socket.connect(timeoutAfter: 0.5, withHandler: {
@ -283,6 +284,23 @@ class SocketSideEffectTest: XCTestCase {
waitForExpectations(timeout: 2) waitForExpectations(timeout: 2)
} }
func testClientCallsConnectOnEngineOpen() {
let expect = expectation(description: "The client call the connect handler")
socket.setTestStatus(.notConnected)
socket.engine = TestEngine(client: socket, url: socket.socketURL, options: nil)
socket.on(clientEvent: .connect) {data, ack in
expect.fulfill()
}
socket.connect(timeoutAfter: 0.5, withHandler: {
XCTFail("Should not call timeout handler if status is connected")
})
waitForExpectations(timeout: 2)
}
func testConnectIsCalledWithNamespace() { func testConnectIsCalledWithNamespace() {
let expect = expectation(description: "The client should not call the timeout function") let expect = expectation(description: "The client should not call the timeout function")
let nspString = "/swift" let nspString = "/swift"
@ -399,7 +417,7 @@ struct ThrowingData : SocketData {
} }
class TestEngine : SocketEngineSpec { class TestEngine : SocketEngineSpec {
var client: SocketEngineClient? = nil weak var client: SocketEngineClient?
private(set) var closed = false private(set) var closed = false
private(set) var connected = false private(set) var connected = false
var connectParams: [String: Any]? = nil var connectParams: [String: Any]? = nil
@ -418,9 +436,14 @@ class TestEngine : SocketEngineSpec {
private(set) var websocket = false private(set) var websocket = false
private(set) var ws: WebSocket? = nil private(set) var ws: WebSocket? = nil
required init(client: SocketEngineClient, url: URL, options: NSDictionary?) { } required init(client: SocketEngineClient, url: URL, options: NSDictionary?) {
self.client = client
}
func connect() {
client?.engineDidOpen(reason: "Connect")
}
func connect() { }
func didError(reason: String) { } func didError(reason: String) { }
func disconnect(reason: String) { } func disconnect(reason: String) { }
func doFastUpgrade() { } func doFastUpgrade() { }