@@ -33,8 +33,7 @@ def run(x):
3333 mocker .Mock (), mocker .Mock (), mocker .Mock ())
3434 sychronizer = Synchronizer (split_synchronizers , mocker .Mock (spec = SplitTasks ))
3535
36- with pytest .raises (APIException ):
37- sychronizer .synchronize_splits (None )
36+ sychronizer .synchronize_splits (None ) # APIExceptions are handled locally and should not be propagated!
3837
3938 sychronizer .sync_all () # sync_all should not throw!
4039
@@ -209,3 +208,59 @@ def stop_mock_2():
209208 assert len (impression_count_task .stop .mock_calls ) == 1
210209 assert len (event_task .stop .mock_calls ) == 1
211210 assert len (telemetry_task .stop .mock_calls ) == 1
211+
212+ def test_sync_all_ok (self , mocker ):
213+ """Test that 3 attempts are done before failing."""
214+ split_synchronizers = mocker .Mock (spec = SplitSynchronizers )
215+ counts = {'splits' : 0 , 'segments' : 0 }
216+
217+ def sync_splits (* _ ):
218+ """Sync Splits."""
219+ counts ['splits' ] += 1
220+ return True
221+
222+ def sync_segments (* _ ):
223+ """Sync Segments."""
224+ counts ['segments' ] += 1
225+ return True
226+
227+ split_synchronizers .split_sync .synchronize_splits .side_effect = sync_splits
228+ split_synchronizers .segment_sync .synchronize_segments .side_effect = sync_segments
229+ split_tasks = mocker .Mock (spec = SplitTasks )
230+ synchronizer = Synchronizer (split_synchronizers , split_tasks )
231+
232+ synchronizer .sync_all ()
233+ assert counts ['splits' ] == 1
234+ assert counts ['segments' ] == 1
235+
236+ def test_sync_all_attempts (self , mocker ):
237+ """Test that 3 attempts are done before failing."""
238+ split_synchronizers = mocker .Mock (spec = SplitSynchronizers )
239+ counts = {'splits' : 0 , 'segments' : 0 }
240+ def sync_splits (* _ ):
241+ """Sync Splits."""
242+ counts ['splits' ] += 1
243+ raise Exception ('sarasa' )
244+
245+ split_synchronizers .split_sync .synchronize_splits .side_effect = sync_splits
246+ split_tasks = mocker .Mock (spec = SplitTasks )
247+ synchronizer = Synchronizer (split_synchronizers , split_tasks )
248+
249+ synchronizer .sync_all ()
250+ assert counts ['splits' ] == 3
251+
252+ def test_sync_all_attempts (self , mocker ):
253+ """Test that 3 attempts are done before failing."""
254+ split_synchronizers = mocker .Mock (spec = SplitSynchronizers )
255+ counts = {'splits' : 0 , 'segments' : 0 }
256+ def sync_segments (* _ ):
257+ """Sync Splits."""
258+ counts ['segments' ] += 1
259+ raise Exception ('sarasa' )
260+
261+ split_synchronizers .segment_sync .synchronize_segments .side_effect = sync_segments
262+ split_tasks = mocker .Mock (spec = SplitTasks )
263+ synchronizer = Synchronizer (split_synchronizers , split_tasks )
264+
265+ synchronizer .sync_all ()
266+ assert counts ['segments' ] == 3
0 commit comments