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

Adjust test availability constant (DEV) (#3085)


* Adjust test availability constant.
The server returns a different result after 60, not 21 days.

* Fix TAG copy paste error.

Co-authored-by: default avatarharambasicluka <64483219+harambasicluka@users.noreply.github.com>
parent 66dca0c0
No related branches found
No related tags found
No related merge requests found
Showing with 32 additions and 28 deletions
...@@ -6,6 +6,7 @@ import de.rki.coronawarnapp.util.PaddingTool.requestPadding ...@@ -6,6 +6,7 @@ import de.rki.coronawarnapp.util.PaddingTool.requestPadding
import de.rki.coronawarnapp.util.security.HashHelper import de.rki.coronawarnapp.util.security.HashHelper
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import org.joda.time.Duration
import timber.log.Timber import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
...@@ -114,6 +115,12 @@ class VerificationServer @Inject constructor( ...@@ -114,6 +115,12 @@ class VerificationServer @Inject constructor(
const val PADDING_LENGTH_BODY_TAN_FAKE = 31 + VERIFICATION_BODY_FILL const val PADDING_LENGTH_BODY_TAN_FAKE = 31 + VERIFICATION_BODY_FILL
const val DUMMY_REGISTRATION_TOKEN = "11111111-2222-4444-8888-161616161616" const val DUMMY_REGISTRATION_TOKEN = "11111111-2222-4444-8888-161616161616"
/**
* Test is available for this long on the server.
* After this period the server will delete it and return PENDING if the regtoken is polled again.
*/
val TEST_AVAILABLBILITY = Duration.standardDays(60)
private const val TAG = "VerificationServer" private const val TAG = "VerificationServer"
} }
} }
...@@ -14,6 +14,7 @@ import de.rki.coronawarnapp.coronatest.server.CoronaTestResult.RAT_NEGATIVE ...@@ -14,6 +14,7 @@ import de.rki.coronawarnapp.coronatest.server.CoronaTestResult.RAT_NEGATIVE
import de.rki.coronawarnapp.coronatest.server.CoronaTestResult.RAT_PENDING import de.rki.coronawarnapp.coronatest.server.CoronaTestResult.RAT_PENDING
import de.rki.coronawarnapp.coronatest.server.CoronaTestResult.RAT_POSITIVE import de.rki.coronawarnapp.coronatest.server.CoronaTestResult.RAT_POSITIVE
import de.rki.coronawarnapp.coronatest.server.CoronaTestResult.RAT_REDEEMED import de.rki.coronawarnapp.coronatest.server.CoronaTestResult.RAT_REDEEMED
import de.rki.coronawarnapp.coronatest.server.VerificationServer
import de.rki.coronawarnapp.coronatest.tan.CoronaTestTAN import de.rki.coronawarnapp.coronatest.tan.CoronaTestTAN
import de.rki.coronawarnapp.coronatest.type.CoronaTest import de.rki.coronawarnapp.coronatest.type.CoronaTest
import de.rki.coronawarnapp.coronatest.type.CoronaTestProcessor import de.rki.coronawarnapp.coronatest.type.CoronaTestProcessor
...@@ -26,7 +27,6 @@ import de.rki.coronawarnapp.exception.http.BadRequestException ...@@ -26,7 +27,6 @@ import de.rki.coronawarnapp.exception.http.BadRequestException
import de.rki.coronawarnapp.exception.http.CwaWebException import de.rki.coronawarnapp.exception.http.CwaWebException
import de.rki.coronawarnapp.exception.reporting.report import de.rki.coronawarnapp.exception.reporting.report
import de.rki.coronawarnapp.util.TimeStamper import de.rki.coronawarnapp.util.TimeStamper
import de.rki.coronawarnapp.worker.BackgroundConstants
import org.joda.time.Duration import org.joda.time.Duration
import org.joda.time.Instant import org.joda.time.Instant
import timber.log.Timber import timber.log.Timber
...@@ -139,7 +139,7 @@ class PCRProcessor @Inject constructor( ...@@ -139,7 +139,7 @@ class PCRProcessor @Inject constructor(
} }
test.copy( test.copy(
testResult = check21PlusDays(test, newTestResult), testResult = check60Days(test, newTestResult),
testResultReceivedAt = determineReceivedDate(test, newTestResult), testResultReceivedAt = determineReceivedDate(test, newTestResult),
lastUpdatedAt = nowUTC, lastUpdatedAt = nowUTC,
lastError = null lastError = null
...@@ -153,13 +153,13 @@ class PCRProcessor @Inject constructor( ...@@ -153,13 +153,13 @@ class PCRProcessor @Inject constructor(
} }
} }
// After 21 days, the previously EXPIRED test is deleted from the server, and it may return pending again. // After 60 days, the previously EXPIRED test is deleted from the server, and it may return pending again.
private fun check21PlusDays(test: CoronaTest, newResult: CoronaTestResult): CoronaTestResult { private fun check60Days(test: CoronaTest, newResult: CoronaTestResult): CoronaTestResult {
val calculateDays = Duration(test.registeredAt, timeStamper.nowUTC).standardDays val calculateDays = Duration(test.registeredAt, timeStamper.nowUTC)
Timber.tag(TAG).d("Calculated test age: %d days, newResult=%s", calculateDays, newResult) Timber.tag(TAG).d("Calculated test age: %d days, newResult=%s", calculateDays.standardDays, newResult)
return if (newResult == PCR_OR_RAT_PENDING && calculateDays >= BackgroundConstants.POLLING_VALIDITY_MAX_DAYS) { return if (newResult == PCR_OR_RAT_PENDING && calculateDays > VerificationServer.TEST_AVAILABLBILITY) {
Timber.tag(TAG).d("$calculateDays is exceeding the maximum polling duration") Timber.tag(TAG).d("$calculateDays is exceeding the test availability.")
PCR_REDEEMED PCR_REDEEMED
} else { } else {
newResult newResult
......
...@@ -13,6 +13,7 @@ import de.rki.coronawarnapp.coronatest.server.CoronaTestResult.RAT_NEGATIVE ...@@ -13,6 +13,7 @@ import de.rki.coronawarnapp.coronatest.server.CoronaTestResult.RAT_NEGATIVE
import de.rki.coronawarnapp.coronatest.server.CoronaTestResult.RAT_PENDING import de.rki.coronawarnapp.coronatest.server.CoronaTestResult.RAT_PENDING
import de.rki.coronawarnapp.coronatest.server.CoronaTestResult.RAT_POSITIVE import de.rki.coronawarnapp.coronatest.server.CoronaTestResult.RAT_POSITIVE
import de.rki.coronawarnapp.coronatest.server.CoronaTestResult.RAT_REDEEMED import de.rki.coronawarnapp.coronatest.server.CoronaTestResult.RAT_REDEEMED
import de.rki.coronawarnapp.coronatest.server.VerificationServer
import de.rki.coronawarnapp.coronatest.tan.CoronaTestTAN import de.rki.coronawarnapp.coronatest.tan.CoronaTestTAN
import de.rki.coronawarnapp.coronatest.type.CoronaTest import de.rki.coronawarnapp.coronatest.type.CoronaTest
import de.rki.coronawarnapp.coronatest.type.CoronaTestProcessor import de.rki.coronawarnapp.coronatest.type.CoronaTestProcessor
...@@ -23,7 +24,6 @@ import de.rki.coronawarnapp.exception.http.BadRequestException ...@@ -23,7 +24,6 @@ import de.rki.coronawarnapp.exception.http.BadRequestException
import de.rki.coronawarnapp.exception.http.CwaWebException import de.rki.coronawarnapp.exception.http.CwaWebException
import de.rki.coronawarnapp.exception.reporting.report import de.rki.coronawarnapp.exception.reporting.report
import de.rki.coronawarnapp.util.TimeStamper import de.rki.coronawarnapp.util.TimeStamper
import de.rki.coronawarnapp.worker.BackgroundConstants
import org.joda.time.Duration import org.joda.time.Duration
import org.joda.time.Instant import org.joda.time.Instant
import timber.log.Timber import timber.log.Timber
...@@ -112,7 +112,7 @@ class RapidAntigenProcessor @Inject constructor( ...@@ -112,7 +112,7 @@ class RapidAntigenProcessor @Inject constructor(
} }
test.copy( test.copy(
testResult = check21PlusDays(test, newTestResult), testResult = check60Days(test, newTestResult),
testResultReceivedAt = determineReceivedDate(test, newTestResult), testResultReceivedAt = determineReceivedDate(test, newTestResult),
lastUpdatedAt = nowUTC, lastUpdatedAt = nowUTC,
lastError = null lastError = null
...@@ -126,16 +126,15 @@ class RapidAntigenProcessor @Inject constructor( ...@@ -126,16 +126,15 @@ class RapidAntigenProcessor @Inject constructor(
} }
} }
// After 21 days, the previously EXPIRED test is deleted from the server, and it may return pending again. // After 60 days, the previously EXPIRED test is deleted from the server, and it may return pending again.
private fun check21PlusDays(test: CoronaTest, newResult: CoronaTestResult): CoronaTestResult { private fun check60Days(test: CoronaTest, newResult: CoronaTestResult): CoronaTestResult {
val calculateDays = Duration(test.registeredAt, timeStamper.nowUTC).standardDays val calculateDays = Duration(test.registeredAt, timeStamper.nowUTC)
Timber.tag(TAG).d("Calculated test age: %d days, newResult=%s", calculateDays, newResult) Timber.tag(TAG).d("Calculated test age: %d days, newResult=%s", calculateDays.standardDays, newResult)
return if ( return if ((newResult == PCR_OR_RAT_PENDING || newResult == RAT_PENDING) &&
(newResult == PCR_OR_RAT_PENDING || newResult == RAT_PENDING) && calculateDays > VerificationServer.TEST_AVAILABLBILITY
calculateDays >= BackgroundConstants.POLLING_VALIDITY_MAX_DAYS
) { ) {
Timber.tag(TAG).d("$calculateDays is exceeding the maximum polling duration") Timber.tag(TAG).d("$calculateDays is exceeding the test availability.")
RAT_REDEEMED RAT_REDEEMED
} else { } else {
newResult newResult
......
...@@ -19,13 +19,6 @@ object BackgroundConstants { ...@@ -19,13 +19,6 @@ object BackgroundConstants {
*/ */
const val WORKER_RETRY_COUNT_THRESHOLD = 2 const val WORKER_RETRY_COUNT_THRESHOLD = 2
/**
* The maximum validity in days for keeping Background polling active
*
* @see TimeUnit.DAYS
*/
const val POLLING_VALIDITY_MAX_DAYS = 21
/** /**
* Backoff initial delay * Backoff initial delay
* *
......
...@@ -13,6 +13,7 @@ import kotlinx.coroutines.runBlocking ...@@ -13,6 +13,7 @@ import kotlinx.coroutines.runBlocking
import okhttp3.ConnectionSpec import okhttp3.ConnectionSpec
import okhttp3.mockwebserver.MockResponse import okhttp3.mockwebserver.MockResponse
import okhttp3.mockwebserver.MockWebServer import okhttp3.mockwebserver.MockWebServer
import org.joda.time.Duration
import org.junit.jupiter.api.AfterEach import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
...@@ -211,4 +212,9 @@ class VerificationServerTest : BaseIOTest() { ...@@ -211,4 +212,9 @@ class VerificationServerTest : BaseIOTest() {
a.headerSizeIgnoringContentLength() shouldBe b.headerSizeIgnoringContentLength() a.headerSizeIgnoringContentLength() shouldBe b.headerSizeIgnoringContentLength()
} }
} }
@Test
fun `test availability constant`() {
VerificationServer.TEST_AVAILABLBILITY shouldBe Duration.standardDays(60)
}
} }
...@@ -94,7 +94,7 @@ class PCRProcessorTest : BaseTest() { ...@@ -94,7 +94,7 @@ class PCRProcessorTest : BaseTest() {
instance.pollServer(pcrTest).testResult shouldBe PCR_OR_RAT_PENDING instance.pollServer(pcrTest).testResult shouldBe PCR_OR_RAT_PENDING
val past60DaysTest = pcrTest.copy( val past60DaysTest = pcrTest.copy(
registeredAt = nowUTC.minus(Duration.standardDays(21)) registeredAt = nowUTC.minus(Duration.standardDays(61))
) )
instance.pollServer(past60DaysTest).testResult shouldBe PCR_REDEEMED instance.pollServer(past60DaysTest).testResult shouldBe PCR_REDEEMED
......
...@@ -75,7 +75,7 @@ class RapidAntigenProcessorTest : BaseTest() { ...@@ -75,7 +75,7 @@ class RapidAntigenProcessorTest : BaseTest() {
instance.pollServer(raTest).testResult shouldBe PCR_OR_RAT_PENDING instance.pollServer(raTest).testResult shouldBe PCR_OR_RAT_PENDING
val past60DaysTest = raTest.copy( val past60DaysTest = raTest.copy(
registeredAt = nowUTC.minus(Duration.standardDays(21)) registeredAt = nowUTC.minus(Duration.standardDays(61))
) )
instance.pollServer(past60DaysTest).testResult shouldBe RAT_REDEEMED instance.pollServer(past60DaysTest).testResult shouldBe RAT_REDEEMED
......
...@@ -9,7 +9,6 @@ class BackgroundConstantsTest { ...@@ -9,7 +9,6 @@ class BackgroundConstantsTest {
fun allBackgroundConstants() { fun allBackgroundConstants() {
Assert.assertEquals(BackgroundConstants.KIND_DELAY, 1L) Assert.assertEquals(BackgroundConstants.KIND_DELAY, 1L)
Assert.assertEquals(BackgroundConstants.WORKER_RETRY_COUNT_THRESHOLD, 2) Assert.assertEquals(BackgroundConstants.WORKER_RETRY_COUNT_THRESHOLD, 2)
Assert.assertEquals(BackgroundConstants.POLLING_VALIDITY_MAX_DAYS, 21)
Assert.assertEquals(BackgroundConstants.BACKOFF_INITIAL_DELAY, 8L) Assert.assertEquals(BackgroundConstants.BACKOFF_INITIAL_DELAY, 8L)
} }
} }
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