109 lines
3.4 KiB
Swift
109 lines
3.4 KiB
Swift
//
|
|
// Copyright (c) 2021 Open Whisper Systems. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
import XCTest
|
|
import SignalServiceKit
|
|
import SignalClient
|
|
|
|
class SessionMigrationPerfTest: PerformanceBaseTest {
|
|
static let newlyInitializedSessionStateData: Data = {
|
|
let dataURL = Bundle(for: SessionMigrationPerfTest.self).url(forResource: "newlyInitializedSessionState",
|
|
withExtension: "")!
|
|
return try! Data(contentsOf: dataURL)
|
|
}()
|
|
|
|
static func makeNewlyInitializedSessionState() -> LegacySessionState {
|
|
let result = try! NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(Self.newlyInitializedSessionStateData)
|
|
return result as! LegacySessionState
|
|
}
|
|
|
|
func makeDeepSession(depth: Int = 2000) -> LegacySessionRecord {
|
|
let session = LegacySessionRecord()!
|
|
|
|
for _ in 1...5 {
|
|
session.archiveCurrentState()
|
|
|
|
let state = Self.makeNewlyInitializedSessionState()
|
|
session.setState(state)
|
|
|
|
state.receivingChains = (1...5).map { _ in
|
|
let senderRatchetKey = Curve25519.generateKeyPair().publicKey
|
|
let chain = LegacyReceivingChain(chainKey: LegacyChainKey(data: senderRatchetKey, index: 0),
|
|
senderRatchetKey: senderRatchetKey)!
|
|
let dummyKeys = LegacyMessageKeys(cipherKey: Data(repeating: 1, count: 32),
|
|
macKey: Data(repeating: 2, count: 32),
|
|
iv: Data(repeating: 3, count: 16),
|
|
index: 0)!
|
|
chain.messageKeysList.addObjects(from: Array(repeating: dummyKeys, count: depth))
|
|
return chain
|
|
}
|
|
}
|
|
|
|
return session
|
|
}
|
|
|
|
func testSerializeDeepSession() {
|
|
let x = makeDeepSession()
|
|
measure {
|
|
_ = try! x.serializeProto()
|
|
}
|
|
}
|
|
|
|
func testDeserializeDeepSession() {
|
|
let x = makeDeepSession()
|
|
let data = try! x.serializeProto()
|
|
measure {
|
|
_ = try! LegacySessionRecord(serializedProto: data)
|
|
}
|
|
}
|
|
|
|
func testUnarchiveDeepSession() {
|
|
let x = makeDeepSession()
|
|
let data = NSKeyedArchiver.archivedData(withRootObject: x)
|
|
measure {
|
|
_ = NSKeyedUnarchiver.unarchiveObject(with: data)
|
|
}
|
|
}
|
|
|
|
func testMigrateDeepSession() {
|
|
let x = makeDeepSession()
|
|
let data = try! x.serializeProto()
|
|
measure {
|
|
_ = try! SessionRecord(bytes: data)
|
|
}
|
|
}
|
|
|
|
func testSerializeSomewhatDeepSession() {
|
|
let x = makeDeepSession(depth: 200)
|
|
measure {
|
|
_ = try! x.serializeProto()
|
|
}
|
|
}
|
|
|
|
func testDeserializeSomewhatDeepSession() {
|
|
let x = makeDeepSession(depth: 200)
|
|
let data = try! x.serializeProto()
|
|
measure {
|
|
_ = try! LegacySessionRecord(serializedProto: data)
|
|
}
|
|
}
|
|
|
|
func testUnarchiveSomewhatDeepSession() {
|
|
let x = makeDeepSession(depth: 200)
|
|
let data = NSKeyedArchiver.archivedData(withRootObject: x)
|
|
measure {
|
|
_ = NSKeyedUnarchiver.unarchiveObject(with: data)
|
|
}
|
|
}
|
|
|
|
func testMigrateSomewhatDeepSession() {
|
|
let x = makeDeepSession(depth: 200)
|
|
let data = try! x.serializeProto()
|
|
measure {
|
|
_ = try! SessionRecord(bytes: data)
|
|
}
|
|
}
|
|
}
|