Skip to content

Commit

Permalink
show trying to connect when sync is retrying
Browse files Browse the repository at this point in the history
  • Loading branch information
Allie Crevier committed Feb 27, 2020
1 parent 692d568 commit 16b30f1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
6 changes: 5 additions & 1 deletion securedrop_client/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,8 @@ def call_api(self,
new_api_thread.start()

def on_queue_paused(self) -> None:
self.gui.update_error_status(_('The SecureDrop server cannot be reached.'), duration=0)
self.gui.update_error_status(
_('The SecureDrop server cannot be reached. Trying to reconnect...'), duration=0)
self.show_last_sync_timer.start(TIME_BETWEEN_SHOWING_LAST_SYNC_MS)

def resume_queues(self) -> None:
Expand Down Expand Up @@ -461,6 +462,9 @@ def on_sync_failure(self, result: Exception) -> None:
self.invalidate_token()
self.logout()
self.gui.show_login(error=_('Your session expired. Please log in again.'))
elif isinstance(result, (RequestTimeoutError, ServerConnectionError)):
self.gui.update_error_status(
_('The SecureDrop server cannot be reached. Trying to reconnect...'), duration=0)

def show_last_sync(self):
"""
Expand Down
34 changes: 33 additions & 1 deletion tests/test_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,38 @@ def test_Controller_on_sync_failure_due_to_invalid_token(homedir, config, mocker
co.gui.show_login.assert_called_once_with(error='Your session expired. Please log in again.')


def test_Controller_on_sync_failure_due_to_request_timeout(homedir, config, mocker, session_maker):
"""
If the sync fails because of a request timeout, make sure to show an error message.
"""
gui = mocker.MagicMock()
co = Controller('http://localhost', gui, session_maker, homedir)
co.logout = mocker.MagicMock()
co.gui = mocker.MagicMock()
co.gui.update_error_status = mocker.MagicMock()

co.on_sync_failure(RequestTimeoutError())

co.gui.update_error_status.assert_called_once_with(
'The SecureDrop server cannot be reached. Trying to reconnect...', duration=0)


def test_Controller_on_sync_failure_due_to_connect_timeout(homedir, config, mocker, session_maker):
"""
If the sync fails because of a connect timeout, make sure to show an error message.
"""
gui = mocker.MagicMock()
co = Controller('http://localhost', gui, session_maker, homedir)
co.logout = mocker.MagicMock()
co.gui = mocker.MagicMock()
co.gui.update_error_status = mocker.MagicMock()

co.on_sync_failure(ServerConnectionError())

co.gui.update_error_status.assert_called_once_with(
'The SecureDrop server cannot be reached. Trying to reconnect...', duration=0)


def test_Controller_on_sync_success(homedir, config, mocker):
"""
If there's a result to syncing, then update local storage.
Expand Down Expand Up @@ -1472,7 +1504,7 @@ def test_Controller_on_queue_paused(homedir, config, mocker, session_maker):
co.show_last_sync_timer = mocker.MagicMock()
co.on_queue_paused()
mock_gui.update_error_status.assert_called_once_with(
'The SecureDrop server cannot be reached.', duration=0)
'The SecureDrop server cannot be reached. Trying to reconnect...', duration=0)
co.show_last_sync_timer.start.assert_called_once_with(TIME_BETWEEN_SHOWING_LAST_SYNC_MS)


Expand Down

0 comments on commit 16b30f1

Please sign in to comment.