Signal-iOS/Signal/test/PerformanceTests/InteractionFinderPerformanceTests.swift
2022-05-26 10:44:43 -04:00

47 lines
1.8 KiB
Swift

//
// Copyright (c) 2022 Open Whisper Systems. All rights reserved.
//
@testable import SignalServiceKit
import Foundation
class InteractionFinderPerformanceTests: PerformanceBaseTest {
func testPerf_getAppBadgeCount() {
measureMetrics(XCTestCase.defaultPerformanceMetrics, automaticallyStartMeasuring: false) {
let nThreads = UInt(200)
let nMessagesPerThread = UInt(10)
simulateIncomingMessages(inThreads: nThreads, messagesPerThread: nMessagesPerThread)
startMeasuring()
read { transaction in
let unreadCount = InteractionFinder.unreadCountInAllThreads(transaction: transaction.unwrapGrdbRead)
XCTAssertEqual(unreadCount, nThreads * nMessagesPerThread)
}
stopMeasuring()
// Clear DB for next iteration, otherwise unfair to compare across iterations as DB grows
write { transaction in
TSThread.anyRemoveAllWithInstantation(transaction: transaction)
TSMessage.anyRemoveAllWithInstantation(transaction: transaction)
TSInteraction.anyRemoveAllWithInstantation(transaction: transaction)
}
}
}
private func simulateIncomingMessages(inThreads threadCount: UInt, messagesPerThread: UInt) {
write { transaction in
let threadFactory = ContactThreadFactory()
let threads = threadFactory.create(count: threadCount, transaction: transaction)
for thread in threads {
let messageFactory = IncomingMessageFactory()
messageFactory.threadCreator = { _ in return thread }
_ = messageFactory.create(count: messagesPerThread, transaction: transaction)
}
}
}
}