diff --git a/components/feature/push/src/main/java/mozilla/components/feature/push/AutoPushFeature.kt b/components/feature/push/src/main/java/mozilla/components/feature/push/AutoPushFeature.kt index 48e59dbe115..610922d7623 100644 --- a/components/feature/push/src/main/java/mozilla/components/feature/push/AutoPushFeature.kt +++ b/components/feature/push/src/main/java/mozilla/components/feature/push/AutoPushFeature.kt @@ -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) } diff --git a/components/feature/push/src/test/java/mozilla/components/feature/push/AutoPushFeatureTest.kt b/components/feature/push/src/test/java/mozilla/components/feature/push/AutoPushFeatureTest.kt index 894e8cb32a1..df5bb339646 100644 --- a/components/feature/push/src/test/java/mozilla/components/feature/push/AutoPushFeatureTest.kt +++ b/components/feature/push/src/test/java/mozilla/components/feature/push/AutoPushFeatureTest.kt @@ -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 @@ -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() @@ -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) diff --git a/docs/changelog.md b/docs/changelog.md index a2da53f1279..f16b1929d71 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -15,6 +15,9 @@ permalink: /changelog/ * **browser-icons** * Fixed issue [#7142](https://github.com/mozilla-mobile/android-components/issues/7142) +* **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)