From b451d1ac04e153ed9a4b970f34714d1bc7491140 Mon Sep 17 00:00:00 2001 From: Morgan Pretty Date: Tue, 20 Aug 2024 11:17:05 +1000 Subject: [PATCH] Added code to defer the CheckForAppUpdatesJob when running tests or sim --- .../Jobs/Types/CheckForAppUpdatesJob.swift | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/SessionMessagingKit/Jobs/Types/CheckForAppUpdatesJob.swift b/SessionMessagingKit/Jobs/Types/CheckForAppUpdatesJob.swift index b5f96a2a0..e60e095b1 100644 --- a/SessionMessagingKit/Jobs/Types/CheckForAppUpdatesJob.swift +++ b/SessionMessagingKit/Jobs/Types/CheckForAppUpdatesJob.swift @@ -19,6 +19,26 @@ public enum CheckForAppUpdatesJob: JobExecutor { deferred: @escaping (Job, Dependencies) -> (), using dependencies: Dependencies ) { + // Just defer the update check when running tests or in the simulator +#if targetEnvironment(simulator) + let shouldCheckForUpdates: Bool = false +#else + let shouldCheckForUpdates: Bool = !SNUtilitiesKit.isRunningTests +#endif + + guard shouldCheckForUpdates else { + var updatedJob: Job = job.with( + failureCount: 0, + nextRunTimestamp: (dependencies.dateNow.timeIntervalSince1970 + updateCheckFrequency) + ) + dependencies.storage.write(using: dependencies) { db in + try updatedJob.save(db) + } + + Log.info("[CheckForAppUpdatesJob] Deferred due to test/simulator build.") + return deferred(updatedJob, dependencies) + } + dependencies.storage .readPublisher(using: dependencies) { db -> [UInt8]? in Identity.fetchUserEd25519KeyPair(db)?.secretKey } .subscribe(on: queue)