From cb126a2f0831efb1fdfdb5f3b4cb6539a61f0b5a Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Mon, 9 Sep 2024 19:29:52 -0400 Subject: [PATCH] Fix runAttempt not updating in job cache. Thank you to @valldrac for finding this and diagnosing it! Fixes #13679 --- .../thoughtcrime/securesms/jobs/FastJobStorage.kt | 12 +++++++----- .../securesms/jobs/FastJobStorageTest.kt | 6 +++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobs/FastJobStorage.kt b/app/src/main/java/org/thoughtcrime/securesms/jobs/FastJobStorage.kt index 180fc72ae9..6c13c03cd5 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobs/FastJobStorage.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/jobs/FastJobStorage.kt @@ -200,12 +200,14 @@ class FastJobStorage(private val jobDatabase: JobDatabase) : JobStorage { if (job == null || !job.isMemoryOnly) { jobDatabase.updateJobAfterRetry(id, currentTime, runAttempt, nextBackoffInterval, serializedData) - // Note: All other fields are accounted for in the min spec. We only need to update from disk if serialized data changes. + // Note: Serialized data and run attempt are the only JobSpec-specific fields that need to be updated -- the rest are in MinimalJobSpec and will be + // updated below. val cached = jobSpecCache[id] - if (cached != null && !cached.serializedData.contentEquals(serializedData)) { - jobDatabase.getJobSpec(id)?.let { - jobSpecCache[id] = it - } + if (cached != null) { + jobSpecCache[id] = cached.copy( + serializedData = serializedData, + runAttempt = runAttempt + ) } } diff --git a/app/src/test/java/org/thoughtcrime/securesms/jobs/FastJobStorageTest.kt b/app/src/test/java/org/thoughtcrime/securesms/jobs/FastJobStorageTest.kt index 4363b8d618..f4fdef4a3f 100644 --- a/app/src/test/java/org/thoughtcrime/securesms/jobs/FastJobStorageTest.kt +++ b/app/src/test/java/org/thoughtcrime/securesms/jobs/FastJobStorageTest.kt @@ -298,7 +298,7 @@ class FastJobStorageTest { @Test fun `updateJobAfterRetry - state updated`() { - val fullSpec = FullSpec(jobSpec(id = "1", factoryKey = "f1", isRunning = true), emptyList(), emptyList()) + val fullSpec = FullSpec(jobSpec(id = "1", factoryKey = "f1", isRunning = true, serializedData = "a".toByteArray()), emptyList(), emptyList()) val subject = FastJobStorage(mockDatabase(listOf(fullSpec))) subject.init() @@ -306,7 +306,7 @@ class FastJobStorageTest { subject.updateJobAfterRetry( id = "1", currentTime = 3, - runAttempt = 1, + runAttempt = 2, nextBackoffInterval = 10, serializedData = "a".toByteArray() ) @@ -315,7 +315,7 @@ class FastJobStorageTest { check(job != null) job.isRunning assertIs false job.lastRunAttemptTime assertIs 3 - job.runAttempt assertIs 1 + job.runAttempt assertIs 2 job.nextBackoffInterval assertIs 10 job.serializedData!!.toString(Charset.defaultCharset()) assertIs "a" }