Fixed some broken tests and removed remaining remnants of the 'syncExpiries' job

pull/941/head
Morgan Pretty 2 years ago
parent 5e3dd3c731
commit 593acd8e37

@ -51,6 +51,7 @@ public struct Contact: Codable, Identifiable, Equatable, FetchableRecord, Persis
// MARK: - Initialization // MARK: - Initialization
public init( public init(
_ db: Database? = nil,
id: String, id: String,
isTrusted: Bool = false, isTrusted: Bool = false,
isApproved: Bool = false, isApproved: Bool = false,
@ -62,7 +63,7 @@ public struct Contact: Codable, Identifiable, Equatable, FetchableRecord, Persis
self.id = id self.id = id
self.isTrusted = ( self.isTrusted = (
isTrusted || isTrusted ||
id == getUserHexEncodedPublicKey() // Always trust ourselves id == getUserHexEncodedPublicKey(db) // Always trust ourselves
) )
self.isApproved = isApproved self.isApproved = isApproved
self.isBlocked = isBlocked self.isBlocked = isBlocked
@ -105,7 +106,7 @@ public extension Contact {
/// **Note:** This method intentionally does **not** save the newly created Contact, /// **Note:** This method intentionally does **not** save the newly created Contact,
/// it will need to be explicitly saved after calling /// it will need to be explicitly saved after calling
static func fetchOrCreate(_ db: Database, id: ID) -> Contact { static func fetchOrCreate(_ db: Database, id: ID) -> Contact {
return ((try? fetchOne(db, id: id)) ?? Contact(id: id)) return ((try? fetchOne(db, id: id)) ?? Contact(db, id: id))
} }
} }

@ -234,7 +234,9 @@ class OpenGroupManagerSpec: QuickSpec {
mockGeneralCache.when { $0.encodedPublicKey }.thenReturn("05\(TestConstants.publicKey)") mockGeneralCache.when { $0.encodedPublicKey }.thenReturn("05\(TestConstants.publicKey)")
mockGenericHash.when { $0.hash(message: anyArray(), outputLength: any()) }.thenReturn([]) mockGenericHash.when { $0.hash(message: anyArray(), outputLength: any()) }.thenReturn([])
mockSodium mockSodium
.when { $0.blindedKeyPair(serverPublicKey: any(), edKeyPair: any(), genericHash: mockGenericHash) } .when { [mockGenericHash] mock in
mock.blindedKeyPair(serverPublicKey: any(), edKeyPair: any(), genericHash: mockGenericHash!)
}
.thenReturn( .thenReturn(
Box.KeyPair( Box.KeyPair(
publicKey: Data.data(fromHex: TestConstants.publicKey)!.bytes, publicKey: Data.data(fromHex: TestConstants.publicKey)!.bytes,
@ -3568,11 +3570,11 @@ class OpenGroupManagerSpec: QuickSpec {
it("adds the image retrieval promise to the cache") { it("adds the image retrieval promise to the cache") {
class TestNeverReturningApi: OnionRequestAPIType { class TestNeverReturningApi: OnionRequestAPIType {
static func sendOnionRequest(_ request: URLRequest, to server: String, using version: OnionRequestAPIVersion, with x25519PublicKey: String) -> Promise<(OnionRequestResponseInfoType, Data?)> { static func sendOnionRequest(_ request: URLRequest, to server: String, using version: OnionRequestAPIVersion, with x25519PublicKey: String, timeout: TimeInterval) -> Promise<(OnionRequestResponseInfoType, Data?)> {
return Promise<(OnionRequestResponseInfoType, Data?)>.pending().promise return Promise<(OnionRequestResponseInfoType, Data?)>.pending().promise
} }
static func sendOnionRequest(to snode: Snode, invoking method: SnodeAPIEndpoint, with parameters: JSON, associatedWith publicKey: String?) -> Promise<Data> { static func sendOnionRequest(to snode: Snode, invoking method: SnodeAPIEndpoint, with parameters: JSON, associatedWith publicKey: String?, timeout: TimeInterval) -> Promise<Data> {
return Promise.value(Data()) return Promise.value(Data())
} }
} }

@ -34,7 +34,7 @@ class TestOnionRequestAPI: OnionRequestAPIType {
class var mockResponse: Data? { return nil } class var mockResponse: Data? { return nil }
static func sendOnionRequest(_ request: URLRequest, to server: String, using version: OnionRequestAPIVersion, with x25519PublicKey: String) -> Promise<(OnionRequestResponseInfoType, Data?)> { static func sendOnionRequest(_ request: URLRequest, to server: String, using version: OnionRequestAPIVersion, with x25519PublicKey: String, timeout: TimeInterval) -> Promise<(OnionRequestResponseInfoType, Data?)> {
let responseInfo: ResponseInfo = ResponseInfo( let responseInfo: ResponseInfo = ResponseInfo(
requestData: RequestData( requestData: RequestData(
urlString: request.url?.absoluteString, urlString: request.url?.absoluteString,
@ -54,7 +54,7 @@ class TestOnionRequestAPI: OnionRequestAPIType {
return Promise.value((responseInfo, mockResponse)) return Promise.value((responseInfo, mockResponse))
} }
static func sendOnionRequest(to snode: Snode, invoking method: SnodeAPIEndpoint, with parameters: JSON, associatedWith publicKey: String?) -> Promise<Data> { static func sendOnionRequest(to snode: Snode, invoking method: SnodeAPIEndpoint, with parameters: JSON, associatedWith publicKey: String?, timeout: TimeInterval) -> Promise<Data> {
return Promise.value(mockResponse!) return Promise.value(mockResponse!)
} }
} }

@ -92,7 +92,9 @@ class ThreadDisappearingMessagesViewModelSpec: QuickSpec {
title: "DISAPPEARING_MESSAGES_OFF".localized(), title: "DISAPPEARING_MESSAGES_OFF".localized(),
rightAccessory: .radio( rightAccessory: .radio(
isSelected: { true } isSelected: { true }
) ),
accessibilityIdentifier: "Off option",
accessibilityLabel: "Off option"
) )
) )
) )
@ -138,7 +140,9 @@ class ThreadDisappearingMessagesViewModelSpec: QuickSpec {
title: "DISAPPEARING_MESSAGES_OFF".localized(), title: "DISAPPEARING_MESSAGES_OFF".localized(),
rightAccessory: .radio( rightAccessory: .radio(
isSelected: { false } isSelected: { false }
) ),
accessibilityIdentifier: "Off option",
accessibilityLabel: "Off option"
) )
) )
) )
@ -173,7 +177,9 @@ class ThreadDisappearingMessagesViewModelSpec: QuickSpec {
title: title, title: title,
rightAccessory: .radio( rightAccessory: .radio(
isSelected: { true } isSelected: { true }
) ),
accessibilityIdentifier: "Time option",
accessibilityLabel: "Time option"
) )
) )
) )
@ -192,7 +198,7 @@ class ThreadDisappearingMessagesViewModelSpec: QuickSpec {
) )
) )
expect(footerButtonInfo).to(equal(nil)) expect(footerButtonInfo).to(beNil())
} }
context("when changed from the previous setting") { context("when changed from the previous setting") {

@ -228,7 +228,7 @@ class ThreadSettingsViewModelSpec: QuickSpec {
ParentType.NavItem( ParentType.NavItem(
id: .cancel, id: .cancel,
systemItem: .cancel, systemItem: .cancel,
accessibilityIdentifier: "Cancel" accessibilityIdentifier: "Cancel button"
) )
])) ]))
expect(viewModel.rightNavItems.firstValue()) expect(viewModel.rightNavItems.firstValue())

