mirror of
https://github.com/austinried/subtracks.git
synced 2026-11-10 23:21:59 +01:00
address the second offline review: cancel guard, bounded reconcile
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user