@@ -31,6 +31,50 @@ class SyncOrchestratorTest {
3131 @get:Rule
3232 val warmUpRule = WarmUpRule ()
3333
34+ @Test
35+ fun `when the sync wasn't running before, an initial sync will take place, even with no network` () = runTest {
36+ val startSyncRecorder = lambdaRecorder<Result <Unit >> { Result .success(Unit ) }
37+ val syncService = FakeSyncService (initialSyncState = SyncState .Idle ).apply {
38+ startSyncLambda = startSyncRecorder
39+ }
40+ val networkMonitor = FakeNetworkMonitor (initialStatus = NetworkStatus .Disconnected )
41+ val syncOrchestrator = createSyncOrchestrator(
42+ syncService = syncService,
43+ networkMonitor = networkMonitor,
44+ )
45+
46+ // We start observing with an initial sync
47+ syncOrchestrator.start()
48+
49+ // Advance the time just enough to make sure the initial sync has run
50+ advanceTimeBy(1 .milliseconds)
51+ startSyncRecorder.assertions().isCalledOnce()
52+ }
53+
54+ @Test
55+ fun `when the sync wasn't running before, an initial sync will take place` () = runTest {
56+ val startSyncRecorder = lambdaRecorder<Result <Unit >> { Result .success(Unit ) }
57+ val syncService = FakeSyncService (initialSyncState = SyncState .Idle ).apply {
58+ startSyncLambda = startSyncRecorder
59+ }
60+ val networkMonitor = FakeNetworkMonitor (initialStatus = NetworkStatus .Connected )
61+ val syncOrchestrator = createSyncOrchestrator(
62+ syncService = syncService,
63+ networkMonitor = networkMonitor,
64+ )
65+
66+ // We start observing with an initial sync
67+ syncOrchestrator.start()
68+
69+ // Advance the time just enough to make sure the initial sync has run
70+ advanceTimeBy(1 .milliseconds)
71+ startSyncRecorder.assertions().isCalledOnce()
72+
73+ // If we wait for a while, the sync will not be started again by the observer since it's already running
74+ advanceTimeBy(10 .seconds)
75+ startSyncRecorder.assertions().isCalledOnce()
76+ }
77+
3478 @Test
3579 fun `when the app goes to background and the sync was running, it will be stopped after a delay` () = runTest {
3680 val stopSyncRecorder = lambdaRecorder<Result <Unit >> { Result .success(Unit ) }
@@ -46,7 +90,7 @@ class SyncOrchestratorTest {
4690 )
4791
4892 // We start observing
49- syncOrchestrator.start ()
93+ syncOrchestrator.observeStates ()
5094
5195 // Advance the time to make sure the orchestrator has had time to start processing the inputs
5296 advanceTimeBy(100 .milliseconds)
@@ -78,7 +122,7 @@ class SyncOrchestratorTest {
78122 )
79123
80124 // We start observing
81- syncOrchestrator.start ()
125+ syncOrchestrator.observeStates ()
82126
83127 // Advance the time to make sure the orchestrator has had time to start processing the inputs
84128 advanceTimeBy(100 .milliseconds)
@@ -126,7 +170,7 @@ class SyncOrchestratorTest {
126170 )
127171
128172 // We start observing
129- syncOrchestrator.start ()
173+ syncOrchestrator.observeStates ()
130174
131175 // Advance the time to make sure the orchestrator has had time to start processing the inputs
132176 advanceTimeBy(100 .milliseconds)
@@ -169,7 +213,7 @@ class SyncOrchestratorTest {
169213 )
170214
171215 // We start observing
172- syncOrchestrator.start ()
216+ syncOrchestrator.observeStates ()
173217
174218 // Advance the time to make sure the orchestrator has had time to start processing the inputs
175219 advanceTimeBy(100 .milliseconds)
@@ -213,7 +257,7 @@ class SyncOrchestratorTest {
213257 )
214258
215259 // We start observing
216- syncOrchestrator.start ()
260+ syncOrchestrator.observeStates ()
217261
218262 // Advance the time to make sure the orchestrator has had time to start processing the inputs
219263 advanceTimeBy(100 .milliseconds)
@@ -256,7 +300,7 @@ class SyncOrchestratorTest {
256300 )
257301
258302 // We start observing
259- syncOrchestrator.start ()
303+ syncOrchestrator.observeStates ()
260304
261305 // Advance the time to make sure the orchestrator has had time to start processing the inputs
262306 advanceTimeBy(100 .milliseconds)
@@ -285,7 +329,7 @@ class SyncOrchestratorTest {
285329 )
286330
287331 // We start observing
288- syncOrchestrator.start ()
332+ syncOrchestrator.observeStates ()
289333
290334 // This should still not trigger a sync, since there is no network
291335 advanceTimeBy(10 .seconds)
0 commit comments