From 90044b6650213cc530bd867ae92137f83d572c67 Mon Sep 17 00:00:00 2001 From: Nikita Lutsenko Date: Thu, 7 Jul 2016 19:21:15 -0700 Subject: [PATCH 1/3] Add CodeCov configuration. --- codecov.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 codecov.yml diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 000000000..04582b9b2 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,10 @@ +coverage: + ignore: + - Tests/.* + status: + project: + default: + target: 65 + patch: false + changes: false +comment: false From a9b444919f8830f0355843e79c2eac8ef7d27b54 Mon Sep 17 00:00:00 2001 From: Nikita Lutsenko Date: Wed, 6 Jul 2016 20:30:20 -0700 Subject: [PATCH 2/3] Remove all usages of Bolts exception APIs. --- Parse/Internal/BFTask+Private.m | 10 -------- .../OfflineStore/PFOfflineStore.m | 4 +--- .../SQLite/PFSQLiteDatabaseController.m | 2 -- Parse/Internal/PFAsyncTaskQueue.m | 7 +----- Parse/Internal/PFEventuallyQueue.m | 8 ++----- Parse/Internal/PFPinningEventuallyQueue.m | 2 +- .../Controller/PFCachedQueryController.m | 21 ++++++++++------- Parse/PFObject.m | 23 +++++-------------- Parse/PFUser.m | 4 ++-- Tests/Unit/QueryCachedControllerTests.m | 4 ++-- 10 files changed, 28 insertions(+), 57 deletions(-) diff --git a/Parse/Internal/BFTask+Private.m b/Parse/Internal/BFTask+Private.m index d93cd84fc..277ff7dc0 100644 --- a/Parse/Internal/BFTask+Private.m +++ b/Parse/Internal/BFTask+Private.m @@ -65,21 +65,13 @@ - (BFTask *)continueWithMainThreadResultBlock:(PFIdResultBlock)resultBlock return [self continueWithExecutor:[BFExecutor mainThreadExecutor] withBlock:^id(BFTask *task) { BFTaskCompletionSource *tcs = [BFTaskCompletionSource taskCompletionSource]; - @try { - if (self.exception) { - //TODO: (nlutsenko) Add more context, by passing a `_cmd` from the caller method - PFLogException(self.exception); - @throw self.exception; - } - if (!self.cancelled || executeIfCancelled) { resultBlock(self.result, self.error); } } @finally { tcs.result = nil; } - return tcs.task; }]; } @@ -121,8 +113,6 @@ - (id)waitForResult:(NSError **)error withMainThreadWarning:(BOOL)warningEnabled } if (self.cancelled) { return nil; - } else if (self.exception) { - @throw self.exception; } if (self.error && error) { *error = self.error; diff --git a/Parse/Internal/LocalDataStore/OfflineStore/PFOfflineStore.m b/Parse/Internal/LocalDataStore/OfflineStore/PFOfflineStore.m index 2d6844007..262d3aaaa 100644 --- a/Parse/Internal/LocalDataStore/OfflineStore/PFOfflineStore.m +++ b/Parse/Internal/LocalDataStore/OfflineStore/PFOfflineStore.m @@ -272,8 +272,6 @@ - (instancetype)initWithFileManager:(PFFileManager *)fileManager options:(PFOffl [tcs cancel]; } else if (task.error != nil) { [tcs setError:task.error]; - } else if (task.exception != nil) { - [tcs setException:task.exception]; } else { [tcs setResult:object]; } @@ -431,7 +429,7 @@ - (instancetype)initWithFileManager:(PFFileManager *)fileManager options:(PFOffl user:user pin:pin isCount:YES] continueWithSuccessBlock:^id(BFTask *task) { - if (!task.cancelled && !task.error && !task.exception) { + if (!task.cancelled && !task.faulted) { NSArray *result = task.result; return @(result.count); } diff --git a/Parse/Internal/LocalDataStore/SQLite/PFSQLiteDatabaseController.m b/Parse/Internal/LocalDataStore/SQLite/PFSQLiteDatabaseController.m index f1dfae511..f4fc7c1ac 100644 --- a/Parse/Internal/LocalDataStore/SQLite/PFSQLiteDatabaseController.m +++ b/Parse/Internal/LocalDataStore/SQLite/PFSQLiteDatabaseController.m @@ -54,8 +54,6 @@ - (BFTask *)openDatabaseWithNameAsync:(NSString *)name { NSError *error = task.error; if (error) { [taskCompletionSource trySetError:error]; - } else { - [taskCompletionSource trySetException:task.exception]; } } else if (task.cancelled) { [taskCompletionSource trySetCancelled]; diff --git a/Parse/Internal/PFAsyncTaskQueue.m b/Parse/Internal/PFAsyncTaskQueue.m index 2dae1672a..c154143bd 100644 --- a/Parse/Internal/PFAsyncTaskQueue.m +++ b/Parse/Internal/PFAsyncTaskQueue.m @@ -50,12 +50,7 @@ - (BFTask *)enqueue:(BFContinuationBlock)block { _tail = [_tail continueAsyncWithBlock:block]; [_tail continueAsyncWithBlock:^id(BFTask *task) { if (task.faulted) { - NSError *error = task.error; - if (error) { - [source trySetError:error]; - } else { - [source trySetException:task.exception]; - } + [source trySetError:task.error]; } else if (task.cancelled) { [source trySetCancelled]; } else { diff --git a/Parse/Internal/PFEventuallyQueue.m b/Parse/Internal/PFEventuallyQueue.m index 9c38ad703..663024e7b 100644 --- a/Parse/Internal/PFEventuallyQueue.m +++ b/Parse/Internal/PFEventuallyQueue.m @@ -106,12 +106,10 @@ - (BFTask *)enqueueCommandInBackground:(id)command withObject: return [[[self _enqueueCommandInBackground:command object:object identifier:identifier] continueWithBlock:^id(BFTask *task) { - if (task.error || task.exception || task.cancelled) { + if (task.faulted || task.cancelled) { [self.testHelper notify:PFEventuallyQueueEventCommandNotEnqueued]; if (task.error) { taskCompletionSource.error = task.error; - } else if (task.exception) { - taskCompletionSource.exception = task.exception; } else if (task.cancelled) { [taskCompletionSource cancel]; } @@ -305,8 +303,6 @@ - (void)_runCommandsWithRetriesCount:(NSUInteger)retriesCount { // Notify anyone waiting that the operation is completed. if (resultTask.error) { taskCompletionSource.error = resultTask.error; - } else if (resultTask.exception) { - taskCompletionSource.exception = resultTask.exception; } else if (resultTask.cancelled) { [taskCompletionSource cancel]; } else { @@ -340,7 +336,7 @@ - (BFTask *)_didFinishRunningCommand:(id)command [_taskCompletionSources removeObjectForKey:identifier]; }); - if (resultTask.exception || resultTask.error || resultTask.cancelled) { + if (resultTask.faulted || resultTask.cancelled) { [self.testHelper notify:PFEventuallyQueueEventCommandFailed]; } else { [self.testHelper notify:PFEventuallyQueueEventCommandSucceded]; diff --git a/Parse/Internal/PFPinningEventuallyQueue.m b/Parse/Internal/PFPinningEventuallyQueue.m index 80edaed2a..59ea4c1b5 100644 --- a/Parse/Internal/PFPinningEventuallyQueue.m +++ b/Parse/Internal/PFPinningEventuallyQueue.m @@ -212,7 +212,7 @@ - (BFTask *)_didFinishRunningCommand:(id)command [_eventuallyPinUUIDQueue removeObject:identifier]; }); - if (resultTask.cancelled || resultTask.exception || resultTask.error) { + if (resultTask.cancelled || resultTask.faulted) { return resultTask; } diff --git a/Parse/Internal/Query/Controller/PFCachedQueryController.m b/Parse/Internal/Query/Controller/PFCachedQueryController.m index 20dcca7b6..55631f2f6 100644 --- a/Parse/Internal/Query/Controller/PFCachedQueryController.m +++ b/Parse/Internal/Query/Controller/PFCachedQueryController.m @@ -68,8 +68,7 @@ - (BFTask *)runNetworkCommandAsync:(PFRESTCommand *)command } cancellationToken:cancellationToken]; } break; - case kPFCachePolicyCacheOnly: - { + case kPFCachePolicyCacheOnly: { return [self _runNetworkCommandAsyncFromCache:command withCancellationToken:cancellationToken forQueryState:queryState]; @@ -83,9 +82,9 @@ - (BFTask *)runNetworkCommandAsync:(PFRESTCommand *)command @weakify(self); return [networkTask continueWithBlock:^id(BFTask *task) { @strongify(self); - if (task.cancelled || task.exception) { + if (task.cancelled) { return task; - } else if (task.error) { + } else if (task.faulted) { return [self _runNetworkCommandAsyncFromCache:command withCancellationToken:cancellationToken forQueryState:queryState]; @@ -111,11 +110,17 @@ - (BFTask *)runNetworkCommandAsync:(PFRESTCommand *)command } cancellationToken:cancellationToken]; } break; - case kPFCachePolicyCacheThenNetwork: - PFConsistencyAssertionFailure(@"kPFCachePolicyCacheThenNetwork is not implemented as a runner."); + case kPFCachePolicyCacheThenNetwork: { + NSError *error = [PFErrorUtilities errorWithCode:kPFErrorInvalidQuery + message:@"Cache then network is not supported directly in PFCachedQueryController."]; + return [BFTask taskWithError:error]; + } break; - default: - PFConsistencyAssertionFailure(@"Unrecognized cache policy: %d", queryState.cachePolicy); + default: { + NSString *message = [NSString stringWithFormat:@"Unrecognized cache policy: %d", queryState.cachePolicy]; + NSError *error = [PFErrorUtilities errorWithCode:kPFErrorInvalidQuery message:message]; + return [BFTask taskWithError:error]; + } break; } return nil; diff --git a/Parse/PFObject.m b/Parse/PFObject.m index e8e23e653..22d39e9d2 100644 --- a/Parse/PFObject.m +++ b/Parse/PFObject.m @@ -505,13 +505,13 @@ + (BFTask *)_deepSaveAsyncChildrenOfObject:(id)object withCurrentUser:(PFUser *) }]; return [[BFTask taskForCompletionOfAllTasks:handleSaveTasks] continueAsyncWithBlock:^id(BFTask *task) { - if (commandRunnerTask.error || commandRunnerTask.cancelled || commandRunnerTask.exception) { + if (commandRunnerTask.faulted || commandRunnerTask.cancelled) { return commandRunnerTask; } // Reiterate saveAll tasks, return first error. for (BFTask *handleSaveTask in handleSaveTasks) { - if (handleSaveTask.error || handleSaveTask.exception) { + if (handleSaveTask.faulted) { return handleSaveTask; } } @@ -525,20 +525,9 @@ + (BFTask *)_deepSaveAsyncChildrenOfObject:(id)object withCurrentUser:(PFUser *) } return [[BFTask taskForCompletionOfAllTasks:tasks] continueWithBlock:^id(BFTask *task) { - // Return the first exception, instead of the aggregated one - // for the sake of compatability with old versions - - if ([task.exception.name isEqualToString:BFTaskMultipleExceptionsException]) { - NSException *firstException = [task.exception.userInfo[@"exceptions"] firstObject]; - if (firstException) { - return [BFTask taskWithException:firstException]; - } - } - - if (task.error || task.cancelled || task.exception) { + if (task.cancelled || task.faulted) { return task; } - return @YES; }]; }]; @@ -856,7 +845,7 @@ + (BFTask *)_migrateObjectInBackgroundFromFile:(NSString *)fileName BFTask *resultTask = [BFTask taskWithResult:object]; // Only delete if we successfully pin it so that it retries the migration next time. - if (!task.error && !task.exception && !task.cancelled) { + if (!task.faulted && !task.cancelled) { NSString *path = [[Parse _currentManager].fileManager parseDataItemPathForPathComponent:fileName]; return [[PFFileManager removeItemAtPathAsync:path] continueWithBlock:^id(BFTask *task) { // We don't care if it fails to delete the file, so return the @@ -1098,7 +1087,7 @@ - (BFTask *)_enqueueSaveEventuallyWithChildren:(BOOL)saveChildren { } saveTask = [saveTask continueWithBlock:^id(BFTask *task) { @try { - if (!task.isCancelled && !task.exception && !task.error) { + if (!task.isCancelled && !task.faulted) { PFCommandResult *result = task.result; // PFPinningEventuallyQueue handle save result directly. if (![Parse _currentManager].offlineStoreLoaded) { @@ -1405,7 +1394,7 @@ - (BFTask *)saveAsync:(BFTask *)toAwait { return [[Parse _currentManager].commandRunner runCommandAsync:command withOptions:PFCommandRunningOptionRetryIfFailed]; }] continueAsyncWithBlock:^id(BFTask *task) { - if (task.isCancelled || task.exception || task.error) { + if (task.cancelled || task.faulted) { // If there was an error, we want to roll forward the save changes before rethrowing. BFTask *commandRunnerTask = task; return [[self handleSaveResultAsync:nil] continueWithBlock:^id(BFTask *task) { diff --git a/Parse/PFUser.m b/Parse/PFUser.m index c8a48fd37..3953217e1 100644 --- a/Parse/PFUser.m +++ b/Parse/PFUser.m @@ -256,7 +256,7 @@ - (BFTask *)handleSignUpResultAsync:(BFTask *)task { BFTask *signUpTask = task; // Bail-out early, but still make sure that super class handled the result - if (task.error || task.cancelled || task.exception) { + if (task.faulted || task.cancelled) { return [[super handleSaveResultAsync:nil] continueWithBlock:^id(BFTask *task) { return signUpTask; }]; @@ -520,7 +520,7 @@ - (BFTask *)signUpAsync:(BFTask *)toAwait { [currentUser rebuildEstimatedData]; return [[[[currentUser saveInBackground] continueWithBlock:^id(BFTask *task) { - if (task.error || task.cancelled || task.exception) { + if (task.faulted || task.cancelled) { @synchronized ([currentUser lock]) { if (oldUsername) { currentUser.username = oldUsername; diff --git a/Tests/Unit/QueryCachedControllerTests.m b/Tests/Unit/QueryCachedControllerTests.m index acc365325..a5439ae81 100644 --- a/Tests/Unit/QueryCachedControllerTests.m +++ b/Tests/Unit/QueryCachedControllerTests.m @@ -294,7 +294,7 @@ - (void)testFindObjectsCacheThenNetwork { [[controller findObjectsAsyncForQueryState:state withCancellationToken:nil user:nil] continueWithBlock:^id(BFTask *task) { - XCTAssertNotNil(task.exception); + XCTAssertNotNil(task.error); [expectation fulfill]; return nil; }]; @@ -310,7 +310,7 @@ - (void)testFindObjectsUnknownPolicy { [[controller findObjectsAsyncForQueryState:state withCancellationToken:nil user:nil] continueWithBlock:^id(BFTask *task) { - XCTAssertNotNil(task.exception); + XCTAssertNotNil(task.error); [expectation fulfill]; return nil; }]; From ae09ca6107a570e17a544f1fc913a8820897a467 Mon Sep 17 00:00:00 2001 From: Nikita Lutsenko Date: Wed, 6 Jul 2016 21:05:58 -0700 Subject: [PATCH 3/3] Unbreak ConfigControllerTests by providing proper mock for PersistenceController. --- Tests/Unit/ConfigControllerTests.m | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Tests/Unit/ConfigControllerTests.m b/Tests/Unit/ConfigControllerTests.m index 36a5cd130..cdfaa401b 100644 --- a/Tests/Unit/ConfigControllerTests.m +++ b/Tests/Unit/ConfigControllerTests.m @@ -17,6 +17,12 @@ #import "PFConfig.h" #import "PFConfigController.h" #import "PFTestCase.h" +#import "PFPersistenceController.h" +#import "PFPersistenceGroup.h" + +@protocol ConfigControllerDataSource + +@end @interface ConfigControllerTests : PFTestCase @@ -24,6 +30,17 @@ @interface ConfigControllerTests : PFTestCase @implementation ConfigControllerTests +///-------------------------------------- +#pragma mark - Helpers +///-------------------------------------- + +- (PFPersistenceController *)mockedPersistenceController { + id controller = PFStrictClassMock([PFPersistenceController class]); + id group = PFProtocolMock(@protocol(PFPersistenceGroup)); + OCMStub([controller getPersistenceGroupAsync]).andReturn([BFTask taskWithResult:group]); + return controller; +} + ///-------------------------------------- #pragma mark - Tests ///-------------------------------------- @@ -50,8 +67,9 @@ - (void)testFetch { forCommandsPassingTest:^BOOL(id obj) { return YES; }]; - id dataSource = PFStrictProtocolMock(@protocol(PFCommandRunnerProvider)); + id dataSource = PFStrictProtocolMock(@protocol(ConfigControllerDataSource)); OCMStub([dataSource commandRunner]).andReturn(commandRunner); + OCMStub([dataSource persistenceController]).andReturn([self mockedPersistenceController]); PFConfigController *configController = [[PFConfigController alloc] initWithDataSource:dataSource];