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

Fix out of range exception and failure to cancel Asynchronous RPC Operation #1078

Merged
merged 2 commits into from
Sep 19, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -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"
9 changes: 6 additions & 3 deletions SmartDeviceLink/SDLAsynchronousRPCRequestOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -119,17 +119,20 @@ - (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);
}

if (self.responseHandler != NULL) {
self.responseHandler(request, nil, [NSError sdl_lifecycle_multipleRequestsCancelled]);
}

if (self.completionHandler != NULL) {
self.completionHandler(NO);
}
}

[self finishOperation];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@

__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;
testConnectionManager = [[TestMultipleRequestsConnectionManager alloc] init];

sendRequests = [NSMutableArray array];
testProgressResponses = [NSMutableDictionary dictionary];
resultResponses = [NSMutableArray array];

testOperationQueue = [[NSOperationQueue alloc] init];
testOperationQueue.name = @"com.sdl.asynchronousRPCOp.testqueue";
Expand Down Expand Up @@ -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", ^{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the focus from this test case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

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];

Expand Down