mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-17 15:26:23 +00:00
Bug 1830080 Add more careful handling of preview-collection in maybeFetchExperiments
This commit is contained in:
parent
5a1ecb81f5
commit
edc5077015
@ -109,12 +109,11 @@ fun NimbusInterface.maybeFetchExperiments(
|
|||||||
feature: NimbusSystem = FxNimbusMessaging.features.nimbusSystem.value(),
|
feature: NimbusSystem = FxNimbusMessaging.features.nimbusSystem.value(),
|
||||||
currentTimeMillis: Long = System.currentTimeMillis(),
|
currentTimeMillis: Long = System.currentTimeMillis(),
|
||||||
) {
|
) {
|
||||||
val minimumPeriodMinutes = if (!context.settings().nimbusUsePreview) {
|
if (context.settings().nimbusUsePreview) {
|
||||||
feature.refreshIntervalForeground
|
context.settings().nimbusLastFetchTime = 0L
|
||||||
|
fetchExperiments()
|
||||||
} else {
|
} else {
|
||||||
0
|
val minimumPeriodMinutes = feature.refreshIntervalForeground
|
||||||
}
|
|
||||||
|
|
||||||
val lastFetchTimeMillis = context.settings().nimbusLastFetchTime
|
val lastFetchTimeMillis = context.settings().nimbusLastFetchTime
|
||||||
val minimumPeriodMillis = minimumPeriodMinutes * Settings.ONE_MINUTE_MS
|
val minimumPeriodMillis = minimumPeriodMinutes * Settings.ONE_MINUTE_MS
|
||||||
|
|
||||||
@ -123,3 +122,4 @@ fun NimbusInterface.maybeFetchExperiments(
|
|||||||
fetchExperiments()
|
fetchExperiments()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@ -100,4 +100,65 @@ class NimbusSystemTest {
|
|||||||
)
|
)
|
||||||
assertTrue(nimbus.isFetching)
|
assertTrue(nimbus.isFetching)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `GIVEN a nimbus object calling maybeFetchExperiments WHEN using a preview collection THEN always call fetchExperiments`() {
|
||||||
|
var currentTime = 0L
|
||||||
|
fun assertFetchEveryTime() {
|
||||||
|
nimbus.maybeFetchExperiments(
|
||||||
|
context,
|
||||||
|
config,
|
||||||
|
currentTime,
|
||||||
|
)
|
||||||
|
assertTrue(nimbus.isFetching)
|
||||||
|
assertEquals(lastTimeSlot.captured, 0L)
|
||||||
|
nimbus.isFetching = false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Using usePreview, we call fetch every time we call maybeFetch.
|
||||||
|
every { settings.nimbusUsePreview } returns true
|
||||||
|
currentTime = Settings.ONE_HOUR_MS
|
||||||
|
assertFetchEveryTime()
|
||||||
|
|
||||||
|
currentTime += Settings.ONE_MINUTE_MS
|
||||||
|
assertFetchEveryTime()
|
||||||
|
|
||||||
|
currentTime += Settings.ONE_MINUTE_MS
|
||||||
|
assertFetchEveryTime()
|
||||||
|
|
||||||
|
// Now turn preview collection off.
|
||||||
|
// We should fetch exactly once…
|
||||||
|
every { settings.nimbusUsePreview } returns false
|
||||||
|
|
||||||
|
currentTime += Settings.ONE_MINUTE_MS
|
||||||
|
nimbus.maybeFetchExperiments(
|
||||||
|
context,
|
||||||
|
config,
|
||||||
|
currentTime,
|
||||||
|
)
|
||||||
|
assertTrue(nimbus.isFetching)
|
||||||
|
assertEquals(lastTimeSlot.captured, currentTime)
|
||||||
|
nimbus.isFetching = false
|
||||||
|
every { settings.nimbusLastFetchTime } returns currentTime
|
||||||
|
|
||||||
|
// … and then back off. We show here that the next call to maybeFetch
|
||||||
|
// doesn't call fetch.
|
||||||
|
currentTime += Settings.ONE_MINUTE_MS
|
||||||
|
nimbus.maybeFetchExperiments(
|
||||||
|
context,
|
||||||
|
config,
|
||||||
|
currentTime,
|
||||||
|
)
|
||||||
|
assertFalse(nimbus.isFetching)
|
||||||
|
|
||||||
|
// Now wait, another hour, and we've reset the behaviour back to normal operation.
|
||||||
|
currentTime += Settings.ONE_HOUR_MS + Settings.ONE_MINUTE_MS
|
||||||
|
nimbus.maybeFetchExperiments(
|
||||||
|
context,
|
||||||
|
config,
|
||||||
|
currentTime,
|
||||||
|
)
|
||||||
|
assertTrue(nimbus.isFetching)
|
||||||
|
assertEquals(lastTimeSlot.captured, currentTime)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user