@@ -233,6 +233,7 @@ - (void)testDisconnectAfterConnect {
233
233
234
234
XCTestExpectation *setupConnection =
235
235
[self expectationWithDescription: @" Fcm should successfully setup a connection" ];
236
+ XCTestExpectation *disconnected = [self expectationWithDescription: @" Fcm should disconnect" ];
236
237
237
238
__block int timesConnected = 0 ;
238
239
FIRMessagingConnectCompletionHandler handler = ^(NSError *error) {
@@ -243,11 +244,12 @@ - (void)testDisconnectAfterConnect {
243
244
// disconnect the connection after some time
244
245
FIRMessagingFakeConnection *fakeConnection =
245
246
(FIRMessagingFakeConnection *)[self .mockClient connection ];
246
- dispatch_time_t time = dispatch_time (DISPATCH_TIME_NOW, (0.2 * NSEC_PER_SEC));
247
+ dispatch_time_t time = dispatch_time (DISPATCH_TIME_NOW, (0.5 * NSEC_PER_SEC));
247
248
dispatch_after (time, dispatch_get_main_queue (), ^{
248
249
// disconnect now
249
250
[(FIRMessagingFakeConnection *)fakeConnection mockSocketDisconnect ];
250
251
[(FIRMessagingFakeConnection *)fakeConnection disconnectNow ];
252
+ [disconnected fulfill ];
251
253
});
252
254
} else {
253
255
XCTFail (@" Fcm should only connect at max 2 times" );
@@ -258,12 +260,11 @@ - (void)testDisconnectAfterConnect {
258
260
// reconnect after disconnect
259
261
XCTAssertTrue (self.client .isConnectionActive );
260
262
261
- [self waitForExpectationsWithTimeout: 10.0
262
- handler: ^(NSError *error) {
263
- XCTAssertNil (error);
264
- XCTAssertNotEqual (self.client .lastDisconnectedTimestamp , 0 );
265
- XCTAssertTrue (self.client .isConnectionActive );
266
- }];
263
+ [self waitForExpectations: @[ setupConnection ] timeout: 2 ];
264
+ XCTAssertNotEqual (self.client .lastDisconnectedTimestamp , 0 );
265
+ XCTAssertTrue (self.client .isConnectionActive );
266
+ [self waitForExpectations: @[ disconnected ] timeout: 2 ];
267
+ XCTAssertFalse (self.client .isConnectionActive );
267
268
}
268
269
269
270
#pragma mark - Private Helpers
0 commit comments