Skip to content

Commit

Permalink
Additional dicom worker tests
Browse files Browse the repository at this point in the history
  • Loading branch information
medihack committed Nov 16, 2023
1 parent fbaf638 commit 9898c2e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
2 changes: 2 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
-- test job_utils
-- Test canceled task/job in test_workers.py

- Test accessible in form
-- Remove accessible tests from transfer/query_util, (already tested in form)
- Replace 7z with .zip format. Really save in patient folder?
- Figure out if favicon works in all browsers
- Rename C_STORE to C-STORE and so on in dimse connector
Expand Down
41 changes: 39 additions & 2 deletions adit/core/tests/test_workers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import datetime

import pytest
import time_machine
from pytest_mock import MockerFixture

from adit.core.errors import RetriableDicomError
Expand All @@ -24,8 +27,8 @@ def patch_dicom_processors(mocker: MockerFixture):

@pytest.fixture
def dicom_worker(mocker: MockerFixture):
worker = DicomWorker()
worker._redis = mocker.MagicMock()
worker = DicomWorker(polling_interval=1)
mocker.patch.object(worker, "_redis", mocker.MagicMock())
return worker


Expand Down Expand Up @@ -148,3 +151,37 @@ def process_dicom_task(self, dicom_task):

with pytest.raises(QueuedTask.DoesNotExist):
QueuedTask.objects.get(pk=queued_task.pk)


@time_machine.travel(datetime.datetime(2022, 1, 1, 0, 0))
def test_worker_inside_timeslot(mocker: MockerFixture):
time_slot = (datetime.time(22, 0), datetime.time(6, 0))
worker = DicomWorker(polling_interval=1, time_slot=time_slot)
mocker.patch.object(worker, "_redis", mocker.MagicMock())

wait_mock = mocker.patch.object(
worker._stop, "wait", wraps=worker._stop.wait, side_effect=lambda _: worker._stop.set()
)
process_mock = mocker.patch.object(worker, "check_and_process_next_task", return_value=False)

worker.run()

wait_mock.assert_called_once()
process_mock.assert_called_once()


@time_machine.travel(datetime.datetime(2022, 1, 1, 12, 0))
def test_worker_outside_timeslot(mocker: MockerFixture):
time_slot = (datetime.time(22, 0), datetime.time(6, 0))
worker = DicomWorker(polling_interval=1, time_slot=time_slot)
mocker.patch.object(worker, "_redis", mocker.MagicMock())

wait_mock = mocker.patch.object(
worker._stop, "wait", wraps=worker._stop.wait, side_effect=lambda _: worker._stop.set()
)
process_spy = mocker.spy(worker, "check_and_process_next_task")

worker.run()

wait_mock.assert_called_once()
process_spy.assert_not_called()
2 changes: 1 addition & 1 deletion adit/core/workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
TimeSlot = tuple[time, time]

DISTRIBUTED_LOCK = "dicom_worker_lock"
PROCESS_TIMEOUT = 60 * 30 # 30 minutes
PROCESS_TIMEOUT = 60 * 20 # 20 minutes
MAX_PRIORITY = 10


Expand Down

0 comments on commit 9898c2e

Please sign in to comment.