From bfc1445675bb67cd828a701f351be5ad0c5f3797 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Tue, 28 Nov 2017 13:01:47 -0500 Subject: [PATCH] Add debug UI for hallucinating lots of large attachments to stress shared data migration. --- .../ViewControllers/DebugUI/DebugUIMessages.m | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m b/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m index 499878b50..1c230fd42 100644 --- a/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m +++ b/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m @@ -132,6 +132,14 @@ NS_ASSUME_NONNULL_BEGIN actionBlock:^{ [DebugUIMessages createFakeUnreadMessages:10 thread:thread]; }], + [OWSTableItem itemWithTitle:@"Create 10 fake large attachments" + actionBlock:^{ + [DebugUIMessages createFakeLargeOutgoingAttachments:10 thread:thread]; + }], + [OWSTableItem itemWithTitle:@"Create 100 fake large attachments" + actionBlock:^{ + [DebugUIMessages createFakeLargeOutgoingAttachments:100 thread:thread]; + }], [OWSTableItem itemWithTitle:@"Send text/x-signal-plain" actionBlock:^{ [DebugUIMessages sendOversizeTextMessage:thread]; @@ -1035,6 +1043,43 @@ NS_ASSUME_NONNULL_BEGIN } } ++ (void)createFakeLargeOutgoingAttachments:(int)counter thread:(TSThread *)thread +{ + if (counter < 1) { + return; + } + + [TSStorageManager.sharedManager.dbReadWriteConnection readWriteWithBlock:^( + YapDatabaseReadWriteTransaction *transaction) { + TSOutgoingMessage *message = [[TSOutgoingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp] + inThread:thread + isVoiceMessage:NO + expiresInSeconds:0]; + DDLogError(@"%@ sendFakeMessages outgoing attachment timestamp: %llu.", self.logTag, message.timestamp); + + NSString *filename = @"test.mp3"; + UInt32 filesize = 8 * 1024 * 1024; + + TSAttachmentStream *attachmentStream = + [[TSAttachmentStream alloc] initWithContentType:@"audio/mp3" byteCount:filesize sourceFilename:filename]; + + NSError *error; + BOOL success = [attachmentStream writeData:[self createRandomNSDataOfSize:filesize] error:&error]; + OWSAssert(success && !error); + + [attachmentStream saveWithTransaction:transaction]; + [message.attachmentIds addObject:attachmentStream.uniqueId]; + if (filename) { + message.attachmentFilenameMap[attachmentStream.uniqueId] = filename; + } + [message saveWithTransaction:transaction]; + }]; + + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)1.f * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ + [self createFakeLargeOutgoingAttachments:counter - 1 thread:thread]; + }); +} + + (void)sendTinyAttachments:(int)counter thread:(TSThread *)thread { if (counter < 1) {