Improve pre-migration testing tools.

pull/1/head
Matthew Chen 7 years ago
parent 9d101c3f53
commit 6f7f1b3b08

@ -785,16 +785,16 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
self.isEnvironmentSetup = YES; self.isEnvironmentSetup = YES;
#ifdef DEBUG //#ifdef DEBUG
// A bug in orphan cleanup could be disastrous so let's only // // A bug in orphan cleanup could be disastrous so let's only
// run it in DEBUG builds for a few releases. // // run it in DEBUG builds for a few releases.
// // //
// TODO: Release to production once we have analytics. // // TODO: Release to production once we have analytics.
// TODO: Orphan cleanup is somewhat expensive - not least in doing a bunch // // TODO: Orphan cleanup is somewhat expensive - not least in doing a bunch
// of disk access. We might want to only run it "once per version" // // of disk access. We might want to only run it "once per version"
// or something like that in production. // // or something like that in production.
[OWSOrphanedDataCleaner auditAndCleanupAsync:nil]; // [OWSOrphanedDataCleaner auditAndCleanupAsync:nil];
#endif //#endif
[OWSProfileManager.sharedManager fetchLocalUsersProfile]; [OWSProfileManager.sharedManager fetchLocalUsersProfile];
[[OWSReadReceiptManager sharedManager] prepareCachedValues]; [[OWSReadReceiptManager sharedManager] prepareCachedValues];

