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

Fixed the choice set manager not handling failed preload choices correctly #2004

Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
c943104
Fixed cancelId tests
NicoleYarroch May 11, 2021
9ec7026
Fixed searchable PI tests
NicoleYarroch May 11, 2021
f3eaeb7
Fixed non/searchable PI tests
NicoleYarroch May 11, 2021
9773a68
Fixed mocked operation queue breaking other tests
NicoleYarroch May 11, 2021
007e4e0
Fixed shutdown during presentation tests
NicoleYarroch May 11, 2021
bc5eac6
Fixed presentation of choice set
NicoleYarroch May 11, 2021
8d85db3
Fixed keyboard dismissal tests
NicoleYarroch May 17, 2021
6cf628e
Added failed choice set tests
NicoleYarroch May 26, 2021
0a55970
Added missing docs
NicoleYarroch May 26, 2021
d5f2ba9
Added generics
NicoleYarroch May 26, 2021
54cd35f
Pending ops updated with failed choice uploads
NicoleYarroch Jun 1, 2021
159c021
Fixed failing tests
NicoleYarroch Jun 1, 2021
1d09aae
Tests added for +/- choices from op
NicoleYarroch Jun 1, 2021
6ef7afd
Added tests for updating preloading op choices
NicoleYarroch Jun 1, 2021
4c30d8e
Added tests for failed choice ids
NicoleYarroch Jun 1, 2021
7e83c69
Removed lazy init
NicoleYarroch Jun 2, 2021
c700e76
Removed check for count
NicoleYarroch Jun 2, 2021
e3449b9
Fixed var name
NicoleYarroch Jun 2, 2021
0fc6d7d
Added check for failed choice uploads
NicoleYarroch Jun 2, 2021
546b55f
Removed updates to preload choices
NicoleYarroch Jun 2, 2021
9a51e8f
Removed upload check
NicoleYarroch Jun 2, 2021
60061c6
Apply suggestions from code review
NicoleYarroch Jun 3, 2021
af8e69a
Fixed how items are added
NicoleYarroch Jun 3, 2021
9e19208
Added order matter expectation to tests
NicoleYarroch Jun 3, 2021
ae58436
Removed unecessary test settings
NicoleYarroch Jun 3, 2021
6ba82a8
Added shutdown tests
NicoleYarroch Jun 4, 2021
a3fa94a
Merge branch 'develop' into bugfix/issue_1941_failed_preload_choice_n…
joeljfischer Jun 4, 2021
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
35 changes: 32 additions & 3 deletions SmartDeviceLink/private/SDLChoiceSetManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ - (void)preloadChoices:(NSArray<SDLChoiceCell *> *)choices withCompletionHandler
return;
}


NSMutableOrderedSet<SDLChoiceCell *> *mutableChoicesToUpload = [self sdl_choicesToBeUploadedWithArray:choices];
[SDLGlobals runSyncOnSerialSubQueue:self.readWriteQueue block:^{
[mutableChoicesToUpload minusSet:self.preloadedMutableChoices];
Expand Down Expand Up @@ -268,6 +267,18 @@ - (void)preloadChoices:(NSArray<SDLChoiceCell *> *)choices withCompletionHandler
__strong typeof(weakSelf) strongSelf = weakSelf;
SDLLogD(@"Choices finished preloading");

NSMutableSet<SDLChoiceCell *> *failedChoiceUploads = [NSMutableSet set];
NicoleYarroch marked this conversation as resolved.
Show resolved Hide resolved
NicoleYarroch marked this conversation as resolved.
Show resolved Hide resolved
if (weakPreloadOp.error != nil) {
NSDictionary<NSErrorUserInfoKey, id> *failedChoices = weakPreloadOp.error.userInfo;
for (SDLCreateInteractionChoiceSet *request in failedChoices) {
NSUInteger failedChoiceUploadIndex = [choicesToUpload indexOfObjectPassingTest:^BOOL(SDLChoiceCell * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
return (obj.choiceId == request.choiceSet.firstObject.choiceID.intValue);
}];
if (failedChoiceUploadIndex == NSNotFound) { continue; }
[failedChoiceUploads addObject:choicesToUpload[failedChoiceUploadIndex]];
}
}

if (handler != nil) {
handler(weakPreloadOp.error);
}
Expand All @@ -280,8 +291,16 @@ - (void)preloadChoices:(NSArray<SDLChoiceCell *> *)choices withCompletionHandler

[SDLGlobals runSyncOnSerialSubQueue:self.readWriteQueue block:^{
__strong typeof(weakSelf) strongSelf = weakSelf;
[strongSelf.preloadedMutableChoices unionSet:choicesToUpload.set];
[strongSelf.pendingMutablePreloadChoices minusSet:choicesToUpload.set];
if (failedChoiceUploads.count == 0) {
[strongSelf.preloadedMutableChoices unionSet:choicesToUpload.set];
[strongSelf.pendingMutablePreloadChoices minusSet:choicesToUpload.set];
} else {
NSMutableSet *successfulChoiceUploads = [NSMutableSet setWithSet:choicesToUpload.set];
NicoleYarroch marked this conversation as resolved.
Show resolved Hide resolved
[successfulChoiceUploads minusSet:failedChoiceUploads];

[strongSelf.preloadedMutableChoices unionSet:[successfulChoiceUploads copy]];
NicoleYarroch marked this conversation as resolved.
Show resolved Hide resolved
[strongSelf.pendingMutablePreloadChoices minusSet:choicesToUpload.set];
}
}];
};
[self.transactionQueue addOperation:preloadOp];
Expand Down Expand Up @@ -373,13 +392,23 @@ - (void)presentChoiceSet:(SDLChoiceSet *)choiceSet mode:(SDLInteractionMode)mode
SDLLogD(@"Preloading and presenting choice set: %@", choiceSet);
self.pendingPresentationSet = choiceSet;

__weak typeof(self) weakSelf = self;
[self preloadChoices:self.pendingPresentationSet.choices withCompletionHandler:^(NSError * _Nullable error) {
__strong typeof(weakSelf) strongSelf = weakSelf;
if (error != nil) {
SDLLogE(@"Error preloading choice cells. Aborting presentation.");
NicoleYarroch marked this conversation as resolved.
Show resolved Hide resolved
[choiceSet.delegate choiceSet:choiceSet didReceiveError:error];
return;
}

[strongSelf sdl_presentChoiceSetWithMode:mode keyboardDelegate:delegate];
NicoleYarroch marked this conversation as resolved.
Show resolved Hide resolved
}];
}

/// Helper method for presenting a choice set.
/// @param mode If the set should be presented for the user to interact via voice, touch, or both
/// @param delegate The keyboard delegate called when the user interacts with the search field of the choice set, if not set, a non-searchable choice set will be used
- (void)sdl_presentChoiceSetWithMode:(SDLInteractionMode)mode keyboardDelegate:(nullable id<SDLKeyboardDelegate>)delegate {
[self sdl_findIdsOnChoiceSet:self.pendingPresentationSet];

SDLPresentChoiceSetOperation *presentOp = nil;
Expand Down
Loading