annotate Tests/CheckZipStreams.py @ 687:edf6ce075823

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