annotate NewTests/Concurrency/test_concurrency.py @ 593:f4f0e2d24a51

more pg-transactions tests
author Alain Mazy <am@osimis.io>
date Thu, 14 Dec 2023 10:41:09 +0100
parents 6753d96dd71f
children 27be80b4b1a9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
592
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
1 import unittest
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
2 import time
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
3 import os
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
4 import threading
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
5 from helpers import OrthancTestCase, Helpers
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
6
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
7 from orthanc_api_client import OrthancApiClient, generate_test_dicom_file
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
8 from orthanc_tools import OrthancTestDbPopulator
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
9
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
10 import pathlib
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
11 import subprocess
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
12 import glob
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
13 here = pathlib.Path(__file__).parent.resolve()
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
14
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
15
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
16 def worker_upload_folder(orthanc_root_url: str, folder: str, repeat: int, worker_id: int):
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
17 o = OrthancApiClient(orthanc_root_url)
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
18 for i in range(0, repeat):
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
19 o.upload_folder(folder, ignore_errors=True)
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
20
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
21 def worker_anonymize_study(orthanc_root_url: str, study_id: str, repeat: int, worker_id: int):
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
22 o = OrthancApiClient(orthanc_root_url)
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
23
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
24 for i in range(0, repeat):
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
25 o.studies.anonymize(orthanc_id=study_id, delete_original=False)
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
26
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
27 def worker_upload_delete_study_part(orthanc_root_url: str, folder: str, repeat: int, workers_count: int, worker_id: int):
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
28 o = OrthancApiClient(orthanc_root_url)
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
29
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
30 all_files = glob.glob(os.path.join(folder, '*.dcm'))
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
31
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
32 for i in range(0, repeat):
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
33 instances_ids = []
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
34
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
35 for i in range(0, len(all_files)):
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
36 if i % workers_count == worker_id:
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
37 instances_ids.extend(o.upload_file(all_files[i]))
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
38
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
39 for instance_id in instances_ids:
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
40 o.instances.delete(orthanc_id=instance_id)
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
41
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
42
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
43 class TestConcurrency(OrthancTestCase):
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
44
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
45 @classmethod
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
46 def terminate(cls):
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
47
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
48 if Helpers.is_docker():
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
49 subprocess.run(["docker", "rm", "-f", "pg-server"])
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
50 else:
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
51 cls.pg_service_process.terminate()
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
52
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
53
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
54 @classmethod
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
55 def prepare(cls):
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
56 test_name = "Concurrency"
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
57 cls._storage_name = "concurrency"
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
58
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
59 print(f'-------------- preparing {test_name} tests')
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
60
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
61 cls.clear_storage(storage_name=cls._storage_name)
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
62
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
63 pg_hostname = "localhost"
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
64 if Helpers.is_docker():
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
65 pg_hostname = "pg-server"
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
66 cls.create_docker_network("concurrency")
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
67
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
68 config = {
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
69 "PostgreSQL" : {
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
70 "EnableStorage": False,
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
71 "EnableIndex": True,
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
72 "Host": pg_hostname,
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
73 "Port": 5432,
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
74 "Database": "postgres",
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
75 "Username": "postgres",
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
76 "Password": "postgres",
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
77 "IndexConnectionsCount": 10,
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
78 "MaximumConnectionRetries" : 2000,
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
79 "ConnectionRetryInterval" : 5,
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
80 "TransactionMode": "READ COMMITTED",
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
81 #"TransactionMode": "SERIALIZABLE",
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
82 "EnableVerboseLogs": True
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
83 },
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
84 "AuthenticationEnabled": False,
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
85 "OverwriteInstances": True,
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
86 "JobsEngineThreadsCount" : {
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
87 "ResourceModification": 8
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
88 },
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
89 }
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
90
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
91 config_path = cls.generate_configuration(
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
92 config_name=f"{test_name}",
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
93 storage_name=cls._storage_name,
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
94 config=config,
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
95 plugins=Helpers.plugins
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
96 )
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
97
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
98 # launch the docker PG server
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
99 print('--------------- launching PostgreSQL server ------------------')
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
100
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
101 cls.pg_service_process = subprocess.Popen([
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
102 "docker", "run", "--rm",
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
103 "-p", "5432:5432",
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
104 "--network", "concurrency",
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
105 "--name", "pg-server",
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
106 "--env", "POSTGRES_HOST_AUTH_METHOD=trust",
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
107 "postgres:15"])
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
108 time.sleep(5)
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
109
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
110 if Helpers.break_before_preparation:
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
111 print(f"++++ It is now time to start your Orthanc under tests with configuration file '{config_path}' +++++")
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
112 input("Press Enter to continue")
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
113 else:
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
114 cls.launch_orthanc_under_tests(
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
115 config_name=f"{test_name}",
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
116 storage_name=cls._storage_name,
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
117 config=config,
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
118 plugins=Helpers.plugins,
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
119 docker_network="concurrency"
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
120 )
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
121
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
122 cls.o = OrthancApiClient(cls.o._root_url)
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
123 cls.o.wait_started()
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
124 cls.o.delete_all_content()
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
125
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
126
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
127 def execute_workers(self, worker_func, worker_args, workers_count):
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
128 workers = []
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
129 for i in range(0, workers_count):
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
130 t = threading.Thread(target=worker_func, args=worker_args + (i, ))
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
131 workers.append(t)
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
132 t.start()
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
133
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
134 for t in workers:
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
135 t.join()
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
136
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
137 def test_concurrent_uploads_same_study(self):
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
138 self.o.delete_all_content()
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
139 self.clear_storage(storage_name=self._storage_name)
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
140
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
141 start_time = time.time()
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
142 workers_count = 20
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
143 repeat_count = 1
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
144
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
145 # massively reupload the same study multiple times with OverwriteInstances set to true
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
146 # Make sure the studies, series and instances are created only once
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
147 self.execute_workers(
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
148 worker_func=worker_upload_folder,
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
149 worker_args=(self.o._root_url, here / "../../Database/Knee", repeat_count,),
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
150 workers_count=workers_count)
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
151
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
152 elapsed = time.time() - start_time
593
f4f0e2d24a51 more pg-transactions tests
Alain Mazy <am@osimis.io>
parents: 592
diff changeset
153 print(f"TIMING test_concurrent_uploads_same_study with {workers_count} workers and {repeat_count}x repeat: {elapsed:.3f} s")
592
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
154
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
155 self.assertTrue(self.o.is_alive())
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
156
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
157 self.assertEqual(1, len(self.o.studies.get_all_ids()))
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
158 self.assertEqual(2, len(self.o.series.get_all_ids()))
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
159 self.assertEqual(50, len(self.o.instances.get_all_ids()))
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
160
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
161 stats = self.o.get_json("/statistics")
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
162 self.assertEqual(1, stats.get("CountPatients"))
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
163 self.assertEqual(1, stats.get("CountStudies"))
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
164 self.assertEqual(2, stats.get("CountSeries"))
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
165 self.assertEqual(50, stats.get("CountInstances"))
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
166 self.assertEqual(4118738, int(stats.get("TotalDiskSize")))
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
167
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
168 self.o.instances.delete(orthanc_ids=self.o.instances.get_all_ids())
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
169
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
170 self.assertEqual(0, len(self.o.studies.get_all_ids()))
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
171 self.assertEqual(0, len(self.o.series.get_all_ids()))
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
172 self.assertEqual(0, len(self.o.instances.get_all_ids()))
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
173
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
174 stats = self.o.get_json("/statistics")
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
175 self.assertEqual(0, stats.get("CountPatients"))
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
176 self.assertEqual(0, stats.get("CountStudies"))
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
177 self.assertEqual(0, stats.get("CountSeries"))
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
178 self.assertEqual(0, stats.get("CountInstances"))
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
179 self.assertEqual(0, int(stats.get("TotalDiskSize")))
593
f4f0e2d24a51 more pg-transactions tests
Alain Mazy <am@osimis.io>
parents: 592
diff changeset
180 # time.sleep(10000)
592
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
181 self.assertTrue(self.is_storage_empty(self._storage_name))
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
182
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
183 def test_concurrent_anonymize_same_study(self):
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
184 self.o.delete_all_content()
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
185 self.clear_storage(storage_name=self._storage_name)
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
186
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
187 self.o.upload_folder(here / "../../Database/Knee")
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
188 study_id = self.o.studies.get_all_ids()[0]
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
189
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
190 start_time = time.time()
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
191 workers_count = 4
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
192 repeat_count = 10
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
193
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
194 # massively anonymize the same study. This generates new studies and is a
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
195 # good way to simulate ingestion of new studies
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
196 self.execute_workers(
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
197 worker_func=worker_anonymize_study,
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
198 worker_args=(self.o._root_url, study_id, repeat_count,),
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
199 workers_count=workers_count)
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
200
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
201 elapsed = time.time() - start_time
593
f4f0e2d24a51 more pg-transactions tests
Alain Mazy <am@osimis.io>
parents: 592
diff changeset
202 print(f"TIMING test_concurrent_anonymize_same_study with {workers_count} workers and {repeat_count}x repeat: {elapsed:.3f} s")
592
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
203
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
204 self.assertTrue(self.o.is_alive())
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
205
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
206 self.assertEqual(1 + workers_count * repeat_count, len(self.o.studies.get_all_ids()))
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
207 self.assertEqual(2 * (1 + workers_count * repeat_count), len(self.o.series.get_all_ids()))
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
208 self.assertEqual(50 * (1 + workers_count * repeat_count), len(self.o.instances.get_all_ids()))
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
209
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
210 stats = self.o.get_json("/statistics")
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
211 self.assertEqual(1 + workers_count * repeat_count, stats.get("CountPatients"))
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
212 self.assertEqual(1 + workers_count * repeat_count, stats.get("CountStudies"))
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
213 self.assertEqual(2 * (1 + workers_count * repeat_count), stats.get("CountSeries"))
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
214 self.assertEqual(50 * (1 + workers_count * repeat_count), stats.get("CountInstances"))
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
215
593
f4f0e2d24a51 more pg-transactions tests
Alain Mazy <am@osimis.io>
parents: 592
diff changeset
216 start_time = time.time()
f4f0e2d24a51 more pg-transactions tests
Alain Mazy <am@osimis.io>
parents: 592
diff changeset
217
592
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
218 self.o.instances.delete(orthanc_ids=self.o.instances.get_all_ids())
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
219
593
f4f0e2d24a51 more pg-transactions tests
Alain Mazy <am@osimis.io>
parents: 592
diff changeset
220 elapsed = time.time() - start_time
f4f0e2d24a51 more pg-transactions tests
Alain Mazy <am@osimis.io>
parents: 592
diff changeset
221 print(f"TIMING test_concurrent_anonymize_same_study deletion took: {elapsed:.3f} s")
f4f0e2d24a51 more pg-transactions tests
Alain Mazy <am@osimis.io>
parents: 592
diff changeset
222
592
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
223 self.assertEqual(0, len(self.o.studies.get_all_ids()))
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
224 self.assertEqual(0, len(self.o.series.get_all_ids()))
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
225 self.assertEqual(0, len(self.o.instances.get_all_ids()))
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
226
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
227 stats = self.o.get_json("/statistics")
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
228 self.assertEqual(0, stats.get("CountPatients"))
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
229 self.assertEqual(0, stats.get("CountStudies"))
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
230 self.assertEqual(0, stats.get("CountSeries"))
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
231 self.assertEqual(0, stats.get("CountInstances"))
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
232 self.assertEqual(0, int(stats.get("TotalDiskSize")))
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
233 self.assertTrue(self.is_storage_empty(self._storage_name))
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
234
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
235
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
236 def test_upload_delete_same_study_from_multiple_threads(self):
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
237 self.o.delete_all_content()
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
238 self.clear_storage(storage_name=self._storage_name)
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
239
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
240 start_time = time.time()
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
241 workers_count = 5
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
242 repeat_count = 30
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
243
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
244 # massively upload and delete the same study. Each worker is writing a part of the instances and deleting them.
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
245 # We are trying to have multiple workers deleting the last instance of a study at the same time.
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
246 self.execute_workers(
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
247 worker_func=worker_upload_delete_study_part,
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
248 worker_args=(self.o._root_url, here / "../../Database/Knee/T1", repeat_count, workers_count, ),
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
249 workers_count=workers_count)
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
250
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
251 elapsed = time.time() - start_time
593
f4f0e2d24a51 more pg-transactions tests
Alain Mazy <am@osimis.io>
parents: 592
diff changeset
252 print(f"TIMING test_upload_delete_same_study_from_multiple_threads with {workers_count} workers and {repeat_count}x repeat: {elapsed:.3f} s")
592
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
253
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
254 self.assertTrue(self.o.is_alive())
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
255
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
256 self.assertEqual(0, len(self.o.studies.get_all_ids()))
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
257 self.assertEqual(0, len(self.o.series.get_all_ids()))
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
258 self.assertEqual(0, len(self.o.instances.get_all_ids()))
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
259
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
260 stats = self.o.get_json("/statistics")
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
261 self.assertEqual(0, stats.get("CountPatients"))
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
262 self.assertEqual(0, stats.get("CountStudies"))
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
263 self.assertEqual(0, stats.get("CountSeries"))
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
264 self.assertEqual(0, stats.get("CountInstances"))
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
265 self.assertEqual(0, int(stats.get("TotalDiskSize")))
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
266 self.assertTrue(self.is_storage_empty(self._storage_name))
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
267
6753d96dd71f new concurrency tests
Alain Mazy <am@osimis.io>
parents:
diff changeset
268 # transfers + dicomweb