address the second offline review: cancel guard, bounded reconcile

This commit is contained in:
austinried
2026-10-04 00:30:05 +00:00
parent 26e9b6cb27
commit f32c84bce7
12 changed files with 81 additions and 48 deletions
@@ -9,6 +9,7 @@ class FakeDownloadEngine : DownloadEngine {
var cancelCalls = 0
var enqueueDelayMs = 0L
var failEnqueueFor: String? = null
var failCancelOnEmpty = false
override fun enqueue(request: EngineRequest): Long {
if (enqueueDelayMs > 0) Thread.sleep(enqueueDelayMs)
@@ -23,6 +24,7 @@ class FakeDownloadEngine : DownloadEngine {
override fun download(id: Long): EngineDownload? = downloads[id]
override fun cancel(ids: List<Long>) {
if (ids.isEmpty() && failCancelOnEmpty) throw IllegalArgumentException("no ids")
cancelCalls++
cancelled += ids
}
@@ -362,6 +362,23 @@ class DownloadRepositoryTest {
assertTrue(engine.cancelled.isNotEmpty())
}
@Test
fun cancellingQueuedRowsWithoutEngineIdsLeavesTheEngineAlone() =
runTest {
seedLibrary()
runBlocking {
db.downloadDao().upsert(SongDownload(1, "s1", DownloadStatus.Queued))
db.downloadDao().upsert(SongDownload(1, "s2", DownloadStatus.Queued))
}
// DownloadManager.remove throws on an empty id list; a queue of only waiting rows has
// no engine ids, so cancelling must not call the engine at all.
engine.failCancelOnEmpty = true
runBlocking { repository.cancelActive() }
assertTrue(allRows().isEmpty())
}
@Test
fun theDownloadStartsBeforeItsArtworkIsFetched() =
runTest {
@@ -224,6 +224,7 @@ class SyncManagerTest {
"<song id=\"s1\" title=\"Song One\" albumId=\"al1\" artistId=\"ar1\" track=\"1\"/>" +
"</searchResult3></subsonic-response>"
}
@Test
fun aSyncRequestWhileOfflineIsRefusedWithoutTouchingTheNetwork() =
runBlocking {