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]]; [NSKeyedUnarchiver setClass:[OWSDatabaseMigration class] forClassName:[OWSDatabaseMigration collection]];
[OWSStorage registerExtensionsWithMigrationBlock:^() { [OWSStorage registerExtensionsWithMigrationBlock:^() {
// Don't start database migrations until storage is ready. dispatch_async(dispatch_get_main_queue(), ^{
[VersionMigrations performUpdateCheckWithCompletion:^() { // Don't start database migrations until storage is ready.
OWSAssertIsOnMainThread(); [VersionMigrations performUpdateCheckWithCompletion:^() {
OWSAssertIsOnMainThread();
migrationCompletion(); migrationCompletion();
OWSAssertDebug(backgroundTask); OWSAssertDebug(backgroundTask);
backgroundTask = nil; backgroundTask = nil;
}]; }];
});
}]; }];
}); });
} }

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

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

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

@ -27,7 +27,9 @@ NS_ASSUME_NONNULL_BEGIN
+ (void)activate + (void)activate
{ {
[self setShared:[self new]]; MockSSKEnvironment *instance = [self new];
[self setShared:instance];
[instance configure];
} }
- (instancetype)init - (instancetype)init
@ -51,19 +53,22 @@ NS_ASSUME_NONNULL_BEGIN
return self; return self;
} }
+ (OWSPrimaryStorage *)createPrimaryStorageForTests + (OWSPrimaryStorage *)createPrimaryStorageForTests
{ {
OWSPrimaryStorage *primaryStorage = [[OWSPrimaryStorage alloc] initStorage]; OWSPrimaryStorage *primaryStorage = [[OWSPrimaryStorage alloc] initStorage];
[OWSPrimaryStorage protectFiles]; [OWSPrimaryStorage protectFiles];
// TODO: Should we inject a block to do view registrations?
primaryStorage.areAsyncRegistrationsComplete = YES;
primaryStorage.areSyncRegistrationsComplete = YES;
return primaryStorage; 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 @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

Loading…
Cancel
Save