annotate Tests/CheckZipStreams.py @ 648:810390d3968a large-queries

new hk2 tests
author Alain Mazy <am@orthanc.team>
date Tue, 21 May 2024 17:10:27 +0200
parents 9f8276ac1cdd
children 5d7b6e43ab7d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
610
ec657d1a62a6 fix compatibility with python3
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 511
diff changeset
1 #!/usr/bin/env python3
404
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 # Orthanc - A Lightweight, RESTful DICOM Store
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 # Department, University Hospital of Liege, Belgium
640
9f8276ac1cdd update year to 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 610
diff changeset
6 # Copyright (C) 2017-2024 Osimis S.A., Belgium
9f8276ac1cdd update year to 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 610
diff changeset
7 # Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
404
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 #
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 # This program is free software: you can redistribute it and/or
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 # modify it under the terms of the GNU General Public License as
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 # published by the Free Software Foundation, either version 3 of the
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 # License, or (at your option) any later version.
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 #
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 # This program is distributed in the hope that it will be useful, but
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 # General Public License for more details.
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 #
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 # You should have received a copy of the GNU General Public License
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 import Toolbox
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 import json
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 import os
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 import subprocess
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 import sys
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 import time
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 import zipfile
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 import multiprocessing
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 import threading
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 import queue
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 if len(sys.argv) != 3:
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 print('Must provide a path to Orthanc binaries and to a sample ZIP archive with one DICOM study')
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 exit(-1)
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 if not os.path.isfile(sys.argv[1]):
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 raise Exception('Inexistent path: %s' % sys.argv[1])
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 if not os.path.isfile(sys.argv[2]):
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 raise Exception('Inexistent path: %s' % sys.argv[2])
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 TMP = '/tmp/OrthancTest'
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 CONFIG = os.path.join(TMP, 'Configuration.json')
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 if os.path.exists(TMP):
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 print('Temporary path already exists: %s' % TMP)
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 exit(-1)
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 os.mkdir(TMP)
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 ORTHANC = Toolbox.DefineOrthanc(username = 'orthanc',
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 password = 'orthanc')
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 def GetArchive(config, testFunction):
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 with open(CONFIG, 'w') as f:
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 f.write(json.dumps(config))
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 process = subprocess.Popen(
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 [ sys.argv[1], CONFIG, '--no-jobs' ],
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 cwd = TMP,
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 #stdout=subprocess.PIPE,
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 stderr=subprocess.PIPE,
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 #shell=True
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 )
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 #time.sleep(1)
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 while True:
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 try:
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 system = Toolbox.DoGet(ORTHANC, '/system')
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 break
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 except:
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 time.sleep(0.1)
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 try:
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 with open(sys.argv[2], 'rb') as f:
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 Toolbox.DoPost(ORTHANC, '/instances', f.read())
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 studies = Toolbox.DoGet(ORTHANC, '/studies')
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 if len(studies) != 1:
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 raise Exception('More than one study is available in Orthanc')
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 testFunction(ORTHANC, studies[0])
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 finally:
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 process.terminate()
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 process.wait()
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 def Assert(b):
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 if not b:
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 raise Exception('Bad result')
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 for streaming in [ False, True, None ]:
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 if streaming == True:
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 suffix = 'with streaming'
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 config = { 'SynchronousZipStream' : True }
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 elif streaming == False:
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 suffix = 'without streaming'
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 config = { 'SynchronousZipStream' : False }
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 else:
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 suffix = 'default streaming'
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 config = { }
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 print('==== SIMPLE TEST - %s ====' % suffix)
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 def test(ORTHANC, study):
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 instances = Toolbox.DoGet(ORTHANC, '/instances')
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 z = Toolbox.ParseArchive(Toolbox.DoGet(ORTHANC, '/studies/%s/archive' % study))
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 Assert(len(instances) == len(z.namelist()))
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 GetArchive(config, test)
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 print('==== CANCEL SERVER JOB - %s ====' % suffix)
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 def TestCancelServerJob(ORTHANC, study):
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 def CheckCorruptedArchive(queue):
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 try:
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 z = Toolbox.DoGet(ORTHANC, '/studies/%s/archive' % study)
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 Assert(streaming == True or streaming == None)
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 try:
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 Toolbox.ParseArchive(z)
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 print('error, got valid archive')
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 queue.put(False) # The archive is not corrupted as expected
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 except zipfile.BadZipfile as e:
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 print('ok, got corrupted archive')
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 queue.put(True)
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 except Exception as e:
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 Assert(streaming == False)
610
ec657d1a62a6 fix compatibility with python3
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 511
diff changeset
139 Assert(e.args[0] == 500) # HTTP status code 500
404
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 print('ok, got none archive')
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 queue.put(True)
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 def cancel():
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 while True:
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 j = Toolbox.DoGet(ORTHANC, '/jobs?expand')
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 Assert(len(j) <= 1)
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 if len(j) == 1:
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 Assert(j[0]['State'] == 'Running')
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 Toolbox.DoPost(ORTHANC, '/jobs/%s/cancel' % j[0]['ID'], {})
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 return
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 time.sleep(.01)
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 q = queue.Queue()
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 t1 = threading.Thread(target=cancel)
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 t2 = threading.Thread(target=CheckCorruptedArchive, args=(q,))
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 t1.start()
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 t2.start()
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 t1.join()
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 t2.join()
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 Assert(q.get() == True)
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 GetArchive(config, TestCancelServerJob)
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 print('==== CANCEL HTTP CLIENT - %s ====' % suffix)
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 def TestCancelHttpClient(ORTHANC, study):
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 def DownloadArchive(queue):
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 z = Toolbox.DoGet(ORTHANC, '/studies/%s/archive' % study)
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 queue.put('success')
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 q = multiprocessing.Queue()
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 p = multiprocessing.Process(target=DownloadArchive, args=(q, ))
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 p.start()
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 time.sleep(0.05)
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 p.terminate()
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 p.join()
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 Assert(q.qsize() == 0)
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 while True:
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 j = Toolbox.DoGet(ORTHANC, '/jobs?expand')
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 Assert(len(j) == 1)
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 if j[0]['State'] == 'Running':
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 continue
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 else:
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 if streaming == False:
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 # The sending of the temporary file is *not* part
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 # of the job in this case
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 Assert(j[0]['State'] == 'Success')
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 else:
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 Assert(j[0]['State'] == 'Failure')
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 Assert(j[0]['ErrorCode'] == 14) # Cannot write to file
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 break
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 GetArchive(config, TestCancelHttpClient)
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197
931be0125954 Tests/CheckZipStreams.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 print('Success!')