From bfc1445675bb67cd828a701f351be5ad0c5f3797 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Tue, 28 Nov 2017 13:01:47 -0500 Subject: [PATCH 1/2] 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) { From 40b2ecf580cb06558833df5293c489e4aad27b3a Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Tue, 28 Nov 2017 14:44:57 -0500 Subject: [PATCH 2/2] Add debug UI for hallucinating lots of large attachments to stress shared data migration. --- Signal/src/ViewControllers/DebugUI/DebugUIMessages.m | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m b/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m index 1c230fd42..0110c41e2 100644 --- a/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m +++ b/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m @@ -140,6 +140,14 @@ NS_ASSUME_NONNULL_BEGIN actionBlock:^{ [DebugUIMessages createFakeLargeOutgoingAttachments:100 thread:thread]; }], + [OWSTableItem itemWithTitle:@"Create 1k fake large attachments" + actionBlock:^{ + [DebugUIMessages createFakeLargeOutgoingAttachments:1000 thread:thread]; + }], + [OWSTableItem itemWithTitle:@"Create 10k fake large attachments" + actionBlock:^{ + [DebugUIMessages createFakeLargeOutgoingAttachments:10000 thread:thread]; + }], [OWSTableItem itemWithTitle:@"Send text/x-signal-plain" actionBlock:^{ [DebugUIMessages sendOversizeTextMessage:thread]; @@ -1072,10 +1080,11 @@ NS_ASSUME_NONNULL_BEGIN if (filename) { message.attachmentFilenameMap[attachmentStream.uniqueId] = filename; } + [message updateWithMessageState:TSOutgoingMessageStateUnsent transaction:transaction]; [message saveWithTransaction:transaction]; }]; - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)1.f * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ [self createFakeLargeOutgoingAttachments:counter - 1 thread:thread]; }); }