Bug 1813823 - stop re-recording timing distribution for recent synced tabs

fenix/118.0
MatthewTighe 10 months ago committed by mergify[bot]
parent 7750e33bba
commit 20b76e009a

@ -154,7 +154,7 @@ class RecentSyncedTabFeature(
AppAction.RecentSyncedTabStateChange(RecentSyncedTabState.None),
)
} else {
recordMetrics(syncedTabs.first(), lastSyncedTabs?.first(), syncStartId)
recordMetrics(syncedTabs.first(), lastSyncedTabs?.first())
appStore.dispatch(
AppAction.RecentSyncedTabStateChange(RecentSyncedTabState.Success(syncedTabs)),
)
@ -171,10 +171,12 @@ class RecentSyncedTabFeature(
private fun recordMetrics(
tab: RecentSyncedTab,
lastSyncedTab: RecentSyncedTab?,
syncStartId: GleanTimerId?,
) {
RecentSyncedTabs.recentSyncedTabShown[tab.deviceType.name.lowercase()].add()
syncStartId?.let { RecentSyncedTabs.recentSyncedTabTimeToLoad.stopAndAccumulate(it) }
syncStartId?.let {
RecentSyncedTabs.recentSyncedTabTimeToLoad.stopAndAccumulate(it)
syncStartId = null
}
if (tab == lastSyncedTab) {
RecentSyncedTabs.latestSyncedTabIsStale.add()
}

@ -38,6 +38,7 @@ import mozilla.components.service.fxa.sync.SyncReason
import mozilla.components.service.glean.testing.GleanTestRule
import mozilla.components.support.test.libstate.ext.waitUntilIdle
import mozilla.components.support.test.robolectric.testContext
import mozilla.telemetry.glean.internal.ErrorType
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertNull
@ -182,6 +183,40 @@ class RecentSyncedTabFeatureTest {
verify { appStore.dispatch(AppAction.RecentSyncedTabStateChange(RecentSyncedTabState.Success(expected))) }
}
@Test
fun `GIVEN loading state has not been dispatched WHEN status becomes idle THEN timing distribution is not recorded`() = runTest {
val account = mockk<Account>()
syncStore.setState(account = account)
every { appStore.state } returns mockk {
every { recentSyncedTabState } returns RecentSyncedTabState.Loading
}
coEvery { historyStorage.getDetailedVisits(any(), any()) } returns listOf()
val activeTab = createActiveTab()
coEvery { syncedTabsStorage.getSyncedDeviceTabs() } returns listOf(
SyncedDeviceTabs(
device = deviceAccessed1,
tabs = listOf(activeTab),
),
)
feature.start()
syncStore.setState(status = SyncStatus.Idle)
runCurrent()
// this does not trigger a loading state, which should only be shown when tabs are loaded
// during app initialization
syncStore.setState(status = SyncStatus.Started)
runCurrent()
syncStore.setState(status = SyncStatus.Idle)
runCurrent()
assertEquals(
0,
RecentSyncedTabs.recentSyncedTabTimeToLoad.testGetNumRecordedErrors(
ErrorType.INVALID_STATE,
),
)
}
@Test
fun `GIVEN tabs from remote and current devices WHEN dispatching recent synced tab THEN current device is filtered out of dispatch`() = runTest {
val account = mockk<Account>()

Loading…
Cancel
Save