summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Fischer <joeljfischer@gmail.com>2016-11-07 10:02:16 -0500
committerJoel Fischer <joeljfischer@gmail.com>2016-11-07 10:02:16 -0500
commitc071ff5e0c2de8ac7b3bd8a46a87516a48794568 (patch)
treea748c5f11263f1f505e56eba7470b5625bc1081f
parent02b8c3847ee3701b0326fe1ffed6f6ea01736077 (diff)
downloadsdl_ios-hotfix/issue_467.tar.gz
Update uploading file operations to use built in cancel mechanismhotfix/issue_467
* Fixed a threading issue only affecting tests
-rw-r--r--SmartDeviceLink/SDLUploadFileOperation.m13
-rw-r--r--SmartDeviceLinkTests/DevAPISpecs/SDLFileManagerSpec.m4
2 files changed, 6 insertions, 11 deletions
diff --git a/SmartDeviceLink/SDLUploadFileOperation.m b/SmartDeviceLink/SDLUploadFileOperation.m
index aa9474972..65910ab5f 100644
--- a/SmartDeviceLink/SDLUploadFileOperation.m
+++ b/SmartDeviceLink/SDLUploadFileOperation.m
@@ -56,7 +56,6 @@ NS_ASSUME_NONNULL_BEGIN
}
- (void)sdl_sendPutFiles:(NSArray<SDLPutFile *> *)putFiles withCompletion:(SDLFileManagerUploadCompletionHandler)completion {
- __block BOOL stop = NO;
__block NSError *streamError = nil;
__block NSUInteger bytesAvailable = 0;
__block NSInteger highestCorrelationIDReceived = -1;
@@ -67,7 +66,8 @@ NS_ASSUME_NONNULL_BEGIN
// When the putfiles all complete, run this block
__weak typeof(self) weakself = self;
dispatch_group_notify(putFileGroup, dispatch_get_main_queue(), ^{
- if (streamError != nil || stop) {
+ typeof(weakself) strongself = weakself;
+ if (streamError != nil || strongself.isCancelled) {
completion(NO, bytesAvailable, streamError);
} else {
completion(YES, bytesAvailable, nil);
@@ -82,20 +82,15 @@ NS_ASSUME_NONNULL_BEGIN
[self.connectionManager sendManagerRequest:putFile
withResponseHandler:^(__kindof SDLRPCRequest *_Nullable request, __kindof SDLRPCResponse *_Nullable response, NSError *_Nullable error) {
typeof(weakself) strongself = weakself;
- // If we've already encountered an error, then just abort
// TODO: Is this the right way to handle this case? Should we just abort everything in the future? Should we be deleting what we sent? Should we have an automatic retry strategy based on what the error was?
if (strongself.isCancelled) {
- stop = YES;
- }
-
- if (stop) {
dispatch_group_leave(putFileGroup);
BLOCK_RETURN;
}
// If we encounted an error, abort in the future and call the completion handler
- if (error != nil || response == nil || ![response.success boolValue]) {
- stop = YES;
+ if (error != nil || response == nil || ![response.success boolValue] || strongself.isCancelled) {
+ [strongself cancel];
streamError = error;
dispatch_group_leave(putFileGroup);
diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLFileManagerSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLFileManagerSpec.m
index 8b3d3d7db..728128aea 100644
--- a/SmartDeviceLinkTests/DevAPISpecs/SDLFileManagerSpec.m
+++ b/SmartDeviceLinkTests/DevAPISpecs/SDLFileManagerSpec.m
@@ -281,7 +281,7 @@ describe(@"SDLFileManager", ^{
});
it(@"should call the completion handler with correct data", ^{
- expect(completionError).to(equal([NSError sdl_lifecycle_notReadyError]));
+ expect(completionError).toEventually(equal([NSError sdl_lifecycle_notReadyError]));
});
});
});
@@ -404,7 +404,7 @@ describe(@"SDLFileManager", ^{
});
it(@"should call the completion handler with nil error", ^{
- expect(completionError).to(equal([NSError sdl_lifecycle_notReadyError]));
+ expect(completionError).toEventually(equal([NSError sdl_lifecycle_notReadyError]));
});
});
});