Skip to content

Commit

Permalink
Merge branch 'master' into use-sdk-serverconnectionerror
Browse files Browse the repository at this point in the history
  • Loading branch information
sssoleileraaa authored Feb 11, 2020
2 parents 4f9abfb + c883cd2 commit 74889ff
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
8 changes: 4 additions & 4 deletions securedrop_client/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ def process(self) -> None:
Note: Generic exceptions are handled in _do_call_api.
'''
logger.debug('Beginning queue processing loop')

while True:
priority, job = self.queue.get(block=True)

Expand Down Expand Up @@ -199,11 +201,9 @@ def on_queue_paused(self) -> None:
self.paused.emit()

def resume_queues(self) -> None:
logger.info("Resuming queues")
self.start_queues()
if not self.main_thread.isRunning():
if self.main_thread.isRunning():
self.main_queue.resume.emit()
if not self.download_file_thread.isRunning():
if self.download_file_thread.isRunning():
self.download_file_queue.resume.emit()

def enqueue(self, job: ApiJob) -> None:
Expand Down
32 changes: 26 additions & 6 deletions tests/test_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,24 +273,38 @@ def test_ApiJobQueue_pause_queues(mocker):
job_queue.paused.emit.assert_called_once_with()


def test_ApiJobQueue_resume_queues_emits_resume_signal(mocker):
def test_ApiJobQueue_resume_queues_emits_resume_signal_if_queues_are_running(mocker):
"""
Resume only emits if the queue is paused.
Ensure resume signal is emitted if the queues are running.
"""
job_queue = ApiJobQueue(mocker.MagicMock(), mocker.MagicMock())
mocker.patch.object(job_queue.main_queue, 'resume')
mocker.patch.object(job_queue.download_file_queue, 'resume')
job_queue.main_thread.isRunning = mocker.MagicMock(return_value=False)
job_queue.download_file_thread.isRunning = mocker.MagicMock(return_value=False)
job_queue.start_queues = mocker.MagicMock()
job_queue.main_thread.isRunning = mocker.MagicMock(return_value=True)
job_queue.download_file_thread.isRunning = mocker.MagicMock(return_value=True)

job_queue.resume_queues()

job_queue.start_queues.assert_called_once_with()
job_queue.main_queue.resume.emit.assert_called_once_with()
job_queue.download_file_queue.resume.emit.assert_called_once_with()


def test_ApiJobQueue_resume_queues_does_not_emit_resume_signal_if_queues_are_not_running(mocker):
"""
Ensure resume signal is not emitted if the queues ar not running.
"""
job_queue = ApiJobQueue(mocker.MagicMock(), mocker.MagicMock())
mocker.patch.object(job_queue.main_queue, 'resume')
mocker.patch.object(job_queue.download_file_queue, 'resume')
job_queue.main_thread.isRunning = mocker.MagicMock(return_value=False)
job_queue.download_file_thread.isRunning = mocker.MagicMock(return_value=False)

job_queue.resume_queues()

job_queue.main_queue.resume.emit.assert_not_called()
job_queue.download_file_queue.resume.emit.assert_not_called()


def test_ApiJobQueue_enqueue_no_auth(mocker):
mock_client = mocker.MagicMock()
mock_session_maker = mocker.MagicMock()
Expand All @@ -314,6 +328,9 @@ def test_ApiJobQueue_enqueue_no_auth(mocker):


def test_ApiJobQueue_login_if_queues_not_running(mocker):
'''
Ensure token is passed to the queues and that they are started.
'''
mock_api = mocker.MagicMock()
mock_client = mocker.MagicMock()
mock_session_maker = mocker.MagicMock()
Expand All @@ -337,6 +354,9 @@ def test_ApiJobQueue_login_if_queues_not_running(mocker):


def test_ApiJobQueue_login_if_queues_running(mocker):
'''
Ensure token is passed to the queues that are already started.
'''
mock_api = mocker.MagicMock()
mock_client = mocker.MagicMock()
mock_session_maker = mocker.MagicMock()
Expand Down

0 comments on commit 74889ff

Please sign in to comment.