Skip to content

Commit

Permalink
Revert "Introduce immediate sync upon source/conversation deletion"
Browse files Browse the repository at this point in the history
This reverts commit 40a224d.
  • Loading branch information
Allie Crevier committed Dec 22, 2021
1 parent 8ef1da6 commit 93ca170
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
14 changes: 2 additions & 12 deletions securedrop_client/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,12 @@ def __init__(

self.sync_thread.started.connect(self.api_sync_bg_task.sync)

self.timer = QTimer()
self.timer.setInterval(self.TIME_BETWEEN_SYNCS_MS)
self.timer.timeout.connect(self.sync)

def start(self, api_client: API) -> None:
"""
Start metadata syncs.
"""
self.api_client = api_client

self.timer.start()

if not self.sync_thread.isRunning():
logger.debug("Starting sync thread")
self.api_sync_bg_task.api_client = self.api_client
Expand All @@ -74,18 +68,14 @@ def on_sync_success(self) -> None:
Start another sync on success.
"""
self.sync_success.emit()
QTimer.singleShot(self.TIME_BETWEEN_SYNCS_MS, self.api_sync_bg_task.sync)

def on_sync_failure(self, result: Exception) -> None:
"""
Only start another sync on failure if the reason is a timeout request.
"""
self.sync_failure.emit(result)

def sync(self) -> None:
"""
Start an immediate sync.
"""
QTimer.singleShot(1, self.api_sync_bg_task.sync)
QTimer.singleShot(self.TIME_BETWEEN_SYNCS_MS, self.api_sync_bg_task.sync)


class ApiSyncBackgroundTask(QObject):
Expand Down
4 changes: 4 additions & 0 deletions tests/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,14 @@ def test_ApiSync_on_sync_failure(mocker, session_maker, homedir):
"""
api_sync = ApiSync(mocker.MagicMock(), session_maker, mocker.MagicMock(), homedir)
sync_failure = mocker.patch.object(api_sync, "sync_failure")
singleShot_fn = mocker.patch("securedrop_client.sync.QTimer.singleShot")

error = Exception()

api_sync.on_sync_failure(error)

sync_failure.emit.assert_called_once_with(error)
singleShot_fn.assert_called_once_with(15000, api_sync.api_sync_bg_task.sync)


@pytest.mark.parametrize("exception", [RequestTimeoutError, ServerConnectionError])
Expand All @@ -175,8 +177,10 @@ def test_ApiSync_on_sync_failure_because_of_timeout(mocker, session_maker, homed
"""
api_sync = ApiSync(mocker.MagicMock(), session_maker, mocker.MagicMock(), homedir)
sync_failure = mocker.patch.object(api_sync, "sync_failure")
singleShot_fn = mocker.patch("securedrop_client.sync.QTimer.singleShot")
error = exception()

api_sync.on_sync_failure(error)

sync_failure.emit.assert_called_once_with(error)
singleShot_fn.assert_called_once_with(15000, api_sync.api_sync_bg_task.sync)

0 comments on commit 93ca170

Please sign in to comment.