Mercurial > hg > orthanc-tests
annotate NewTests/DelayedDeletion/test_delayed_deletion.py @ 627:76c9923050b5
patch Docker env var (thx James)
author | Alain Mazy <am@osimis.io> |
---|---|
date | Wed, 21 Feb 2024 08:36:58 +0100 |
parents | 6144ef431512 |
children | ed0a51317c0b |
rev | line source |
---|---|
483 | 1 import unittest |
2 import time | |
3 import os | |
4 from helpers import OrthancTestCase, Helpers | |
5 | |
6 from orthanc_api_client import OrthancApiClient, generate_test_dicom_file | |
7 from orthanc_tools import OrthancTestDbPopulator | |
8 | |
9 import pathlib | |
10 import glob | |
11 here = pathlib.Path(__file__).parent.resolve() | |
12 | |
13 | |
14 class TestDelayedDeletion(OrthancTestCase): | |
15 | |
16 @classmethod | |
17 def prepare(cls): | |
18 print('-------------- preparing TestDelayedDeletion tests') | |
19 | |
20 cls.clear_storage(storage_name="DelayedDeletion") | |
21 | |
22 config = { | |
23 "DelayedDeletion": { | |
24 "Enable": True, | |
25 "ThrottleDelayMs": 200 | |
26 } | |
27 } | |
28 | |
29 config_path = cls.generate_configuration( | |
30 config_name="delayed_deletion", | |
31 storage_name="DelayedDeletion", | |
32 config=config, | |
33 plugins=Helpers.plugins | |
34 ) | |
35 | |
36 if Helpers.break_before_preparation: | |
37 print(f"++++ It is now time to start your Orthanc under tests with configuration file '{config_path}' +++++") | |
38 input("Press Enter to continue") | |
39 else: | |
40 print('-------------- launching DelayedDeletion preparation') | |
41 | |
42 cls.launch_orthanc_to_prepare_db( | |
43 config_name="delayed_deletion", | |
44 config_path=config_path, | |
45 storage_name="DelayedDeletion", | |
46 config=config, | |
47 plugins=Helpers.plugins | |
48 ) | |
486
6144ef431512
new tests for sequences in ExtraMainDicomTags
Alain Mazy <am@osimis.io>
parents:
484
diff
changeset
|
49 |
6144ef431512
new tests for sequences in ExtraMainDicomTags
Alain Mazy <am@osimis.io>
parents:
484
diff
changeset
|
50 print('-------------- waiting for orthanc-to-prepare-db to be available') |
6144ef431512
new tests for sequences in ExtraMainDicomTags
Alain Mazy <am@osimis.io>
parents:
484
diff
changeset
|
51 cls.o.wait_started() |
483 | 52 |
486
6144ef431512
new tests for sequences in ExtraMainDicomTags
Alain Mazy <am@osimis.io>
parents:
484
diff
changeset
|
53 print('-------------- populating') |
6144ef431512
new tests for sequences in ExtraMainDicomTags
Alain Mazy <am@osimis.io>
parents:
484
diff
changeset
|
54 cls.o.upload_folder(here / "../../Database/Knix/Loc") |
6144ef431512
new tests for sequences in ExtraMainDicomTags
Alain Mazy <am@osimis.io>
parents:
484
diff
changeset
|
55 print('-------------- populated') |
483 | 56 cls.files_count_after_preparation = len(glob.glob(os.path.join(cls.get_storage_path("DelayedDeletion"), "**"), recursive=True)) |
57 | |
58 all_studies_ids = cls.o.studies.get_all_ids() | |
59 # delete all studies and exit Orthanc one seconds later | |
60 cls.o.studies.delete(orthanc_ids = all_studies_ids) | |
61 time.sleep(1) | |
62 | |
63 if Helpers.break_before_preparation: | |
64 print(f"++++ It is now time stop your Orthanc +++++") | |
65 input("Press Enter to continue") | |
66 else: | |
67 cls.kill_orthanc() | |
68 | |
69 cls.files_count_after_stop = len(glob.glob(os.path.join(cls.get_storage_path("DelayedDeletion"), "**"), recursive=True)) | |
70 | |
71 # speed up deletion for the second part of the tests | |
72 config["DelayedDeletion"]["ThrottleDelayMs"] = 0 | |
73 | |
74 config_path = cls.generate_configuration( | |
75 config_name="delayed_deletion", | |
76 storage_name="DelayedDeletion", | |
77 config=config, | |
78 plugins=Helpers.plugins | |
79 ) | |
80 | |
81 print('-------------- prepared DelayedDeletion tests') | |
82 if Helpers.break_after_preparation: | |
83 print(f"++++ It is now time to start your Orthanc under tests with configuration file '{config_path}' +++++") | |
84 input("Press Enter to continue") | |
85 else: | |
86 print('-------------- launching DelayedDeletion tests') | |
87 cls.launch_orthanc_under_tests( | |
88 config_path=config_path, | |
89 config_name="delayed_deletion", | |
90 storage_name="DelayedDeletion", | |
91 plugins=Helpers.plugins | |
92 ) | |
93 | |
94 print('-------------- waiting for orthanc-under-tests to be available') | |
95 cls.o.wait_started() | |
96 | |
97 | |
98 | |
99 def test_resumes_pending_deletion(self): | |
100 | |
101 completed = False | |
102 while not completed: | |
103 print('-------------- waiting for DelayedDeletion to finish processing') | |
104 time.sleep(1) | |
105 plugin_status = self.o.get_json("/plugins/delayed-deletion/status") | |
106 completed = plugin_status["FilesPendingDeletion"] == 0 | |
107 | |
484
ddfabe1fbee1
new tests for DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
483
diff
changeset
|
108 self.assertTrue(completed) |
ddfabe1fbee1
new tests for DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
483
diff
changeset
|
109 files_count_after_delayed_deletion_is_complete = len(glob.glob(os.path.join(self.get_storage_path("DelayedDeletion"), "**"), recursive=True)) |
ddfabe1fbee1
new tests for DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
483
diff
changeset
|
110 self.assertGreater(10, files_count_after_delayed_deletion_is_complete) # only the sqlite files shall remain (and . and ..) |
ddfabe1fbee1
new tests for DelayedDeletion plugin
Alain Mazy <am@osimis.io>
parents:
483
diff
changeset
|
111 |