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

Catch case where we are trying to download on the same hour as previously, but...

Catch case where we are trying to download on the same hour as previously, but on a new day. (#1670)

Co-authored-by: default avatarharambasicluka <64483219+harambasicluka@users.noreply.github.com>
parent 59b6aa26
No related branches found
No related tags found
No related merge requests found
...@@ -11,7 +11,6 @@ import de.rki.coronawarnapp.diagnosiskeys.storage.CachedKeyInfo.Type ...@@ -11,7 +11,6 @@ import de.rki.coronawarnapp.diagnosiskeys.storage.CachedKeyInfo.Type
import de.rki.coronawarnapp.diagnosiskeys.storage.KeyCacheRepository import de.rki.coronawarnapp.diagnosiskeys.storage.KeyCacheRepository
import de.rki.coronawarnapp.storage.DeviceStorage import de.rki.coronawarnapp.storage.DeviceStorage
import de.rki.coronawarnapp.util.TimeAndDateExtensions.toLocalDate import de.rki.coronawarnapp.util.TimeAndDateExtensions.toLocalDate
import de.rki.coronawarnapp.util.TimeAndDateExtensions.toLocalTime
import de.rki.coronawarnapp.util.TimeStamper import de.rki.coronawarnapp.util.TimeStamper
import de.rki.coronawarnapp.util.coroutine.DispatcherProvider import de.rki.coronawarnapp.util.coroutine.DispatcherProvider
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
...@@ -19,6 +18,7 @@ import kotlinx.coroutines.Deferred ...@@ -19,6 +18,7 @@ import kotlinx.coroutines.Deferred
import kotlinx.coroutines.async import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import org.joda.time.DateTimeZone
import org.joda.time.Instant import org.joda.time.Instant
import org.joda.time.LocalDate import org.joda.time.LocalDate
import org.joda.time.LocalTime import org.joda.time.LocalTime
...@@ -117,10 +117,10 @@ class HourPackageSyncTool @Inject constructor( ...@@ -117,10 +117,10 @@ class HourPackageSyncTool @Inject constructor(
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
internal fun expectNewHourPackages(cachedHours: List<CachedKey>, now: Instant): Boolean { internal fun expectNewHourPackages(cachedHours: List<CachedKey>, now: Instant): Boolean {
val previousHour = now.toLocalTime().minusHours(1) val today = now.toDateTime(DateTimeZone.UTC)
val newestHour = cachedHours.map { it.info.toDateTime() }.maxOrNull()?.toLocalTime() val newestHour = cachedHours.map { it.info.toDateTime() }.maxOrNull()
return previousHour.hourOfDay != newestHour?.hourOfDay return today.minusHours(1).hourOfDay != newestHour?.hourOfDay || today.toLocalDate() != newestHour.toLocalDate()
} }
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
......
...@@ -204,6 +204,20 @@ class HourPackageSyncToolTest : CommonSyncToolTest() { ...@@ -204,6 +204,20 @@ class HourPackageSyncToolTest : CommonSyncToolTest() {
instance.expectNewHourPackages(listOf(cachedKey1, cachedKey2), now) shouldBe true instance.expectNewHourPackages(listOf(cachedKey1, cachedKey2), now) shouldBe true
} }
@Test
fun `EXPECT_NEW_HOUR_PACKAGES does not get confused by same hour on next day`() = runBlockingTest {
val cachedKey1 = mockk<CachedKey>().apply {
every { info } returns mockk<CachedKeyInfo>().apply {
every { toDateTime() } returns Instant.parse("2020-01-01T00:00:03.000Z").toDateTime(DateTimeZone.UTC)
}
}
val instance = createInstance()
val now = Instant.parse("2020-01-02T01:00:03.000Z")
instance.expectNewHourPackages(listOf(cachedKey1), now) shouldBe true
}
@Test @Test
fun `if keys were revoked skip the EXPECT packages check`() = runBlockingTest { fun `if keys were revoked skip the EXPECT packages check`() = runBlockingTest {
every { timeStamper.nowUTC } returns Instant.parse("2020-01-04T02:00:00.000Z") every { timeStamper.nowUTC } returns Instant.parse("2020-01-04T02:00:00.000Z")
......
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