Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase the timeout on some tests to fix CI fails #1930

Merged
merged 14 commits into from
Mar 10, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,9 @@
}];

[testOperationQueue addOperation:testOperation];
[NSThread sleepForTimeInterval:0.5];

expect(testSuccess).toEventually(beTruthy());
expect(testError).toEventually(beNil());
expect(testSuccess).withTimeout(3.0).toEventually(beTrue());
expect(testError).withTimeout(3.0).toEventually(beNil());
});
});

Expand Down Expand Up @@ -120,11 +119,10 @@
[resultResponses addObject:response];
} completionHandler:^(BOOL success) {
expect(resultResponses).to(haveCount(3));
expect(success).to(beFalsy());
expect(success).to(beFalse());
}];

[testOperationQueue addOperation:testOperation];
[NSThread sleepForTimeInterval:0.5];
});
});
});
Expand Down
14 changes: 3 additions & 11 deletions SmartDeviceLinkTests/DevAPISpecs/SDLAudioStreamManagerSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,11 @@
beforeEach(^{
[mockAudioManager clearData];
[testManager playNextWhenReady];
// playNextWhenReady dispatches to a new thread so the test can sometimes fail due to timing issues even when using `toEventually`.
[NSThread sleepForTimeInterval:0.1];
});

it(@"should fail to send data", ^{
expect(mockAudioManager.dataSinceClear.length).toEventually(equal(0));
expect(mockAudioManager.error.code).toEventually(equal(SDLAudioStreamManagerErrorNotConnected));
expect(mockAudioManager.dataSinceClear.length).withTimeout(3.0).toEventually(equal(0));
expect(mockAudioManager.error.code).withTimeout(3.0).toEventually(equal(SDLAudioStreamManagerErrorNotConnected));
});
});
});
Expand Down Expand Up @@ -89,13 +87,7 @@
it(@"should be sending data", ^{
expect(testManager.isPlaying).toEventually(beTrue());
expect(mockAudioManager.dataSinceClear.length).toEventually(equal(34380));

// wait for the delegate to be called when the audio finishes
float waitTime = 1.1 + 0.25; // length of audio in testAudioFileURL + 0.25 buffer
NSLog(@"Please wait %f for audio file to finish playing...", waitTime);
[NSThread sleepForTimeInterval:waitTime];

expect(mockAudioManager.finishedPlaying).toEventually(beTrue());
expect(mockAudioManager.finishedPlaying).withTimeout(3.0).toEventually(beTrue());
});
});

Expand Down
8 changes: 3 additions & 5 deletions SmartDeviceLinkTests/DevAPISpecs/SDLFileManagerSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,12 @@ @implementation FileManagerSpecHelper
startupError = error;
completionHandlerCalled = YES;
}];

[NSThread sleepForTimeInterval:0.1];
});

it(@"should have queued a ListFiles request", ^{
expect(testFileManager.currentState).to(match(SDLFileManagerStateFetchingInitialList));
expect(testFileManager.pendingTransactions).to(haveCount(@1));
expect(testFileManager.pendingTransactions.firstObject).to(beAnInstanceOf([SDLListFilesOperation class]));
expect(testFileManager.currentState).toEventually(match(SDLFileManagerStateFetchingInitialList));
expect(testFileManager.pendingTransactions).toEventually(haveCount(@1));
expect(testFileManager.pendingTransactions.firstObject).toEventually(beAnInstanceOf([SDLListFilesOperation class]));
});

describe(@"after going to the shutdown state and receiving a ListFiles response", ^{
Expand Down
6 changes: 2 additions & 4 deletions SmartDeviceLinkTests/DevAPISpecs/SDLLifecycleManagerSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,10 @@ + (void)configure:(Configuration *)configuration {
beforeEach(^{
[testManager.notificationDispatcher postNotificationName:SDLRPCServiceDidConnect infoObject:nil];
[testManager.notificationDispatcher postNotificationName:SDLTransportDidDisconnect infoObject:nil];
[NSThread sleepForTimeInterval:0.1];
});

it(@"should be in the started state", ^{
expect(testManager.lifecycleState).to(equal(SDLLifecycleStateReconnecting));
expect(testManager.lifecycleState).toEventually(equal(SDLLifecycleStateReconnecting));
});
});

Expand Down Expand Up @@ -518,11 +517,10 @@ + (void)configure:(Configuration *)configuration {
OCMStub([protocolMock stopWithCompletionHandler:[OCMArg invokeBlock]]);
OCMStub([secondaryTransportManagerMock stopWithCompletionHandler:[OCMArg invokeBlock]]);
[testManager.notificationDispatcher postNotificationName:SDLTransportDidDisconnect infoObject:nil];
[NSThread sleepForTimeInterval:1.0];
});

