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
}
val isOnRemovableDrive: Boolean get() = backendProperties?.isUsb == true
val requiresNetwork: Boolean get() = backendProperties?.requiresNetwork == true
init {
when (settingsManager.storagePluginType) {

View file

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

View file

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