session-ios/_SharedTestUtilities/MockJobRunner.swift
Morgan Pretty a41f1c1366 Fixed the broken tests
Cleaned up the Dependencies so that tests can run synchronously without having to custom set queues as much
Sorted out the crypto and network dependencies to avoid needing weird dependency inheritance
Fixed the flaky tests so they are no longer flaky
Fixed some unexpected JobRunner behaviours
Updated the CI config to use a local build directory for derivedData (now works with build tweaks)
2023-08-01 14:27:41 +10:00

53 lines
1.7 KiB
Swift

// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
import Foundation
import GRDB
import SessionUtilitiesKit
@testable import SessionMessagingKit
class MockJobRunner: Mock<JobRunnerType>, JobRunnerType {
// MARK: - Configuration
func setExecutor(_ executor: JobExecutor.Type, for variant: Job.Variant) {
accept(args: [executor, variant])
}
func canStart(queue: JobQueue?) -> Bool {
return accept(args: [queue]) as! Bool
}
func afterBlockingQueue(callback: @escaping () -> ()) {
callback()
}
// MARK: - State Management
func jobInfoFor(jobs: [Job]?, state: JobRunner.JobState, variant: Job.Variant?) -> [Int64: JobRunner.JobInfo] {
return accept(args: [jobs, state, variant]) as! [Int64: JobRunner.JobInfo]
}
func appDidFinishLaunching(using dependencies: Dependencies) {}
func appDidBecomeActive(using dependencies: Dependencies) {}
func startNonBlockingQueues(using dependencies: Dependencies) {}
func stopAndClearPendingJobs(exceptForVariant: Job.Variant?, onComplete: (() -> ())?) {
accept(args: [exceptForVariant, onComplete])
onComplete?()
}
// MARK: - Job Scheduling
@discardableResult func add(_ db: Database, job: Job?, canStartJob: Bool, using dependencies: Dependencies) -> Job? {
return accept(args: [db, job, canStartJob]) as? Job
}
func upsert(_ db: Database, job: Job?, canStartJob: Bool, using dependencies: Dependencies) {
accept(args: [db, job, canStartJob])
}
func insert(_ db: Database, job: Job?, before otherJob: Job) -> (Int64, Job)? {
return accept(args: [db, job, otherJob]) as? (Int64, Job)
}
}