@@ -226,31 +226,61 @@ class SocketSideEffectTest: XCTestCase {
226
226
227
227
socket. setTestStatus ( . notConnected)
228
228
229
- socket. connect ( timeoutAfter: 1 , withHandler: {
229
+ socket. connect ( timeoutAfter: 0.2 , withHandler: {
230
230
expect. fulfill ( )
231
231
} )
232
232
233
- waitForExpectations ( timeout: 2 )
233
+ waitForExpectations ( timeout: 0.4 )
234
234
}
235
235
236
236
func testConnectDoesNotTimeOutIfConnected( ) {
237
237
let expect = expectation ( description: " The client should not call the timeout function " )
238
238
239
239
socket. setTestStatus ( . notConnected)
240
240
241
- socket. connect ( timeoutAfter: 1 , withHandler: {
241
+ socket. connect ( timeoutAfter: 0.3 , withHandler: {
242
242
XCTFail ( " Should not call timeout handler if status is connected " )
243
243
} )
244
244
245
- DispatchQueue . main. asyncAfter ( deadline: DispatchTime . now ( ) + 0.2 ) {
245
+ DispatchQueue . main. asyncAfter ( deadline: DispatchTime . now ( ) + 0.1 ) {
246
246
// Fake connecting
247
247
self . socket. setTestStatus ( . connected)
248
248
}
249
249
250
- DispatchQueue . main. asyncAfter ( deadline: DispatchTime . now ( ) + 1.1 ) {
250
+ DispatchQueue . main. asyncAfter ( deadline: DispatchTime . now ( ) + 0.5 ) {
251
+ expect. fulfill ( )
252
+ }
253
+
254
+ waitForExpectations ( timeout: 2 )
255
+ }
256
+
257
+ func testConnectIsCalledWithNamepsace( ) {
258
+ let expect = expectation ( description: " The client should not call the timeout function " )
259
+ let nspString = " /swift "
260
+
261
+ socket. setTestStatus ( . notConnected)
262
+
263
+ socket. on ( clientEvent: . connect) { data, ack in
264
+ guard let nsp = data [ 0 ] as? String else {
265
+ XCTFail ( " Connect should be called with a namespace " )
266
+
267
+ return
268
+ }
269
+
270
+ XCTAssertEqual ( nspString, nsp, " It should connect with the correct namespace " )
271
+
251
272
expect. fulfill ( )
252
273
}
253
274
275
+ socket. connect ( timeoutAfter: 0.3 , withHandler: {
276
+ XCTFail ( " Should not call timeout handler if status is connected " )
277
+ } )
278
+
279
+ DispatchQueue . main. asyncAfter ( deadline: DispatchTime . now ( ) + 0.1 ) {
280
+ // Fake connecting
281
+ self . socket. parseEngineMessage ( " 0/swift " )
282
+ }
283
+
254
284
waitForExpectations ( timeout: 2 )
255
285
}
256
286
0 commit comments