it(@"should enter the started state", ^{
expect(testManager.lifecycleState).toEventually(equal(SDLLifecycleStateStarted));
expect(testManager.lifecycleState).withTimeout(3.0).toEventually(equal(SDLLifecycleStateStarted));
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,19 @@
testOperation = [[SDLSequentialRPCRequestOperation alloc] initWithConnectionManager:testConnectionManager requests:sendRequests.copy progressHandler:^BOOL(__kindof SDLRPCRequest * _Nonnull request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error, float percentComplete) {
TestRequestProgressResponse *progressResponse = testProgressResponses[request.correlationID];

expect(progressResponse.percentComplete).toEventually(beCloseTo(percentComplete));
expect(response).toEventuallyNot(beNil());
expect(error).toEventually(beNil());
expect(progressResponse.percentComplete).to(beCloseTo(percentComplete));
expect(response).toNot(beNil());
expect(error).to(beNil());

[resultResponses addObject:response];

return YES;
} completionHandler:^(BOOL success) {
expect(resultResponses).to(haveCount(3));
expect(success).to(beTruthy());
expect(success).to(beTrue());
}];

[testOperationQueue addOperation:testOperation];
[NSThread sleepForTimeInterval:0.5];
});
});

Expand All @@ -82,11 +81,10 @@
return NO;
} completionHandler:^(BOOL success) {
expect(resultResponses).to(haveCount(1));
expect(success).to(beFalsy());
expect(success).to(beFalse());
}];

[testOperationQueue addOperation:testOperation];
[NSThread sleepForTimeInterval:0.5];
});
});
});
Expand Down Expand Up @@ -124,11 +122,10 @@
return YES;
} completionHandler:^(BOOL success) {
expect(resultResponses).to(haveCount(3));
expect(success).to(beFalsy());
expect(success).to(beFalse());
}];

[testOperationQueue addOperation:testOperation];
[NSThread sleepForTimeInterval:0.5];
});
});
});
Expand Down
26 changes: 15 additions & 11 deletions SmartDeviceLinkTests/DevAPISpecs/SDLSoftButtonManagerSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ - (void)sdl_displayCapabilityDidUpdate;
});
});

