From 63d2fc001e5f937cf4e9e9802b3fa773ed9774e2 Mon Sep 17 00:00:00 2001 From: Joel Fischer Date: Tue, 18 Sep 2018 14:05:49 -0400 Subject: [PATCH 1/2] Fix Async RPC Operation bugs --- Cartfile.resolved | 6 ++-- .../SDLAsynchronousRPCRequestOperation.m | 9 ++++-- .../SDLAsynchronousRPCRequestOperationSpec.m | 29 ++++++++++++++++++- 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 @@ - (void)sdl_sendRequests { for (SDLRPCRequest *request in self.requests) { if (self.isCancelled) { [self sdl_abortOperationWithRequest:request]; - break; + return; } [self sdl_sendRequest:request]; @@ -119,10 +119,9 @@ - (void)sdl_sendRequest:(SDLRPCRequest *)request { } - (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 @@ - (void)sdl_abortOperationWithRequest:(SDLRPCRequest *)request { 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 @@ __block NSMutableArray *sendRequests = nil; __block NSMutableDictionary *, TestRequestProgressResponse *> *testProgressResponses; - __block NSMutableArray *resultResponses = [NSMutableArray array]; + __block NSMutableArray *resultResponses = nil; beforeEach(^{ testOperation = nil; @@ -25,6 +25,7 @@ sendRequests = [NSMutableArray array]; testProgressResponses = [NSMutableDictionary dictionary]; + resultResponses = [NSMutableArray array]; testOperationQueue = [[NSOperationQueue alloc] init]; testOperationQueue.name = @"com.sdl.asynchronousRPCOp.testqueue"; @@ -62,6 +63,32 @@ }); }); + 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]; From 7ebfb931f3b8bf1d22fe20aa54f142314c689776 Mon Sep 17 00:00:00 2001 From: Joel Fischer Date: Wed, 19 Sep 2018 10:29:27 -0400 Subject: [PATCH 2/2] Remove focus --- .../DevAPISpecs/SDLAsynchronousRPCRequestOperationSpec.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLAsynchronousRPCRequestOperationSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLAsynchronousRPCRequestOperationSpec.m index bf60c969f..7cec8f3e5 100644 --- a/SmartDeviceLinkTests/DevAPISpecs/SDLAsynchronousRPCRequestOperationSpec.m +++ b/SmartDeviceLinkTests/DevAPISpecs/SDLAsynchronousRPCRequestOperationSpec.m @@ -74,7 +74,7 @@ } }); - fit(@"should fail correctly", ^{ + it(@"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());