Skip to content

Commit

Permalink
test(ApiJobQueue_stop_stops_queue_threads): check thread state, not w…
Browse files Browse the repository at this point in the history
…hether QThread.quit() has been called
  • Loading branch information
cfm committed Nov 8, 2022
1 parent 1ed35ce commit f70327c
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions tests/test_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,15 +510,20 @@ def test_ApiJobQueue_start_if_queues_running(mocker):


def test_ApiJobQueue_stop_stops_queue_threads(mocker):
"""
After ApiJobQueue.stop(), the queue threads return from the processing loop and quit.
"""
with threads(2) as [main_thread, file_download_thread]:
job_queue = ApiJobQueue(
mocker.MagicMock(), mocker.MagicMock(), main_thread, file_download_thread
)
job_queue.start(mocker.MagicMock())
assert job_queue.main_thread.isRunning()
assert job_queue.download_file_thread.isRunning()

job_queue.stop()

assert not job_queue.main_thread.isRunning()
assert not job_queue.download_file_thread.isRunning()
assert job_queue.main_thread.wait()
assert job_queue.download_file_thread.wait()


def test_ApiJobQueue_stop_clears_jobs(mocker):
Expand All @@ -540,18 +545,7 @@ def test_ApiJobQueue_stop_clears_jobs(mocker):
assert job_queue.main_queue.queue.qsize() == 1

job_queue.stop()
assert job_queue.main_queue.queue.empty()
assert job_queue.main_thread.wait()
assert job_queue.download_file_thread.wait()


def test_ApiJobQueue_stop_results_in_queue_threads_not_running(mocker):
with threads(2) as [main_thread, file_download_thread]:
job_queue = ApiJobQueue(
mocker.MagicMock(), mocker.MagicMock(), main_thread, file_download_thread
)
job_queue.main_thread = mocker.MagicMock()
job_queue.download_file_thread = mocker.MagicMock()

job_queue.stop()

job_queue.main_thread.quit.assert_called_once_with()
job_queue.download_file_thread.quit.assert_called_once_with()
assert job_queue.main_queue.queue.empty()

0 comments on commit f70327c

Please sign in to comment.