changeset 598:b9ae7c59fee9

new concurrency test
author Alain Mazy <am@osimis.io>
date Wed, 10 Jan 2024 15:19:46 +0100
parents 0cbefe7369ee
children f3475c3e42e5
files NewTests/Concurrency/test_concurrency.py
diffstat 1 files changed, 48 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/NewTests/Concurrency/test_concurrency.py	Fri Dec 22 17:42:35 2023 +0100
+++ b/NewTests/Concurrency/test_concurrency.py	Wed Jan 10 15:19:46 2024 +0100
@@ -4,7 +4,9 @@
 import threading
 from helpers import OrthancTestCase, Helpers
 
-from orthanc_api_client import OrthancApiClient, generate_test_dicom_file, ChangeType
+from orthanc_api_client import OrthancApiClient, ChangeType
+from orthanc_api_client import helpers as OrthancHelpers
+
 from orthanc_tools import OrthancTestDbPopulator
 
 import pathlib
@@ -36,13 +38,33 @@
         instances_ids = []
 
         for i in range(0, len(all_files)):
-            if i % workers_count == worker_id:
+            if i % workers_count == worker_id:  # each thread takes a part
                 instances_ids.extend(o.upload_file(all_files[i]))
 
         for instance_id in instances_ids:
             o.instances.delete(orthanc_id=instance_id, ignore_errors=True)
 
 
+def worker_upload_delete_test_dicoms(orthanc_root_url: str, files_count: int, worker_id: int):
+    o = OrthancApiClient(orthanc_root_url)
+
+    instances_ids = []
+    counter = 0
+
+    for i in range(0, files_count):
+        counter += 1
+        dicom_file = OrthancHelpers.generate_test_dicom_file(width=4, height=4,
+                                                             tags = {
+                                                                 "PatientID" : f"{worker_id}",
+                                                                 "StudyInstanceUID" : f"{worker_id}",
+                                                                 "SeriesInstanceUID" : f"{worker_id}.{counter%10}"
+                                                             })
+        instances_ids.extend(o.upload(dicom_file))
+
+    study_id = o.instances.get_parent_study_id(instances_ids[0])
+    o.studies.delete(orthanc_id=study_id)
+
+
 class TestConcurrency(OrthancTestCase):
 
     @classmethod
@@ -248,7 +270,7 @@
         start_time = time.time()
         overall_repeat = 10
 
-        for i in range(0, 10):
+        for i in range(0, overall_repeat):
             workers_count = 5
             repeat_count = 3
 
@@ -265,4 +287,27 @@
         print(f"TIMING test_upload_delete_same_study_from_multiple_threads with {workers_count} workers and {repeat_count}x repeat ({overall_repeat}x): {elapsed:.3f} s")
 
 
+    def test_upload_multiple_studies_from_multiple_threads(self):
+        self.o.delete_all_content()
+        self.clear_storage(storage_name=self._storage_name)
+
+        start_time = time.time()
+        overall_repeat = 3
+
+        for i in range(0, overall_repeat):
+            files_count = 25
+            workers_count = 10
+
+            # massively upload and delete all studies from the test detabase.  Each worker is writing all instances from a folder and then deletes them.
+            # This test is only measuring performances.
+            self.execute_workers(
+                worker_func=worker_upload_delete_test_dicoms,
+                worker_args=(self.o._root_url, files_count, ),
+                workers_count=workers_count)
+
+            self.check_is_empty()
+
+        elapsed = time.time() - start_time
+        print(f"TIMING test_upload_multiple_studies_from_multiple_threads with {workers_count} workers and {files_count} files and repeat {overall_repeat}x: {elapsed:.3f} s")
+
     # transfers + dicomweb
\ No newline at end of file