mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-20 19:18:37 +00:00
Fix bug related to in-memory jobs not being prioritized properly.
This commit is contained in:
committed by
jeffrey-signal
parent
9ed921f58c
commit
c25ce2bcdd
@@ -356,10 +356,15 @@ class FastJobStorage(private val jobDatabase: JobDatabase) : JobStorage {
|
|||||||
mostEligibleJobForQueue.keys.removeAll(affectedQueues)
|
mostEligibleJobForQueue.keys.removeAll(affectedQueues)
|
||||||
|
|
||||||
for (queue in affectedQueues) {
|
for (queue in affectedQueues) {
|
||||||
jobDatabase.getMostEligibleJobInQueue(queue)?.let {
|
minimalJobs
|
||||||
jobSpecCache[it.id] = it
|
.filter { it.queueKey == queue }
|
||||||
placeJobInEligibleList(it.toMinimalJobSpec())
|
.minWithOrNull(
|
||||||
}
|
compareByDescending<MinimalJobSpec> { it.globalPriority }
|
||||||
|
.thenByDescending { it.queuePriority }
|
||||||
|
.thenBy { it.createTime }
|
||||||
|
.thenBy { it.id }
|
||||||
|
)
|
||||||
|
?.let { placeJobInEligibleList(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
for (jobId in ids) {
|
for (jobId in ids) {
|
||||||
|
|||||||
@@ -863,6 +863,28 @@ class FastJobStorageTest {
|
|||||||
verify(exactly = 0) { database.deleteJobs(ids) }
|
verify(exactly = 0) { database.deleteJobs(ids) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `deleteJobs - memory-only job remains in mostEligibleJobForQueue after deleting other job in same queue`() {
|
||||||
|
// This test targets a case where we weren't handling in-memory jobs when calculating mostEligiibleForJobQueue after a deletion
|
||||||
|
val memoryJob = fullSpec(id = "memory-job", factoryKey = "f1", queueKey = "q1", isMemoryOnly = true, globalPriority = 10)
|
||||||
|
val durableJob = fullSpec(id = "durable-job", factoryKey = "f2", queueKey = "q1", isMemoryOnly = false, globalPriority = 5)
|
||||||
|
|
||||||
|
val database = mockDatabase(listOf(memoryJob, durableJob))
|
||||||
|
val subject = FastJobStorage(database)
|
||||||
|
subject.init()
|
||||||
|
|
||||||
|
// Verify memory job is initially the most eligible
|
||||||
|
val initialNext = subject.getNextEligibleJob(System.currentTimeMillis(), NO_PREDICATE)
|
||||||
|
assertThat(initialNext).isNotNull().prop(JobSpec::id).isEqualTo("memory-job")
|
||||||
|
|
||||||
|
// Delete the durable job
|
||||||
|
subject.deleteJobs(listOf("durable-job"))
|
||||||
|
|
||||||
|
// The memory job should still be available as the most eligible
|
||||||
|
val afterDelete = subject.getNextEligibleJob(System.currentTimeMillis(), NO_PREDICATE)
|
||||||
|
assertThat(afterDelete).isNotNull().prop(JobSpec::id).isEqualTo("memory-job")
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `deleteJobs - deletes all relevant pieces`() {
|
fun `deleteJobs - deletes all relevant pieces`() {
|
||||||
val subject = FastJobStorage(mockDatabase(DataSet1.FULL_SPECS))
|
val subject = FastJobStorage(mockDatabase(DataSet1.FULL_SPECS))
|
||||||
@@ -1439,8 +1461,8 @@ class FastJobStorageTest {
|
|||||||
return mock
|
return mock
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun fullSpec(id: String, factoryKey: String, queueKey: String? = null): FullSpec {
|
private fun fullSpec(id: String, factoryKey: String, queueKey: String? = null, isMemoryOnly: Boolean = false, globalPriority: Int = 0): FullSpec {
|
||||||
return FullSpec(jobSpec(id, factoryKey, queueKey), emptyList(), emptyList())
|
return FullSpec(jobSpec(id, factoryKey, queueKey, isMemoryOnly = isMemoryOnly, globalPriority = globalPriority), emptyList(), emptyList())
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun jobSpec(
|
private fun jobSpec(
|
||||||
|
|||||||
Reference in New Issue
Block a user