Restrict Checker.concurrencyLimit to 3 when backend requires network

This commit is contained in:
Torsten Grote 2024-10-29 15:42:56 -03:00
parent 166f81b3a8
commit 45d710270a
No known key found for this signature in database
GPG key ID: 3E5F77D92CF891FF
3 changed files with 8 additions and 2 deletions

View file

@ -43,6 +43,7 @@ class BackendManager(
return mBackendProperties return mBackendProperties
} }
val isOnRemovableDrive: Boolean get() = backendProperties?.isUsb == true val isOnRemovableDrive: Boolean get() = backendProperties?.isUsb == true
val requiresNetwork: Boolean get() = backendProperties?.requiresNetwork == true
init { init {
when (settingsManager.storagePluginType) { when (settingsManager.storagePluginType) {

View file

@ -42,8 +42,8 @@ internal class Checker(
private var snapshots: List<Snapshot>? = null private var snapshots: List<Snapshot>? = null
private val concurrencyLimit: Int private val concurrencyLimit: Int
get() { get() {
// TODO determine also based on backendManager val maxConcurrent = if (backendManager.requiresNetwork) 3 else 42
return Runtime.getRuntime().availableProcessors() return min(Runtime.getRuntime().availableProcessors(), maxConcurrent)
} }
var checkerResult: CheckerResult? = null var checkerResult: CheckerResult? = null
private set private set

View file

@ -86,6 +86,7 @@ internal class CheckerTest : TransportTest() {
fun `check works even with no backup data`() = runBlocking { fun `check works even with no backup data`() = runBlocking {
expectLoadingSnapshots(emptyMap()) expectLoadingSnapshots(emptyMap())
every { backendManager.requiresNetwork } returns Random.nextBoolean()
every { nm.onCheckFinishedWithError(0, 0) } just Runs every { nm.onCheckFinishedWithError(0, 0) } just Runs
assertNull(checker.checkerResult) assertNull(checker.checkerResult)
@ -121,6 +122,7 @@ internal class CheckerTest : TransportTest() {
snapshotHandle2 to snapshot.copy { token = 2 }, snapshotHandle2 to snapshot.copy { token = 2 },
) )
expectLoadingSnapshots(snapshotMap) expectLoadingSnapshots(snapshotMap)
every { backendManager.requiresNetwork } returns Random.nextBoolean()
val data = ByteArray(0) val data = ByteArray(0)
coEvery { loader.loadFile(blobHandle1, null) } returns ByteArrayInputStream(data) coEvery { loader.loadFile(blobHandle1, null) } returns ByteArrayInputStream(data)
@ -172,6 +174,7 @@ internal class CheckerTest : TransportTest() {
}, },
) )
expectLoadingSnapshots(snapshotMap) expectLoadingSnapshots(snapshotMap)
every { backendManager.requiresNetwork } returns Random.nextBoolean()
coEvery { loader.loadFile(blobHandle1, null) } returns ByteArrayInputStream(data1) coEvery { loader.loadFile(blobHandle1, null) } returns ByteArrayInputStream(data1)
coEvery { loader.loadFile(blobHandle2, null) } throws GeneralSecurityException() coEvery { loader.loadFile(blobHandle2, null) } throws GeneralSecurityException()
@ -220,6 +223,7 @@ internal class CheckerTest : TransportTest() {
val expectedSize = blob1.length.toLong() + blob2.length.toLong() val expectedSize = blob1.length.toLong() + blob2.length.toLong()
expectLoadingSnapshots(snapshotMap) expectLoadingSnapshots(snapshotMap)
every { backendManager.requiresNetwork } returns Random.nextBoolean()
coEvery { loader.loadFile(blobHandle1, null) } returns ByteArrayInputStream(data1) coEvery { loader.loadFile(blobHandle1, null) } returns ByteArrayInputStream(data1)
coEvery { loader.loadFile(blobHandle2, null) } returns ByteArrayInputStream(data2) coEvery { loader.loadFile(blobHandle2, null) } returns ByteArrayInputStream(data2)
@ -257,6 +261,7 @@ internal class CheckerTest : TransportTest() {
}, },
) )
expectLoadingSnapshots(snapshotMap) expectLoadingSnapshots(snapshotMap)
every { backendManager.requiresNetwork } returns Random.nextBoolean()
// only loading app data, not other blobs // only loading app data, not other blobs
coEvery { loader.loadFile(appDataBlobHandle1, null) } throws SecurityException() coEvery { loader.loadFile(appDataBlobHandle1, null) } throws SecurityException()