diff --git a/securedrop_client/queue.py b/securedrop_client/queue.py index 40021f6f2c..97b3eaed89 100644 --- a/securedrop_client/queue.py +++ b/securedrop_client/queue.py @@ -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) @@ -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: diff --git a/tests/test_queue.py b/tests/test_queue.py index 0c438d303f..3fc6831b7c 100644 --- a/tests/test_queue.py +++ b/tests/test_queue.py @@ -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() @@ -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() @@ -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()