@@ -252,6 +252,7 @@ class SocketSideEffectTest: XCTestCase {
252
252
let expect = expectation ( description: " The client should call the timeout function " )
253
253
254
254
socket. setTestStatus ( . notConnected)
255
+ socket. nsp = " /someNamespace "
255
256
socket. engine = TestEngine ( client: socket, url: socket. socketURL, options: nil )
256
257
257
258
socket. connect ( timeoutAfter: 0.5 , withHandler: {
@@ -283,6 +284,23 @@ class SocketSideEffectTest: XCTestCase {
283
284
waitForExpectations ( timeout: 2 )
284
285
}
285
286
287
+ func testClientCallsConnectOnEngineOpen( ) {
288
+ let expect = expectation ( description: " The client call the connect handler " )
289
+
290
+ socket. setTestStatus ( . notConnected)
291
+ socket. engine = TestEngine ( client: socket, url: socket. socketURL, options: nil )
292
+
293
+ socket. on ( clientEvent: . connect) { data, ack in
294
+ expect. fulfill ( )
295
+ }
296
+
297
+ socket. connect ( timeoutAfter: 0.5 , withHandler: {
298
+ XCTFail ( " Should not call timeout handler if status is connected " )
299
+ } )
300
+
301
+ waitForExpectations ( timeout: 2 )
302
+ }
303
+
286
304
func testConnectIsCalledWithNamespace( ) {
287
305
let expect = expectation ( description: " The client should not call the timeout function " )
288
306
let nspString = " /swift "
@@ -399,7 +417,7 @@ struct ThrowingData : SocketData {
399
417
}
400
418
401
419
class TestEngine : SocketEngineSpec {
402
- var client : SocketEngineClient ? = nil
420
+ weak var client : SocketEngineClient ?
403
421
private( set) var closed = false
404
422
private( set) var connected = false
405
423
var connectParams : [ String : Any ] ? = nil
@@ -418,9 +436,14 @@ class TestEngine : SocketEngineSpec {
418
436
private( set) var websocket = false
419
437
private( set) var ws : WebSocket ? = nil
420
438
421
- required init ( client: SocketEngineClient , url: URL , options: NSDictionary ? ) { }
439
+ required init ( client: SocketEngineClient , url: URL , options: NSDictionary ? ) {
440
+ self . client = client
441
+ }
442
+
443
+ func connect( ) {
444
+ client? . engineDidOpen ( reason: " Connect " )
445
+ }
422
446
423
- func connect( ) { }
424
447
func didError( reason: String ) { }
425
448
func disconnect( reason: String ) { }
426
449
func doFastUpgrade( ) { }
0 commit comments