@ -128,6 +128,10 @@ NS_ASSUME_NONNULL_BEGIN
actionBlock:^{ actionBlock:^{
[DebugUIMessages sendFakeMessages:100 * 1000 thread:thread]; [DebugUIMessages sendFakeMessages:100 * 1000 thread:thread];
}], }],
[OWSTableItem itemWithTitle:@"Create 100k fake text messages"
actionBlock:^{
[DebugUIMessages sendFakeMessages:100 * 1000 thread:thread isTextOnly:YES];
}],
[OWSTableItem itemWithTitle:@"Create 1 fake unread messages" [OWSTableItem itemWithTitle:@"Create 1 fake unread messages"
actionBlock:^{ actionBlock:^{
[DebugUIMessages createFakeUnreadMessages:1 thread:thread]; [DebugUIMessages createFakeUnreadMessages:1 thread:thread];
@ -983,27 +987,42 @@ NS_ASSUME_NONNULL_BEGIN
+ (void)sendFakeMessages:(NSUInteger)counter thread:(TSThread *)thread + (void)sendFakeMessages:(NSUInteger)counter thread:(TSThread *)thread
{ {
NSUInteger remainder = counter; [self sendFakeMessages:counter thread:thread isTextOnly:NO];
while (remainder > 0) { }
NSUInteger batchSize = MIN((NSUInteger)2500, remainder);
[TSStorageManager.dbReadWriteConnection + (void)sendFakeMessages:(NSUInteger)counter thread:(TSThread *)thread isTextOnly:(BOOL)isTextOnly
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { {
[self sendFakeMessages:counter thread:thread transaction:transaction]; const NSUInteger kMaxBatchSize = 2500;
}]; if (counter < kMaxBatchSize) {
remainder -= batchSize; [TSStorageManager.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
DDLogInfo(@"%@ sendFakeMessages %zd / %zd", self.logTag, counter - remainder, counter); [self sendFakeMessages:counter thread:thread isTextOnly:isTextOnly transaction:transaction];
}];
} else {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSUInteger remainder = counter;
while (remainder > 0) {
NSUInteger batchSize = MIN(kMaxBatchSize, remainder);
[TSStorageManager.dbReadWriteConnection
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
[self sendFakeMessages:batchSize thread:thread isTextOnly:isTextOnly transaction:transaction];
}];
remainder -= batchSize;
DDLogInfo(@"%@ sendFakeMessages %zd / %zd", self.logTag, counter - remainder, counter);
}
});
} }
} }
+ (void)sendFakeMessages:(NSUInteger)counter + (void)sendFakeMessages:(NSUInteger)counter
thread:(TSThread *)thread thread:(TSThread *)thread
isTextOnly:(BOOL)isTextOnly
transaction:(YapDatabaseReadWriteTransaction *)transaction transaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
DDLogInfo(@"%@ sendFakeMessages: %zd", self.logTag, counter); DDLogInfo(@"%@ sendFakeMessages: %zd", self.logTag, counter);
for (NSUInteger i = 0; i < counter; i++) { for (NSUInteger i = 0; i < counter; i++) {
NSString *randomText = [self randomText]; NSString *randomText = [self randomText];
switch (arc4random_uniform(4)) { switch (arc4random_uniform(isTextOnly ? 2 : 4)) {
case 0: { case 0: {
TSIncomingMessage *message = TSIncomingMessage *message =
[[TSIncomingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp] [[TSIncomingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp]
@ -1038,6 +1057,7 @@ NS_ASSUME_NONNULL_BEGIN
relay:@"" relay:@""
sourceFilename:@"test.mp3" sourceFilename:@"test.mp3"
attachmentType:TSAttachmentTypeDefault]; attachmentType:TSAttachmentTypeDefault];
pointer.state = TSAttachmentPointerStateFailed;
[pointer saveWithTransaction:transaction]; [pointer saveWithTransaction:transaction];
TSIncomingMessage *message = TSIncomingMessage *message =
[[TSIncomingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp] [[TSIncomingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp]
@ -1280,7 +1300,7 @@ NS_ASSUME_NONNULL_BEGIN
}, },
^(YapDatabaseReadWriteTransaction *transaction) { ^(YapDatabaseReadWriteTransaction *transaction) {
NSUInteger messageCount = (NSUInteger)(1 + arc4random_uniform(4)); NSUInteger messageCount = (NSUInteger)(1 + arc4random_uniform(4));
[self sendFakeMessages:messageCount thread:thread transaction:transaction]; [self sendFakeMessages:messageCount thread:thread isTextOnly:NO transaction:transaction];
}, },
^(YapDatabaseReadWriteTransaction *transaction) { ^(YapDatabaseReadWriteTransaction *transaction) {
NSUInteger messageCount = (NSUInteger)(1 + arc4random_uniform(4)); NSUInteger messageCount = (NSUInteger)(1 + arc4random_uniform(4));

@ -141,6 +141,10 @@ void runAsyncRegistrationsForStorage(OWSStorage *storage)
+ (void)protectFiles + (void)protectFiles
{ {
DDLogInfo(@"%@ Database file size: %@", self.logTag, [OWSFileSystem fileSizeOfPath:self.legacyDatabaseFilePath]);
DDLogInfo(@"%@ \t SHM file size: %@", self.logTag, [OWSFileSystem fileSizeOfPath:self.legacyDatabaseFilePath_SHM]);
DDLogInfo(@"%@ \t WAL file size: %@", self.logTag, [OWSFileSystem fileSizeOfPath:self.legacyDatabaseFilePath_WAL]);
// The old database location was in the Document directory, // The old database location was in the Document directory,
// so protect the database files individually. // so protect the database files individually.
[OWSFileSystem protectFileOrFolderAtPath:self.legacyDatabaseFilePath]; [OWSFileSystem protectFileOrFolderAtPath:self.legacyDatabaseFilePath];

@ -35,6 +35,8 @@ NS_ASSUME_NONNULL_BEGIN
// Returns nil on failure. // Returns nil on failure.
+ (nullable NSString *)writeDataToTemporaryFile:(NSData *)data fileExtension:(NSString *_Nullable)fileExtension; + (nullable NSString *)writeDataToTemporaryFile:(NSData *)data fileExtension:(NSString *_Nullable)fileExtension;
+ (nullable NSNumber *)fileSizeOfPath:(NSString *)filePath;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

@ -200,6 +200,20 @@ NS_ASSUME_NONNULL_BEGIN
return tempFilePath; return tempFilePath;
} }
+ (nullable NSNumber *)fileSizeOfPath:(NSString *)filePath
{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *_Nullable error;
unsigned long long fileSize =
[[fileManager attributesOfItemAtPath:filePath error:&error][NSFileSize] unsignedLongLongValue];
if (error) {
DDLogError(@"%@ Couldn't fetch file size[%@]: %@", self.logTag, filePath, error);
return nil;
} else {
return @(fileSize);
}
}
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

Loading…
Cancel
Save