Mercurial > hg > orthanc-tests
annotate NewTests/Concurrency/test_transfer.py @ 700:8561d9c88d1a
fix
author | Alain Mazy <am@orthanc.team> |
---|---|
date | Thu, 26 Sep 2024 12:27:52 +0200 |
parents | b50b6acc1206 |
children | 765446710507 33e8cb8511ca |
rev | line source |
---|---|
601
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
1 import subprocess |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
2 import time |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
3 import unittest |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
4 from orthanc_api_client import OrthancApiClient, ResourceType |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
5 from orthanc_tools import OrthancTestDbPopulator |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
6 from helpers import Helpers, wait_container_healthy |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
7 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
8 import pathlib |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
9 import os |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
10 here = pathlib.Path(__file__).parent.resolve() |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
11 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
12 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
13 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
14 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
15 class TestConcurrencyTransfers(unittest.TestCase): |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
16 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
17 @classmethod |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
18 def cleanup(cls): |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
19 os.chdir(here) |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
20 print("Cleaning old compose") |
627 | 21 subprocesss_env = os.environ.copy() |
22 subprocesss_env["ORTHANC_IMAGE_UNDER_TESTS"] = Helpers.orthanc_under_tests_docker_image | |
616
a5882a40ccb6
rename osimis/orthanc to orthancteam/orthanc
Alain Mazy <am@osimis.io>
parents:
602
diff
changeset
|
23 subprocess.run(["docker", "compose", "-f", "docker-compose-transfers-concurrency.yml", "down", "-v", "--remove-orphans"], |
627 | 24 env=subprocesss_env, check=True) |
601
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
25 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
26 @classmethod |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
27 def compose_up(cls): |
616
a5882a40ccb6
rename osimis/orthanc to orthancteam/orthanc
Alain Mazy <am@osimis.io>
parents:
602
diff
changeset
|
28 # print("Pullling containers") |
627 | 29 # subprocesss_env = os.environ.copy() |
30 # subprocesss_env["ORTHANC_IMAGE_UNDER_TESTS"] = Helpers.orthanc_under_tests_docker_image | |
31 # subprocess.run(["docker", "compose", "-f", "docker-compose-transfers-concurrency.yml", "pull"], | |
32 # env=subprocesss_env, check=True) | |
601
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
33 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
34 print("Compose up") |
627 | 35 subprocesss_env = os.environ.copy() |
36 subprocesss_env["ORTHANC_IMAGE_UNDER_TESTS"] = Helpers.orthanc_under_tests_docker_image | |
616
a5882a40ccb6
rename osimis/orthanc to orthancteam/orthanc
Alain Mazy <am@osimis.io>
parents:
602
diff
changeset
|
37 subprocess.run(["docker", "compose", "-f", "docker-compose-transfers-concurrency.yml", "up", "-d"], |
627 | 38 env=subprocesss_env, check=True) |
39 | |
601
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
40 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
41 @classmethod |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
42 def setUpClass(cls): |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
43 cls.cleanup() |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
44 cls.compose_up() |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
45 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
46 @classmethod |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
47 def tearDownClass(cls): |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
48 #cls.cleanup() |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
49 pass |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
50 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
51 def clean_start(self): |
602 | 52 oa = OrthancApiClient("http://localhost:8062") |
53 ob = OrthancApiClient("http://localhost:8063") | |
601
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
54 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
55 oa.wait_started() |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
56 ob.wait_started() |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
57 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
58 oa.delete_all_content() |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
59 ob.delete_all_content() |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
60 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
61 return oa, ob |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
62 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
63 def test_push(self): |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
64 oa, ob = self.clean_start() |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
65 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
66 populator = OrthancTestDbPopulator(oa, studies_count=5, random_seed=65) |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
67 populator.execute() |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
68 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
69 all_studies_ids = oa.studies.get_all_ids() |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
70 instances_count = oa.get_statistics().instances_count |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
71 disk_size = oa.get_statistics().total_disk_size |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
72 repeat_count = 2 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
73 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
74 for compression in [True, False]: |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
75 start_time = time.time() |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
76 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
77 for i in range(0, repeat_count): |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
78 oa.transfers.send(target_peer='b', |
671 | 79 resources_ids=all_studies_ids, |
80 resource_type=ResourceType.STUDY, | |
81 compress=compression) | |
601
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
82 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
83 self.assertEqual(instances_count, ob.get_statistics().instances_count) |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
84 self.assertEqual(disk_size, ob.get_statistics().total_disk_size) |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
85 ob.delete_all_content() |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
86 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
87 elapsed = time.time() - start_time |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
88 print(f"TIMING test_push (compression={compression}) with {instances_count} instances for a total of {disk_size/(1024*1024)} MB (repeat {repeat_count}x): {elapsed:.3f} s") |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
89 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
90 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
91 def test_pull(self): |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
92 oa, ob = self.clean_start() |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
93 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
94 populator = OrthancTestDbPopulator(ob, studies_count=5, random_seed=65) |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
95 populator.execute() |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
96 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
97 all_studies_ids = ob.studies.get_all_ids() |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
98 instances_count = ob.get_statistics().instances_count |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
99 disk_size = ob.get_statistics().total_disk_size |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
100 repeat_count = 2 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
101 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
102 for compression in [True, False]: |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
103 start_time = time.time() |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
104 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
105 for i in range(0, repeat_count): |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
106 remote_job = ob.transfers.send_async(target_peer='a', |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
107 resources_ids=all_studies_ids, |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
108 resource_type=ResourceType.STUDY, |
622 | 109 compress=compression) |
601
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
110 job = oa.jobs.get(orthanc_id=remote_job.remote_job_id) |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
111 job.wait_completed(polling_interval=0.1) |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
112 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
113 self.assertEqual(instances_count, oa.get_statistics().instances_count) |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
114 self.assertEqual(disk_size, oa.get_statistics().total_disk_size) |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
115 oa.delete_all_content() |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
116 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
117 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
118 elapsed = time.time() - start_time |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
119 print(f"TIMING test_pull (compression={compression}) with {instances_count} instances for a total of {disk_size/(1024*1024)} MB (repeat {repeat_count}x): {elapsed:.3f} s") |