Skip to content
Snippets Groups Projects
Unverified Commit 90581125 authored by Matthias Urhahn's avatar Matthias Urhahn Committed by GitHub
Browse files

For data consistency, the test repo processes actions sequentially. (#2999)


If we have a blocking operations (network refresh), the UI could queue up multiple test removals.
The first one would work, the following would throw an exception.
We should handle this silently for users of `SubmissionRepository`

Co-authored-by: default avatarI502720 <axel.herbstreith@sap.com>
parent 59bd0bd8
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,7 @@ package de.rki.coronawarnapp.coronatest
import androidx.annotation.VisibleForTesting
import de.rki.coronawarnapp.bugreporting.reportProblem
import de.rki.coronawarnapp.coronatest.errors.CoronaTestNotFoundException
import de.rki.coronawarnapp.coronatest.migration.PCRTestMigration
import de.rki.coronawarnapp.coronatest.qrcode.CoronaTestGUID
import de.rki.coronawarnapp.coronatest.qrcode.CoronaTestQRCode
......@@ -123,7 +124,7 @@ class CoronaTestRepository @Inject constructor(
internalData.updateBlocking {
val toBeRemoved = values.singleOrNull { it.identifier == identifier }
?: throw IllegalArgumentException("No found for $identifier")
?: throw CoronaTestNotFoundException("No found for $identifier")
getProcessor(toBeRemoved.type).onRemove(toBeRemoved)
......@@ -236,7 +237,7 @@ class CoronaTestRepository @Inject constructor(
) {
internalData.updateBlocking {
val original = values.singleOrNull { it.identifier == identifier }
?: throw IllegalArgumentException("No found for $identifier")
?: throw CoronaTestNotFoundException("No test found for $identifier")
val processor = getProcessor(original.type)
......
package de.rki.coronawarnapp.coronatest.errors
class CoronaTestNotFoundException(
message: String
) : IllegalArgumentException(message)
......@@ -2,6 +2,7 @@ package de.rki.coronawarnapp.submission
import de.rki.coronawarnapp.coronatest.CoronaTestRepository
import de.rki.coronawarnapp.coronatest.TestRegistrationRequest
import de.rki.coronawarnapp.coronatest.errors.CoronaTestNotFoundException
import de.rki.coronawarnapp.coronatest.server.CoronaTestResult
import de.rki.coronawarnapp.coronatest.type.CoronaTest
import de.rki.coronawarnapp.coronatest.type.pcr.PCRCoronaTest
......@@ -101,9 +102,15 @@ class SubmissionRepository @Inject constructor(
scope.launch {
val test = coronaTestRepository.coronaTests.first().singleOrNull { it.type == type }
?: throw IllegalStateException("No test of type $type available")
coronaTestRepository.removeTest(identifier = test.identifier)
if (test == null) {
Timber.tag(TAG).w("There is no test of type=$type to remove.")
return@launch
}
try {
coronaTestRepository.removeTest(identifier = test.identifier)
} catch (e: CoronaTestNotFoundException) {
Timber.tag(TAG).e(e, "Test not found (type=$type), already removed?")
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment