@@ -227,66 +227,6 @@ - (void)SLOWtestMQTTSessionManagerPersistent {
227227 [timer invalidate ];
228228}
229229
230- - (void )testSessionManagerShort {
231- NSDictionary *parameters = MQTTTestHelpers.broker ;
232- if ([parameters[@" websocket" ] boolValue ]) {
233- return ;
234- }
235-
236- MQTTSessionManager *manager = [[MQTTSessionManager alloc ] init ];
237- manager.delegate = self;
238-
239- // allow 5 sec for connect
240- self.timedout = false ;
241- NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval: 5
242- target: self
243- selector: @selector (timedout: )
244- userInfo: nil
245- repeats: false ];
246-
247-
248- manager.subscriptions = @{TOPIC: @(MQTTQosLevelExactlyOnce)};
249- [manager connectWithParameters: parameters clean: YES connectHandler: nil ];
250-
251- while (!self.timedout && manager.state != MQTTSessionManagerStateConnected) {
252- DDLogInfo (@" waiting for connect %d " , manager.state );
253- [[NSRunLoop currentRunLoop ] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: .1 ]];
254- }
255- if (timer.valid ) [timer invalidate ];
256-
257- // allow 5 sec for sending and receiving
258- self.timedout = false ;
259- timer = [NSTimer scheduledTimerWithTimeInterval: 5
260- target: self
261- selector: @selector (timedout: )
262- userInfo: nil
263- repeats: false ];
264-
265-
266- while (!self.timedout ) {
267- [manager sendData: [[NSDate date ].description dataUsingEncoding: NSUTF8StringEncoding]
268- topic: TOPIC qos: MQTTQosLevelExactlyOnce retain: FALSE ];
269- [[NSRunLoop currentRunLoop ] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 1 ]];
270- }
271- if (timer.valid ) [timer invalidate ];
272- [manager sendData: [[NSData alloc ] init ] topic: TOPIC qos: MQTTQosLevelExactlyOnce retain: true ];
273-
274- // allow 3 sec for disconnect
275- self.timedout = false ;
276- timer = [NSTimer scheduledTimerWithTimeInterval: 3
277- target: self
278- selector: @selector (timedout: )
279- userInfo: nil
280- repeats: false ];
281-
282- [manager disconnectWithDisconnectHandler: nil ];
283- while (!self.timedout && manager.state != MQTTSessionStatusClosed) {
284- DDLogInfo (@" waiting for disconnect %d " , manager.state );
285- [[NSRunLoop currentRunLoop ] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: .1 ]];
286- }
287- if (timer.valid ) [timer invalidate ];
288- }
289-
290230- (void )SLOWtestSessionManagerALotSubscriptions {
291231 NSDictionary *parameters = MQTTTestHelpers.broker ;
292232 if ([parameters[@" websocket" ] boolValue ]) {
@@ -585,10 +525,8 @@ - (void)testMQTTSessionManagerDestoryedWhenDeallocated {
585525 XCTAssertNil (weakManager);
586526}
587527
588- // Disable this test for now because it is failing. We need to figure out why
589- // and rewrite it in a better way or remove it completely
590- - (void )DISABLEtestMQTTSessionManagerRecconnectionWithConnectToLast {
591- NSDictionary *parameters = MQTTTestHelpers.allBrokers [@" mosquitto" ];
528+ - (void )testMQTTSessionManagerRecconnectionWithConnectToLast {
529+ NSDictionary *parameters = MQTTTestHelpers.broker ;
592530
593531 MQTTSessionManager *manager = [[MQTTSessionManager alloc ] init ];
594532
@@ -618,6 +556,16 @@ - (void)DISABLEtestMQTTSessionManagerRecconnectionWithConnectToLast {
618556 [self waitForExpectationsWithTimeout: 30 handler: nil ];
619557
620558 XCTAssertEqual (manager.state , MQTTSessionManagerStateConnected);
559+
560+ XCTestExpectation *expectation4 = [self expectationWithDescription: @" Disconnect Expectation" ];
561+ [manager disconnectWithDisconnectHandler: ^(NSError *error) {
562+ XCTAssertNil (error);
563+ [expectation4 fulfill ];
564+ }];
565+ [self waitForExpectationsWithTimeout: 30 handler: nil ];
566+
567+ XCTAssertEqual (manager.state , MQTTSessionManagerStateClosed);
568+
621569}
622570
623571#pragma mark - helpers
0 commit comments