// valid button objects (button objects have different names)
describe(@"valid button objects (button objects have different names)", ^{
beforeEach(^{
SDLOnHMIStatus *status = [[SDLOnHMIStatus alloc] init];
Expand All @@ -208,27 +209,30 @@ - (void)sdl_displayCapabilityDidUpdate;
testObject2 = [[SDLSoftButtonObject alloc] initWithName:object2Name state:object2State1 handler:nil];

testManager.softButtonObjects = @[testObject1, testObject2];
[NSThread sleepForTimeInterval:0.1];
});

// should set soft buttons correctly
it(@"should set soft buttons correctly", ^{
expect(testManager.softButtonObjects).toNot(beNil());
expect(testObject1.buttonId).to(equal(1));
expect(testObject2.buttonId).to(equal(2));
expect(testObject1.manager).to(equal(testManager));
expect(testObject2.manager).to(equal(testManager));
expect(testManager.softButtonObjects).toEventuallyNot(beNil());
expect(testObject1.buttonId).toEventually(equal(1));
expect(testObject2.buttonId).toEventually(equal(2));
expect(testObject1.manager).toEventually(equal(testManager));
expect(testObject2.manager).toEventually(equal(testManager));

// One replace operation
expect(testManager.transactionQueue.operationCount).to(equal(1));
expect(testManager.transactionQueue.operationCount).toEventually(equal(1));
});

// should replace earlier operations when a replace operation is entered
it(@"should replace earlier operations when a replace operation is entered", ^{
[testObject1 transitionToNextState];
testManager.softButtonObjects = @[testObject1];
expect(testManager.transactionQueue.operationCount).to(equal(3));
expect(testManager.transactionQueue.operations[0].isCancelled).to(beTrue());
expect(testManager.transactionQueue.operations[1].isCancelled).to(beTrue());
expect(testManager.transactionQueue.operations[2].isCancelled).to(beFalse());
[NSThread sleepForTimeInterval:0.5]; // Necessary to not get range exceptions with toEventually?

expect(testManager.transactionQueue.operationCount).withTimeout(3.0).toEventually(equal(3));
expect(testManager.transactionQueue.operations[0].isCancelled).withTimeout(3.0).toEventually(beTrue());
expect(testManager.transactionQueue.operations[1].isCancelled).withTimeout(3.0).toEventually(beTrue());
expect(testManager.transactionQueue.operations[2].isCancelled).withTimeout(3.0).toEventually(beFalse());
});

it(@"should retrieve soft buttons correctly", ^{
Expand Down
6 changes: 3 additions & 3 deletions SmartDeviceLinkTests/DevAPISpecs/SDLVoiceCommandManagerSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,12 @@ @interface SDLVoiceCommandManager()
SDLVoiceCommandUpdateOperation *firstOp = testManager.transactionQueue.operations[0];
firstOp.currentVoiceCommands = [@[testVoiceCommand2] mutableCopy];
[firstOp finishOperation];

[NSThread sleepForTimeInterval:0.5];
});

it(@"should update the second operation", ^{
SDLVoiceCommandUpdateOperation *secondOp = testManager.transactionQueue.operations[0];

expect(secondOp.oldVoiceCommands.firstObject).toEventually(equal(testVoiceCommand2));
expect(((SDLVoiceCommandUpdateOperation *)testManager.transactionQueue.operations.firstObject).oldVoiceCommands.firstObject).withTimeout(3.0).toEventually(equal(testVoiceCommand2));
});
});
});
Expand Down
20 changes: 3 additions & 17 deletions SmartDeviceLinkTests/ProxySpecs/SDLSecondaryTransportManagerSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -726,13 +726,9 @@ __block void (^sendNotificationForHMILevel)(SDLHMILevel hmiLevel) = ^(SDLHMILeve

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];
[NSThread sleepForTimeInterval:RegisterTransportTime]; // This still needs to be here to ensure that the Verify happens correctly

OCMVerifyAllWithDelay(testStreamingProtocolDelegate, 0.5);

expect(manager.stateMachine.currentState).toEventually(equal(SDLSecondaryTransportStateReconnecting));
});

Expand All @@ -743,12 +739,7 @@ __block void (^sendNotificationForHMILevel)(SDLHMILevel hmiLevel) = ^(SDLHMILeve

[testSecondaryProtocolMock onTransportConnected];

// 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));
expect(manager.stateMachine.currentState).withTimeout(3.0).toEventually(equal(SDLSecondaryTransportStateReconnecting));
});
});
});
Expand Down Expand Up @@ -1011,12 +1002,7 @@ __block void (^sendNotificationForHMILevel)(SDLHMILevel hmiLevel) = ^(SDLHMILeve
[manager.stateMachine setToState:SDLSecondaryTransportStateReconnecting fromOldState:nil callEnterTransition:YES];
});

// wait for the timer
float waitTime = RetryConnectionDelay;
NSLog(@"Please wait for reconnection timeout... (for %.02f seconds)", waitTime);
[NSThread sleepForTimeInterval:waitTime];

expect(manager.stateMachine.currentState).toEventually(equal(SDLSecondaryTransportStateConfigured));
expect(manager.stateMachine.currentState).withTimeout(RetryConnectionDelay + 3.0).toEventually(equal(SDLSecondaryTransportStateConfigured));
});
});

Expand Down
8 changes: 4 additions & 4 deletions SmartDeviceLinkTests/SDLAlertManagerSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ @interface SDLPresentAlertOperation()
SDLPresentAlertOperation *presentAlertOp2 = testAlertManager.transactionQueue.operations[1];
expect(presentAlertOp1.isExecuting).to(beTrue());
expect(presentAlertOp2.isExecuting).to(beFalse());
expect(presentAlertOp1.currentWindowCapability).to(equal(testWindowCapability));
expect(presentAlertOp2.currentWindowCapability).to(beNil());
expect(presentAlertOp1.currentWindowCapability).toEventually(equal(testWindowCapability));
expect(presentAlertOp2.currentWindowCapability).toEventually(beNil());
});

