diff options
author | NicoleYarroch <nicole@livio.io> | 2020-06-18 13:56:35 -0400 |
---|---|---|
committer | NicoleYarroch <nicole@livio.io> | 2020-06-18 13:56:35 -0400 |
commit | 9dd3712ed129c1c110c64d43841ffd004b21107e (patch) | |
tree | ce17fdfca1290a68081daff472d37cbc8b2f0ef6 | |
parent | 3fe2e773719079a1c8beb739fd9dc73d24f5a873 (diff) | |
download | sdl_ios-bugfix/issue_1634_wifi_turned_off_breaks_secondary_transport.tar.gz |
Transport now shut down after registration failurebugfix/issue_1634_wifi_turned_off_breaks_secondary_transport
Signed-off-by: NicoleYarroch <nicole@livio.io>
-rw-r--r-- | SmartDeviceLink/SDLSecondaryTransportManager.m | 13 | ||||
-rw-r--r-- | SmartDeviceLinkTests/ProxySpecs/SDLSecondaryTransportManagerSpec.m | 49 |
2 files changed, 53 insertions, 9 deletions
diff --git a/SmartDeviceLink/SDLSecondaryTransportManager.m b/SmartDeviceLink/SDLSecondaryTransportManager.m index 4bbdb828e..64d2b980f 100644 --- a/SmartDeviceLink/SDLSecondaryTransportManager.m +++ b/SmartDeviceLink/SDLSecondaryTransportManager.m @@ -154,7 +154,7 @@ struct TransportProtocolUpdated { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sdl_hmiStatusDidChange:) name:SDLDidChangeHMIStatusNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sdl_appStateDidBecomeActive:) name:UIApplicationDidBecomeActiveNotification object:nil]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sdl_appStateDidBecomeInActive:) name:UIApplicationWillResignActiveNotification object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sdl_appStateDidBecomeInactive:) name:UIApplicationWillResignActiveNotification object:nil]; return self; } @@ -555,12 +555,12 @@ struct TransportProtocolUpdated { return; } - // if the state is still Connecting, go back to Configured state and retry immediately + // If still in Connecting state, shutdown the transport and try to reconnect if ([strongSelf.stateMachine isCurrentState:SDLSecondaryTransportStateConnecting]) { - SDLLogD(@"Retry secondary transport connection after registration timeout"); - [strongSelf.stateMachine transitionToState:SDLSecondaryTransportStateConfigured]; + SDLLogD(@"Shutting down and restarting the secondary transport connection after registration timeout"); + [strongSelf sdl_transportClosed]; } else { - SDLLogD(@"Will not retry secondary transport connection because current state is: %@", strongSelf.stateMachine.currentState); + SDLLogD(@"Could not register the secondary transport with the module. The services will not be started on the secondary transport."); } }); }; @@ -717,7 +717,7 @@ struct TransportProtocolUpdated { }); } -- (void)sdl_appStateDidBecomeInActive:(NSNotification *)notification { +- (void)sdl_appStateDidBecomeInactive:(NSNotification *)notification { self.currentApplicationState = UIApplicationStateInactive; __weak typeof(self) weakSelf = self; @@ -815,6 +815,7 @@ struct TransportProtocolUpdated { } #pragma mark - RPC Notifications + /// Check and track the HMI status to ensure that the secondary transport only attempts a connection in non-NONE HMI states /// /// See: https://github.com/smartdevicelink/sdl_evolution/blob/master/proposals/0214-secondary-transport-optimization.md diff --git a/SmartDeviceLinkTests/ProxySpecs/SDLSecondaryTransportManagerSpec.m b/SmartDeviceLinkTests/ProxySpecs/SDLSecondaryTransportManagerSpec.m index 7e284a4e7..f3e34ee09 100644 --- a/SmartDeviceLinkTests/ProxySpecs/SDLSecondaryTransportManagerSpec.m +++ b/SmartDeviceLinkTests/ProxySpecs/SDLSecondaryTransportManagerSpec.m @@ -45,6 +45,7 @@ typedef NS_ENUM(NSInteger, SDLSecondaryTransportType) { // should be in sync with SDLSecondaryTransportManager.m static const float RetryConnectionDelay = 5.25; +static const float RegisterTransportTime = 10.25; static const int TCPPortUnspecified = -1; @@ -645,8 +646,6 @@ describe(@"the secondary transport manager ", ^{ [testSecondaryProtocolMock onProtocolOpened]; OCMVerifyAllWithDelay(testSecondaryProtocolMock, 0.5); - - // Note: cannot test the timeout scenario since the timer fires on main thread }); describe(@"and Register Secondary Transport ACK is received", ^{ @@ -699,6 +698,50 @@ describe(@"the secondary transport manager ", ^{ expect(manager.stateMachine.currentState).toEventually(equal(SDLSecondaryTransportStateReconnecting)); }); }); + + describe(@"and timeout occurs while waiting for the module to respond to the Register Secondary Transport request", ^{ + beforeEach(^{ + // assume audio and video services are allowed only on secondary transport + manager.transportsForAudioService = @[@(SDLTransportClassSecondary)]; + manager.transportsForVideoService = @[@(SDLTransportClassSecondary)]; + manager.streamingServiceTransportMap[@(SDLServiceTypeAudio)] = @(SDLTransportClassSecondary); + manager.streamingServiceTransportMap[@(SDLServiceTypeVideo)] = @(SDLTransportClassSecondary); + }); + + it(@"if in the Connecting state it should transition to Reconnecting state", ^{ + dispatch_sync(testStateMachineQueue, ^{ + [manager.stateMachine setToState:SDLSecondaryTransportStateConnecting fromOldState:nil callEnterTransition:NO]; + }); + + [testSecondaryProtocolMock onProtocolOpened]; + + OCMExpect([testStreamingProtocolDelegate transportClosed]); + + // Wait for the timer to elapse + float waitTime = RegisterTransportTime; + NSLog(@"Please wait for register transport timer to elapse... (for %.02f seconds)", waitTime); + [NSThread sleepForTimeInterval:waitTime]; + + OCMVerifyAllWithDelay(testStreamingProtocolDelegate, 0.5); + + expect(manager.stateMachine.currentState).toEventually(equal(SDLSecondaryTransportStateReconnecting)); + }); + + it(@"if not in the Connecting state it should not try to reconnect", ^{ + dispatch_sync(testStateMachineQueue, ^{ + [manager.stateMachine setToState:SDLSecondaryTransportStateReconnecting fromOldState:nil callEnterTransition:NO]; + }); + + [testSecondaryProtocolMock onProtocolOpened]; + + // Wait for the timer to elapse + float waitTime = RegisterTransportTime; + NSLog(@"Please wait for register transport timer to elapse... (for %.02f seconds)", waitTime); + [NSThread sleepForTimeInterval:waitTime]; + + expect(manager.stateMachine.currentState).toEventually(equal(SDLSecondaryTransportStateReconnecting)); + }); + }); }); describe(@"when transport is closed", ^{ @@ -961,7 +1004,7 @@ describe(@"the secondary transport manager ", ^{ // wait for the timer float waitTime = RetryConnectionDelay; - NSLog(@"Please wait for reconnection timeout ... (for %f seconds)", waitTime); + NSLog(@"Please wait for reconnection timeout... (for %.02f seconds)", waitTime); [NSThread sleepForTimeInterval:waitTime]; expect(manager.stateMachine.currentState).toEventually(equal(SDLSecondaryTransportStateConfigured)); |