Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Merge #7239
Browse files Browse the repository at this point in the history
7239: Close #7236: Fix last verification check in AutoPushFeature r=Amejia481 a=jonalmeida

When we first access the `lastVerified` pref we do not have an value
stored so we get the value from the current time.

The first usage is where we compare the delta of the current time with
the `lastVerified` so this lead us to have a negative value which fails.




Co-authored-by: Jonathan Almeida <[email protected]>
  • Loading branch information
MozLando and jonalmeida committed Jun 8, 2020
2 parents 9473211 + de6f222 commit 35d3909
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class AutoPushFeature(
private val prefToken: String?
get() = preferences(context).getString(PREF_TOKEN, null)
private var prefLastVerified: Long
get() = preferences(context).getLong(LAST_VERIFIED, System.currentTimeMillis())
get() = preferences(context).getLong(LAST_VERIFIED, 0)
set(value) = preferences(context).edit().putLong(LAST_VERIFIED, value).apply()

private val coroutineScope = CoroutineScope(coroutineContext) + SupervisorJob() + exceptionHandler { onError(it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import mozilla.components.support.test.mock
import mozilla.components.support.test.nullable
import mozilla.components.support.test.robolectric.testContext
import mozilla.components.support.test.whenever
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNotNull
Expand Down Expand Up @@ -54,11 +55,14 @@ class AutoPushFeatureTest {

@Before
fun setup() {
lastVerified = 0L

whenever(connection.isInitialized()).thenReturn(true)
}

@After
fun shutdown() {
preference(testContext).edit().remove(LAST_VERIFIED).apply()
}

@Test
fun `initialize starts push service`() {
val service: PushService = mock()
Expand Down Expand Up @@ -407,6 +411,23 @@ class AutoPushFeatureTest {
verify(feature, never()).verifyActiveSubscriptions()
}

@Test
fun `verification always happens on first attempt`() = runBlockingTest {
val feature = spy(
AutoPushFeature(
context = testContext,
service = mock(),
config = mock(),
coroutineContext = coroutineContext,
connection = mock()
)
)

feature.initialize()

verify(feature).verifyActiveSubscriptions()
}

@Test
fun `crash reporter is notified of errors`() = runBlockingTest {
val native: PushConnection = TestPushConnection(true)
Expand Down
3 changes: 3 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ permalink: /changelog/
* **support-rustlog**
* `RustLog.enable` now takes an optional [CrashReporting] instance which is used to submit error-level log messages as `RustErrorException`s.

* **feature-push**
* Fixed a bug where we do not verify subscriptions on first attempt.

# 44.0.0

* [Commits](https://github.com/mozilla-mobile/android-components/compare/v43.0.0...v44.0.0)
Expand Down

0 comments on commit 35d3909

Please sign in to comment.