Skip to content
This repository has been archived by the owner on Dec 14, 2021. It is now read-only.

Add telemetry probes to syncIfRequired trigger syncs #887

Merged
merged 1 commit into from
Aug 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions app/src/main/java/mozilla/lockbox/store/DataStore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,11 @@ open class DataStore(
if (item != null) {
backend.delete(item.id)
.asSingle(coroutineContext)
.subscribe()
.subscribe { _ ->
dispatcher.dispatch(DataStoreAction.Sync)
}
.addTo(compositeDisposable)
sync()

deletedItemSubject.accept(Consumable(item))
}
} catch (loginsStorageException: LoginsStorageException) {
Expand Down Expand Up @@ -230,9 +232,12 @@ open class DataStore(
}
}

private fun syncIfRequired() {
@VisibleForTesting(
otherwise = VisibleForTesting.PRIVATE
)
fun syncIfRequired() {
if (timingSupport.shouldSync) {
this.sync()
dispatcher.dispatch(DataStoreAction.Sync)
timingSupport.storeNextSyncTime()
}
}
Expand Down
18 changes: 18 additions & 0 deletions app/src/test/java/mozilla/lockbox/store/DataStoreTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import mozilla.components.concept.sync.AccessTokenInfo
import mozilla.lockbox.DisposingTest
import mozilla.lockbox.action.DataStoreAction
import mozilla.lockbox.action.LifecycleAction
import mozilla.lockbox.extensions.filterByType
import mozilla.lockbox.flux.Dispatcher
import mozilla.lockbox.mocks.MockDataStoreSupport
import mozilla.lockbox.model.FixedSyncCredentials
Expand All @@ -33,6 +34,7 @@ import org.mockito.Mockito.never
import org.mockito.Mockito.times
import org.mockito.Mockito.verify
import org.powermock.api.mockito.PowerMockito
import java.util.concurrent.atomic.AtomicBoolean
import org.powermock.api.mockito.PowerMockito.`when` as whenCalled

@ExperimentalCoroutinesApi
Expand Down Expand Up @@ -87,6 +89,22 @@ class DataStoreTest : DisposingTest() {
Assert.assertEquals(0, listIterator.next().size)
}

@Test
fun testSyncIfRequired_dispatchesSyncAction() {
whenCalled(timingSupport.shouldSync).thenReturn(true)
val isSyncing = AtomicBoolean(false)
val sub = dispatcher.register
.filterByType(DataStoreAction::class.java)
.subscribe {
isSyncing.set(true)
}

subject.syncIfRequired()

Assert.assertTrue(isSyncing.get())
sub.dispose()
}

@Test
fun testLockUnlock_shouldNotSync() {
val stateIterator = this.subject.state.blockingIterable().iterator()
Expand Down