Modify mock environments to register all db views.

pull/1/head
Matthew Chen 7 years ago
parent 83e6484156
commit 3b2c5bfc7b

@ -68,15 +68,17 @@ NS_ASSUME_NONNULL_BEGIN
[NSKeyedUnarchiver setClass:[OWSDatabaseMigration class] forClassName:[OWSDatabaseMigration collection]];
[OWSStorage registerExtensionsWithMigrationBlock:^() {
// Don't start database migrations until storage is ready.
[VersionMigrations performUpdateCheckWithCompletion:^() {
OWSAssertIsOnMainThread();
dispatch_async(dispatch_get_main_queue(), ^{
// Don't start database migrations until storage is ready.
[VersionMigrations performUpdateCheckWithCompletion:^() {
OWSAssertIsOnMainThread();
migrationCompletion();
migrationCompletion();
OWSAssertDebug(backgroundTask);
backgroundTask = nil;
}];
OWSAssertDebug(backgroundTask);
backgroundTask = nil;
}];
});
}];
});
}

@ -213,17 +213,18 @@ void VerifyRegistrationsForPrimaryStorage(OWSStorage *storage)
[OWSMediaGalleryFinder asyncRegisterDatabaseExtensionsWithPrimaryStorage:self];
[TSDatabaseView asyncRegisterLazyRestoreAttachmentsDatabaseView:self];
[self.database flushExtensionRequestsWithCompletionQueue:nil
completionBlock:^{
OWSAssertIsOnMainThread();
OWSAssertDebug(!self.areAsyncRegistrationsComplete);
OWSLogVerbose(@"async registrations complete.");
self.areAsyncRegistrationsComplete = YES;
[self.database
flushExtensionRequestsWithCompletionQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
completionBlock:^{
OWSAssertDebug(!self.areAsyncRegistrationsComplete);
OWSLogVerbose(@"async registrations complete.");
completion();
self.areAsyncRegistrationsComplete = YES;
[self verifyDatabaseViews];
}];
completion();
[self verifyDatabaseViews];
}];
}
- (void)verifyDatabaseViews

@ -15,6 +15,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)loadDatabase;
- (void)runSyncRegistrations;
// completion will be invoked _off_ the main thread.
- (void)runAsyncRegistrationsWithCompletion:(void (^_Nonnull)(void))completion;
- (BOOL)areAsyncRegistrationsComplete;

@ -58,6 +58,7 @@ typedef void (^OWSStorageMigrationBlock)(void);
// This object can be used to filter database notifications.
@property (nonatomic, readonly, nullable) id dbNotificationObject;
// migrationBlock will be invoked _off_ the main thread.
+ (void)registerExtensionsWithMigrationBlock:(OWSStorageMigrationBlock)migrationBlock;
#ifdef DEBUG

@ -27,7 +27,9 @@ NS_ASSUME_NONNULL_BEGIN
+ (void)activate
{
[self setShared:[self new]];
MockSSKEnvironment *instance = [self new];
[self setShared:instance];
[instance configure];
}
- (instancetype)init
@ -51,19 +53,22 @@ NS_ASSUME_NONNULL_BEGIN
return self;
}
+ (OWSPrimaryStorage *)createPrimaryStorageForTests
{
OWSPrimaryStorage *primaryStorage = [[OWSPrimaryStorage alloc] initStorage];
[OWSPrimaryStorage protectFiles];
// TODO: Should we inject a block to do view registrations?
primaryStorage.areAsyncRegistrationsComplete = YES;
primaryStorage.areSyncRegistrationsComplete = YES;
return primaryStorage;
}
- (void)configure
{
__block dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
[OWSStorage registerExtensionsWithMigrationBlock:^() {
dispatch_semaphore_signal(semaphore);
}];
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
}
@end
NS_ASSUME_NONNULL_END

Loading…
Cancel
Save