# HG changeset patch # User Alain Mazy # Date 1655905531 -7200 # Node ID 45c3fe035fed4772d6c4bca6fe5ac0e0438b1b65 # Parent 535e651e70a29800ee60477a9745e6fb6a574b6a added tests for delayed_deletion diff -r 535e651e70a2 -r 45c3fe035fed NewTests/DelayedDeletion/__init__.py diff -r 535e651e70a2 -r 45c3fe035fed NewTests/DelayedDeletion/test_delayed_deletion.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/NewTests/DelayedDeletion/test_delayed_deletion.py Wed Jun 22 15:45:31 2022 +0200 @@ -0,0 +1,109 @@ +import unittest +import time +import os +from helpers import OrthancTestCase, Helpers + +from orthanc_api_client import OrthancApiClient, generate_test_dicom_file +from orthanc_tools import OrthancTestDbPopulator + +import pathlib +import glob +here = pathlib.Path(__file__).parent.resolve() + + +class TestDelayedDeletion(OrthancTestCase): + + @classmethod + def prepare(cls): + print('-------------- preparing TestDelayedDeletion tests') + + cls.clear_storage(storage_name="DelayedDeletion") + + config = { + "DelayedDeletion": { + "Enable": True, + "ThrottleDelayMs": 200 + } + } + + config_path = cls.generate_configuration( + config_name="delayed_deletion", + storage_name="DelayedDeletion", + config=config, + plugins=Helpers.plugins + ) + + if Helpers.break_before_preparation: + print(f"++++ It is now time to start your Orthanc under tests with configuration file '{config_path}' +++++") + input("Press Enter to continue") + else: + print('-------------- launching DelayedDeletion preparation') + + cls.launch_orthanc_to_prepare_db( + config_name="delayed_deletion", + config_path=config_path, + storage_name="DelayedDeletion", + config=config, + plugins=Helpers.plugins + ) + + populator = OrthancTestDbPopulator( + api_client=cls.o, + studies_count=2, + random_seed=42 + ) + populator.execute() + + cls.files_count_after_preparation = len(glob.glob(os.path.join(cls.get_storage_path("DelayedDeletion"), "**"), recursive=True)) + + all_studies_ids = cls.o.studies.get_all_ids() + # delete all studies and exit Orthanc one seconds later + cls.o.studies.delete(orthanc_ids = all_studies_ids) + time.sleep(1) + + if Helpers.break_before_preparation: + print(f"++++ It is now time stop your Orthanc +++++") + input("Press Enter to continue") + else: + cls.kill_orthanc() + + cls.files_count_after_stop = len(glob.glob(os.path.join(cls.get_storage_path("DelayedDeletion"), "**"), recursive=True)) + + # speed up deletion for the second part of the tests + config["DelayedDeletion"]["ThrottleDelayMs"] = 0 + + config_path = cls.generate_configuration( + config_name="delayed_deletion", + storage_name="DelayedDeletion", + config=config, + plugins=Helpers.plugins + ) + + print('-------------- prepared DelayedDeletion tests') + if Helpers.break_after_preparation: + print(f"++++ It is now time to start your Orthanc under tests with configuration file '{config_path}' +++++") + input("Press Enter to continue") + else: + print('-------------- launching DelayedDeletion tests') + cls.launch_orthanc_under_tests( + config_path=config_path, + config_name="delayed_deletion", + storage_name="DelayedDeletion", + plugins=Helpers.plugins + ) + + print('-------------- waiting for orthanc-under-tests to be available') + cls.o.wait_started() + + + + def test_resumes_pending_deletion(self): + + completed = False + while not completed: + print('-------------- waiting for DelayedDeletion to finish processing') + time.sleep(1) + plugin_status = self.o.get_json("/plugins/delayed-deletion/status") + completed = plugin_status["FilesPendingDeletion"] == 0 + + self.assertTrue(completed) \ No newline at end of file diff -r 535e651e70a2 -r 45c3fe035fed NewTests/Housekeeper/test_housekeeper.py --- a/NewTests/Housekeeper/test_housekeeper.py Tue Jun 21 11:02:45 2022 +0200 +++ b/NewTests/Housekeeper/test_housekeeper.py Wed Jun 22 15:45:31 2022 +0200 @@ -74,7 +74,7 @@ while not completed: print('-------------- waiting for housekeeper to finish processing') time.sleep(1) - housekeeper_status = cls.o.get_json("/housekeeper/status") + housekeeper_status = cls.o.get_json("/plugins/housekeeper/status") completed = (housekeeper_status["LastProcessedConfiguration"]["StorageCompressionEnabled"] == True) \ and (housekeeper_status["LastChangeToProcess"] == housekeeper_status["LastProcessedChange"]) @@ -86,16 +86,16 @@ filter="Instance" )[0] - instance_info = cls.o.get_json(relative_url=f"/instances/{instance_id}") + instance_info = cls.o.get_json(endpoint=f"/instances/{instance_id}") series_id = instance_info["ParentSeries"] - series_info = cls.o.get_json(relative_url=f"/series/{series_id}") + series_info = cls.o.get_json(endpoint=f"/series/{series_id}") study_id = series_info["ParentStudy"] - study_info = cls.o.get_json(relative_url=f"/studies/{study_id}") + study_info = cls.o.get_json(endpoint=f"/studies/{study_id}") patient_id = study_info["ParentPatient"] - patient_info = cls.o.get_json(relative_url=f"/patients/{patient_id}") + patient_info = cls.o.get_json(endpoint=f"/patients/{patient_id}") return instance_info, series_info, study_info, patient_info diff -r 535e651e70a2 -r 45c3fe035fed NewTests/README --- a/NewTests/README Tue Jun 21 11:02:45 2022 +0200 +++ b/NewTests/README Wed Jun 22 15:45:31 2022 +0200 @@ -32,6 +32,7 @@ --orthanc_under_tests_exe=/home/alain/o/build/orthanc/Orthanc \ --orthanc_under_tests_http_port=8043 \ --plugin=/home/alain/o/build/orthanc/libHousekeeper.so \ + --plugin=/home/alain/o/build/orthanc/libDelayedDeletion.so \ --plugin=/home/alain/o/build/orthanc-gdcm/libOrthancGdcm.so diff -r 535e651e70a2 -r 45c3fe035fed NewTests/helpers.py --- a/NewTests/helpers.py Tue Jun 21 11:02:45 2022 +0200 +++ b/NewTests/helpers.py Wed Jun 22 15:45:31 2022 +0200 @@ -27,6 +27,7 @@ orthanc_under_tests_docker_image: str = None skip_preparation: bool = False break_after_preparation: bool = False + break_before_preparation: bool = False plugins: typing.List[str] = [] @classmethod diff -r 535e651e70a2 -r 45c3fe035fed NewTests/main.py --- a/NewTests/main.py Tue Jun 21 11:02:45 2022 +0200 +++ b/NewTests/main.py Wed Jun 22 15:45:31 2022 +0200 @@ -28,9 +28,9 @@ parser.add_argument('--orthanc_previous_version_docker_image', type=str, default=None, help="Docker image of the orthanc version used to prepare previous version of storage/db (if it must be launched by this script)") parser.add_argument('--skip_preparation', action='store_true', help="if this is a multi stage tests with preparations, skip the preparation") parser.add_argument('--break_after_preparation', action='store_true', help="if this is a multi stage tests with preparations, pause after the preparation (such that you can start your own orthanc-under-tests in your debugger)") + parser.add_argument('--break_before_preparation', action='store_true', help="if this is a multi stage tests with preparations, pause before the preparation (such that you can start your own orthanc-under-tests in your debugger)") parser.add_argument('-p', '--plugin', dest='plugins', action='append', type=str, help='path to a plugin to add to configuration') - args = parser.parse_args() loader = unittest.TestLoader() @@ -58,6 +58,8 @@ Helpers.skip_preparation = True if args.break_after_preparation: Helpers.break_after_preparation = True + if args.break_before_preparation: + Helpers.break_before_preparation = True print("Launching tests") diff -r 535e651e70a2 -r 45c3fe035fed NewTests/requirements.txt --- a/NewTests/requirements.txt Tue Jun 21 11:02:45 2022 +0200 +++ b/NewTests/requirements.txt Wed Jun 22 15:45:31 2022 +0200 @@ -1,1 +1,1 @@ -orthanc-api-client==0.3.5 \ No newline at end of file +orthanc-tools==0.4.6 \ No newline at end of file