it(@"should start the queue if the new capability is not nil and update the pending operations with the new capability", ^{
Expand All @@ -186,8 +186,8 @@ @interface SDLPresentAlertOperation()
SDLPresentAlertOperation *presentAlertOp2 = testAlertManager.transactionQueue.operations[1];
expect(presentAlertOp1.isExecuting).to(beTrue());
expect(presentAlertOp2.isExecuting).to(beFalse());
expect(presentAlertOp2.currentWindowCapability).to(equal(testWindowCapability));
expect(presentAlertOp1.currentWindowCapability).to(equal(testWindowCapability));
expect(presentAlertOp2.currentWindowCapability).toEventually(equal(testWindowCapability));
expect(presentAlertOp1.currentWindowCapability).toEventually(equal(testWindowCapability));
});
});

Expand Down
6 changes: 1 addition & 5 deletions SmartDeviceLinkTests/SDLAsynchronousRPCOperationSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@

it(@"should correctly send the rpc", ^{
testOperation = [[SDLAsynchronousRPCOperation alloc] initWithConnectionManager:testConnectionManager rpc:sendRPC];

[testOperationQueue addOperation:testOperation];
[NSThread sleepForTimeInterval:0.1];

expect(testConnectionManager.receivedRequests).toEventually(contain(sendRPC));
});
Expand Down Expand Up @@ -85,9 +83,7 @@
[testOperationQueue cancelAllOperations];
[testOperationQueue setSuspended:NO];

[NSThread sleepForTimeInterval:0.5];

expect(testConnectionManager.receivedRequests).toEventually(beEmpty());
expect(testConnectionManager.receivedRequests).withTimeout(3.0).toEventually(beEmpty());
});
});
});
Expand Down
4 changes: 2 additions & 2 deletions SmartDeviceLinkTests/SDLPresentAlertOperationSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -697,8 +697,8 @@ - (SDLAlert *)alertRPC;

[testPresentAlertOperation start];

expect(testPresentAlertOperation.internalError).to(equal([NSError sdl_alertManager_alertDataInvalid]));
expect(hasCalledOperationCompletionHandler).to(beTrue());
expect(testPresentAlertOperation.internalError).toEventually(equal([NSError sdl_alertManager_alertDataInvalid]));
expect(hasCalledOperationCompletionHandler).toEventually(beTrue());
expect(testPresentAlertOperation.isFinished).toEventually(beTrue());
});
});
Expand Down
16 changes: 7 additions & 9 deletions SmartDeviceLinkTests/SDLSystemCapabilityManagerSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -615,12 +615,11 @@ @interface SDLSystemCapabilityManager ()

it(@"should should not save the capabilities", ^{
[testSystemCapabilityManager updateCapabilityType:SDLSystemCapabilityTypePhoneCall completionHandler:^(NSError * _Nullable error, SDLSystemCapabilityManager * _Nonnull systemCapabilityManager) {
expect(error).toEventually(equal(testConnectionManager.defaultError));
expect(systemCapabilityManager.phoneCapability).toEventually(beNil());
expect(error).to(equal(testConnectionManager.defaultError));
expect(systemCapabilityManager.phoneCapability).to(beNil());
}];

[NSThread sleepForTimeInterval:0.1];

[NSThread sleepForTimeInterval:0.1]; // This still needs to be here to ensure request is sent first
[testConnectionManager respondToLastRequestWithResponse:testGetSystemCapabilityResponse];
});
});
Expand All @@ -632,18 +631,17 @@ @interface SDLSystemCapabilityManager ()

it(@"should save the capabilitity", ^{
[testSystemCapabilityManager updateCapabilityType:SDLSystemCapabilityTypePhoneCall completionHandler:^(NSError * _Nullable error, SDLSystemCapabilityManager * _Nonnull systemCapabilityManager) {
expect(testSystemCapabilityManager.phoneCapability).toEventually(equal(testPhoneCapability));
expect(error).toEventually(beNil());
expect(testSystemCapabilityManager.phoneCapability).to(equal(testPhoneCapability));
expect(error).to(beNil());
}];

[NSThread sleepForTimeInterval:0.1];

[NSThread sleepForTimeInterval:0.1]; // This still needs to be here to ensure request is sent first
[testConnectionManager respondToLastRequestWithResponse:testGetSystemCapabilityResponse];
});
});

afterEach(^{
// Make sure the RAIR properties and other system capabilities were not inadverdently set
// Make sure the RAIR properties and other system capabilities were not inadvertently set
expect(testSystemCapabilityManager.displays).to(beNil());
expect(testSystemCapabilityManager.hmiCapabilities).to(beNil());
#pragma clang diagnostic push
Expand Down