summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Fischer <joeljfischer@gmail.com>2018-09-18 14:05:49 -0400
committerJoel Fischer <joeljfischer@gmail.com>2018-09-18 14:05:49 -0400
commit63d2fc001e5f937cf4e9e9802b3fa773ed9774e2 (patch)
tree6d33a5c41eb9e3e440b89ecdc5e9db70eea2b700
parentba71c667ad97f7409330cf7d350f3f581a7cf9f8 (diff)
downloadsdl_ios-bugfix/issue_1076_range_exception.tar.gz
Fix Async RPC Operation bugsbugfix/issue_1076_range_exception
-rw-r--r--Cartfile.resolved6
-rw-r--r--SmartDeviceLink/SDLAsynchronousRPCRequestOperation.m9
-rw-r--r--SmartDeviceLinkTests/DevAPISpecs/SDLAsynchronousRPCRequestOperationSpec.m29
3 files changed, 37 insertions, 7 deletions
diff --git a/Cartfile.resolved b/Cartfile.resolved
index 20086137a..45a305d09 100644
--- a/Cartfile.resolved
+++ b/Cartfile.resolved
@@ -1,4 +1,4 @@
-github "Quick/Nimble" "v7.0.3"
-github "Quick/Quick" "v1.2.0"
-github "erikdoe/ocmock" "v3.4.1"
+github "Quick/Nimble" "v7.3.0"
+github "Quick/Quick" "v1.3.1"
+github "erikdoe/ocmock" "v3.4.2"
github "facebook/ios-snapshot-test-case" "2.1.4"
diff --git a/SmartDeviceLink/SDLAsynchronousRPCRequestOperation.m b/SmartDeviceLink/SDLAsynchronousRPCRequestOperation.m
index a891f7268..5c67e3e8a 100644
--- a/SmartDeviceLink/SDLAsynchronousRPCRequestOperation.m
+++ b/SmartDeviceLink/SDLAsynchronousRPCRequestOperation.m
@@ -80,7 +80,7 @@ NS_ASSUME_NONNULL_BEGIN
for (SDLRPCRequest *request in self.requests) {
if (self.isCancelled) {
[self sdl_abortOperationWithRequest:request];
- break;
+ return;
}
[self sdl_sendRequest:request];
@@ -119,10 +119,9 @@ NS_ASSUME_NONNULL_BEGIN
}
- (void)sdl_abortOperationWithRequest:(SDLRPCRequest *)request {
- if (self.isFinished) { return; }
self.requestFailed = YES;
- for (NSUInteger i = self.requestsComplete; i <= self.requests.count; i++) {
+ for (NSUInteger i = self.requestsComplete; i < self.requests.count; i++) {
if (self.progressHandler != NULL) {
self.progressHandler(self.requests[i], nil, [NSError sdl_lifecycle_multipleRequestsCancelled], self.percentComplete);
}
@@ -130,6 +129,10 @@ NS_ASSUME_NONNULL_BEGIN
if (self.responseHandler != NULL) {
self.responseHandler(request, nil, [NSError sdl_lifecycle_multipleRequestsCancelled]);
}
+
+ if (self.completionHandler != NULL) {
+ self.completionHandler(NO);
+ }
}
[self finishOperation];
diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLAsynchronousRPCRequestOperationSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLAsynchronousRPCRequestOperationSpec.m
index eed4efa81..bf60c969f 100644
--- a/SmartDeviceLinkTests/DevAPISpecs/SDLAsynchronousRPCRequestOperationSpec.m
+++ b/SmartDeviceLinkTests/DevAPISpecs/SDLAsynchronousRPCRequestOperationSpec.m
@@ -17,7 +17,7 @@ describe(@"sending asynchronous requests", ^{
__block NSMutableArray<SDLAddCommand *> *sendRequests = nil;
__block NSMutableDictionary<NSNumber<SDLInt> *, TestRequestProgressResponse *> *testProgressResponses;
- __block NSMutableArray<SDLRPCResponse *> *resultResponses = [NSMutableArray array];
+ __block NSMutableArray<SDLRPCResponse *> *resultResponses = nil;
beforeEach(^{
testOperation = nil;
@@ -25,6 +25,7 @@ describe(@"sending asynchronous requests", ^{
sendRequests = [NSMutableArray array];
testProgressResponses = [NSMutableDictionary dictionary];
+ resultResponses = [NSMutableArray array];
testOperationQueue = [[NSOperationQueue alloc] init];
testOperationQueue.name = @"com.sdl.asynchronousRPCOp.testqueue";
@@ -62,6 +63,32 @@ describe(@"sending asynchronous requests", ^{
});
});
+ context(@"when request are cancelled", ^{
+ beforeEach(^{
+ for (int i = 0; i < 3; i++) {
+ SDLAddCommand *addCommand = [[SDLAddCommand alloc] init];
+ addCommand.correlationID = @(i);
+ [sendRequests addObject:addCommand];
+
+ testProgressResponses[addCommand.correlationID] = [[TestRequestProgressResponse alloc] initWithCorrelationId:addCommand.correlationID percentComplete:((float)(i+1)/3.0) error:nil];
+ }
+ });
+
+ fit(@"should fail correctly", ^{
+ testOperation = [[SDLAsynchronousRPCRequestOperation alloc] initWithConnectionManager:testConnectionManager requests:[sendRequests copy] progressHandler:^(__kindof SDLRPCRequest * _Nonnull request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error, float percentComplete) {
+ expect(percentComplete).to(beCloseTo(0));
+ expect(response).to(beNil());
+ expect(error).toNot(beNil());
+ expect(error.code).to(equal(-8));
+ } completionHandler:^(BOOL success) {
+ expect(success).to(beFalsy());
+ }];
+
+ [testOperationQueue addOperation:testOperation];
+ [testOperationQueue cancelAllOperations];
+ });
+ });
+
context(@"where not all requests succeed", ^{
__block NSError *testError = [NSError errorWithDomain:@"com.test" code:-3 userInfo:nil];