// // Copyright (c) 2021 Open Whisper Systems. All rights reserved. // import Foundation import XCTest import SignalServiceKit class ThreadFinderPerformanceTest: PerformanceBaseTest { func testPerf_enumerateVisibleThreads() { measureMetrics(XCTestCase.defaultPerformanceMetrics, automaticallyStartMeasuring: false) { enumerateVisibleThreads(isArchived: false) } } func testPerf_enumerateVisibleThreads_isArchived() { measureMetrics(XCTestCase.defaultPerformanceMetrics, automaticallyStartMeasuring: false) { enumerateVisibleThreads(isArchived: true) } } func enumerateVisibleThreads(isArchived: Bool) { // To properly stress GRDB, we want a large number // of threads with a large number of messages. // // NOTE: the total thread count is 4 x threadCount. let threadCount = DebugFlags.fastPerfTests ? 5 : 100 var emptyThreads = [TSThread]() var hasMessageThreads = [TSThread]() var archivedThreads = [TSThread]() var unarchivedThreads = [TSThread]() for _ in 0.. [TSThread] { var result = [TSThread]() for _ in 0.. TSThread { // .empty let contactThread = ContactThreadFactory().create() XCTAssertFalse(contactThread.shouldThreadBeVisible) if threadType == .empty { return contactThread } // .hasMessage let messageFactory = OutgoingMessageFactory() messageFactory.threadCreator = { _ in return contactThread } write { transaction in if let latestThread = TSThread.anyFetch(uniqueId: contactThread.uniqueId, transaction: transaction) { XCTAssertFalse(latestThread.shouldThreadBeVisible) XCTAssertFalse(ThreadAssociatedData.fetchOrDefault(for: latestThread, transaction: transaction).isArchived) } else { XCTFail("Missing thread.") } for _ in 0..