@ -106,10 +106,6 @@ public struct Job: Codable, Equatable, Hashable, Identifiable, FetchableRecord,
/// This is a job that runs once whenever the user leaves a group to send a group leaving message, remove group /// This is a job that runs once whenever the user leaves a group to send a group leaving message, remove group
/// record and group member record /// record and group member record
case groupLeaving case groupLeaving
/// This is a job that runs once whenever some disappearing messages is read and started the timer to inform
/// linked devices and the network for the change of the messages's ttl
case syncExpires
} }
public enum Behaviour: Int, Codable, DatabaseValueConvertible, CaseIterable { public enum Behaviour: Int, Codable, DatabaseValueConvertible, CaseIterable {

@ -267,7 +267,7 @@ open class Storage {
// after device restart until device is unlocked for the first time. If the app receives a push // after device restart until device is unlocked for the first time. If the app receives a push
// notification, we won't be able to access the keychain to process that notification, so we should // notification, we won't be able to access the keychain to process that notification, so we should
// just terminate by throwing an uncaught exception // just terminate by throwing an uncaught exception
if CurrentAppContext().isMainApp || CurrentAppContext().isInBackground() { if HasAppContext() && (CurrentAppContext().isMainApp || CurrentAppContext().isInBackground()) {
let appState: UIApplication.State = CurrentAppContext().reportedApplicationState let appState: UIApplication.State = CurrentAppContext().reportedApplicationState
// In this case we should have already detected the situation earlier and exited gracefully (in the // In this case we should have already detected the situation earlier and exited gracefully (in the

@ -90,14 +90,6 @@ public final class JobRunner {
jobVariants.remove(.attachmentDownload) jobVariants.remove(.attachmentDownload)
].compactMap { $0 } ].compactMap { $0 }
) )
let syncExpiriesQueue: JobQueue = JobQueue(
type: .syncExpiries,
executionType: .concurrent, // Allow as many jobs to run at once as supported by the device
qos: .default,
jobVariants: [
jobVariants.remove(.syncExpires)
].compactMap { $0 }
)
let generalQueue: JobQueue = JobQueue( let generalQueue: JobQueue = JobQueue(
type: .general(number: 0), type: .general(number: 0),
qos: .utility, qos: .utility,
@ -108,7 +100,6 @@ public final class JobRunner {
messageSendQueue, messageSendQueue,
messageReceiveQueue, messageReceiveQueue,
attachmentDownloadQueue, attachmentDownloadQueue,
syncExpiriesQueue,
generalQueue generalQueue
].reduce(into: [:]) { prev, next in ].reduce(into: [:]) { prev, next in
next.jobVariants.forEach { variant in next.jobVariants.forEach { variant in
@ -417,7 +408,6 @@ private final class JobQueue {
case messageSend case messageSend
case messageReceive case messageReceive
case attachmentDownload case attachmentDownload
case syncExpiries
var name: String { var name: String {
switch self { switch self {
@ -426,7 +416,6 @@ private final class JobQueue {
case .messageSend: return "MessageSend" case .messageSend: return "MessageSend"
case .messageReceive: return "MessageReceive" case .messageReceive: return "MessageReceive"
case .attachmentDownload: return "AttachmentDownload" case .attachmentDownload: return "AttachmentDownload"
case .syncExpiries: return "SyncExpiries"
} }
} }
} }

Loading…
Cancel
Save