Mercurial > hg > orthanc-tests
annotate NewTests/Concurrency/test_transfer.py @ 610:ec657d1a62a6 Orthanc-1.12.3
fix compatibility with python3
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 31 Jan 2024 12:18:20 +0100 |
parents | d88b0fc15f08 |
children | a5882a40ccb6 |
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") |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
21 subprocess.run(["docker", "compose", "-f", "docker-compose-transfers-concurrency.yml", "down", "-v", "--remove-orphans"], check=True) |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
22 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
23 @classmethod |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
24 def compose_up(cls): |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
25 print("Pullling containers") |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
26 subprocess.run(["docker", "compose", "-f", "docker-compose-transfers-concurrency.yml", "pull"], check=True) |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
27 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
28 print("Compose up") |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
29 subprocess.run(["docker", "compose", "-f", "docker-compose-transfers-concurrency.yml", "up", "-d"], check=True) |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
30 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
31 @classmethod |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
32 def setUpClass(cls): |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
33 cls.cleanup() |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
34 cls.compose_up() |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
35 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
36 @classmethod |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
37 def tearDownClass(cls): |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
38 #cls.cleanup() |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
39 pass |
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 def clean_start(self): |
602 | 42 oa = OrthancApiClient("http://localhost:8062") |
43 ob = OrthancApiClient("http://localhost:8063") | |
601
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
44 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
45 oa.wait_started() |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
46 ob.wait_started() |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
47 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
48 oa.delete_all_content() |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
49 ob.delete_all_content() |
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 return oa, ob |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
52 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
53 def test_push(self): |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
54 oa, ob = self.clean_start() |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
55 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
56 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
|
57 populator.execute() |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
58 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
59 all_studies_ids = oa.studies.get_all_ids() |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
60 instances_count = oa.get_statistics().instances_count |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
61 disk_size = oa.get_statistics().total_disk_size |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
62 repeat_count = 2 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
63 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
64 for compression in [True, False]: |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
65 start_time = time.time() |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
66 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
67 for i in range(0, repeat_count): |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
68 oa.transfers.send(target_peer='b', |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
69 resources_ids=all_studies_ids, |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
70 resource_type=ResourceType.STUDY, |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
71 compress=compression) |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
72 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
73 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
|
74 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
|
75 ob.delete_all_content() |
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 elapsed = time.time() - start_time |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
78 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
|
79 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
80 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
81 def test_pull(self): |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
82 oa, ob = self.clean_start() |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
83 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
84 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
|
85 populator.execute() |
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 all_studies_ids = ob.studies.get_all_ids() |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
88 instances_count = ob.get_statistics().instances_count |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
89 disk_size = ob.get_statistics().total_disk_size |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
90 repeat_count = 2 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
91 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
92 for compression in [True, False]: |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
93 start_time = time.time() |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
94 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
95 for i in range(0, repeat_count): |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
96 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
|
97 resources_ids=all_studies_ids, |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
98 resource_type=ResourceType.STUDY, |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
99 compress=True) |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
100 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
|
101 job.wait_completed(polling_interval=0.1) |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
102 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
103 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
|
104 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
|
105 oa.delete_all_content() |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
106 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
107 |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
108 elapsed = time.time() - start_time |
3e15e950c462
new transfer tests in the concurrency section
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
109 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") |