8
8
import shutil
9
9
import logging
10
10
import sys
11
+ import requests
11
12
12
13
pkg_root = os .path .abspath (os .path .join (os .path .dirname (__file__ ), '..' )) # noqa
13
14
sys .path .insert (0 , pkg_root ) # noqa
@@ -23,7 +24,7 @@ class IntegrationTest(unittest.TestCase):
23
24
def setUpClass (cls ):
24
25
# cwl
25
26
cls .cwl_dockstore_url = 'https://dockstore.org:8443/api/ga4gh/v2/tools/quay.io%2Fbriandoconnor%2Fdockstore-tool-md5sum/versions/master/plain-CWL/descriptor/%2FDockstore.cwl'
26
- cls .cwl_local_path = os .path .abspath ('testdata/md5sum.cwl' )
27
+ cls .cwl_local_path = "file://" + os .path .abspath ('testdata/md5sum.cwl' )
27
28
cls .cwl_json_input = "file://" + os .path .abspath ('testdata/md5sum.json' )
28
29
cls .cwl_attachments = ['file://' + os .path .abspath ('testdata/md5sum.input' ),
29
30
'file://' + os .path .abspath ('testdata/dockstore-tool-md5sum.cwl' )]
@@ -52,33 +53,37 @@ def tearDown(self):
52
53
time .sleep (3 )
53
54
except OSError as e :
54
55
print (e )
55
- if os .path .exists ('workflows' ):
56
- shutil .rmtree ('workflows' )
57
56
unittest .TestCase .tearDown (self )
58
57
59
58
def test_dockstore_md5sum (self ):
60
59
"""HTTP md5sum cwl (dockstore), run it on the wes-service server, and check for the correct output."""
61
- outfile_path , _ = self .run_md5sum (wf_input = self .cwl_dockstore_url ,
60
+ outfile_path , run_id = self .run_md5sum (wf_input = self .cwl_dockstore_url ,
62
61
json_input = self .cwl_json_input ,
63
62
workflow_attachment = self .cwl_attachments )
64
- self .assertTrue (check_for_file (outfile_path ), 'Output file was not found: ' + str (outfile_path ))
63
+ state = self .wait_for_finish (run_id )
64
+ self .check_complete (run_id )
65
+ self .assertTrue (self .check_for_file (outfile_path ), 'Output file was not found: ' + str (outfile_path ))
65
66
66
67
def test_local_md5sum (self ):
67
68
"""LOCAL md5sum cwl to the wes-service server, and check for the correct output."""
68
69
outfile_path , run_id = self .run_md5sum (wf_input = self .cwl_local_path ,
69
70
json_input = self .cwl_json_input ,
70
71
workflow_attachment = self .cwl_attachments )
71
- self .assertTrue (check_for_file (outfile_path ), 'Output file was not found: ' + str (outfile_path ))
72
+ state = self .wait_for_finish (run_id )
73
+ self .check_complete (run_id )
74
+ self .assertTrue (self .check_for_file (outfile_path ), 'Output file was not found: ' + str (outfile_path ))
72
75
73
76
def test_run_attachments (self ):
74
77
"""LOCAL md5sum cwl to the wes-service server, check for attachments."""
75
78
outfile_path , run_id = self .run_md5sum (wf_input = self .cwl_local_path ,
76
79
json_input = self .cwl_json_input ,
77
80
workflow_attachment = self .cwl_attachments )
78
81
get_response = self .client .get_run_log (run_id )["request" ]
79
- self .assertTrue (check_for_file (outfile_path ), 'Output file was not found: ' + get_response ["workflow_attachment" ])
82
+ state = self .wait_for_finish (run_id )
83
+ self .check_complete (run_id )
84
+ self .assertTrue (self .check_for_file (outfile_path ), 'Output file was not found: ' + get_response ["workflow_attachment" ])
80
85
attachment_tool_path = get_response ["workflow_attachment" ][7 :] + "/dockstore-tool-md5sum.cwl"
81
- self .assertTrue (check_for_file (attachment_tool_path ), 'Attachment file was not found: ' + get_response ["workflow_attachment" ])
86
+ self .assertTrue (self . check_for_file (attachment_tool_path ), 'Attachment file was not found: ' + get_response ["workflow_attachment" ])
82
87
83
88
def test_get_service_info (self ):
84
89
"""
@@ -90,7 +95,7 @@ def test_get_service_info(self):
90
95
assert 'workflow_type_versions' in r
91
96
assert 'supported_wes_versions' in r
92
97
assert 'supported_filesystem_protocols' in r
93
- assert 'engine_versions ' in r
98
+ assert 'workflow_engine_versions ' in r
94
99
95
100
def test_list_runs (self ):
96
101
"""
@@ -121,6 +126,37 @@ def run_md5sum(self, wf_input, json_input, workflow_attachment=None):
121
126
output_dir = os .path .abspath (os .path .join ('workflows' , response ['run_id' ], 'outdir' ))
122
127
return os .path .join (output_dir , 'md5sum.txt' ), response ['run_id' ]
123
128
129
+ def wait_for_finish (self , run_id , seconds = 120 ):
130
+ """Return True if a file exists within a certain amount of time."""
131
+ wait_counter = 0
132
+ r = self .client .get_run_status (run_id )
133
+ while r ["state" ] in ("QUEUED" , "INITIALIZING" , "RUNNING" ):
134
+ time .sleep (1 )
135
+ wait_counter += 1
136
+ if wait_counter > seconds :
137
+ return None
138
+ r = self .client .get_run_status (run_id )
139
+ return r ["state" ]
140
+
141
+ def check_complete (self , run_id ):
142
+ s = self .client .get_run_log (run_id )
143
+ if s ["state" ] != "COMPLETE" :
144
+ logging .info (str (s ["run_log" ]["stderr" ]))
145
+ if str (s ["run_log" ]["stderr" ]).startswith ("http" ):
146
+ logs = requests .get (s ["run_log" ]["stderr" ], headers = self .client .auth ).text
147
+ logging .info ("Run log:\n " + logs )
148
+ assert s ["state" ] == "COMPLETE"
149
+
150
+ def check_for_file (self , filepath , seconds = 120 ):
151
+ """Return True if a file exists within a certain amount of time."""
152
+ wait_counter = 0
153
+ while not os .path .exists (filepath ):
154
+ time .sleep (1 )
155
+ wait_counter += 1
156
+ if wait_counter > seconds :
157
+ return False
158
+ return True
159
+
124
160
125
161
def get_server_pids ():
126
162
try :
@@ -130,16 +166,6 @@ def get_server_pids():
130
166
return pids
131
167
132
168
133
- def check_for_file (filepath , seconds = 120 ):
134
- """Return True if a file exists within a certain amount of time."""
135
- wait_counter = 0
136
- while not os .path .exists (filepath ):
137
- time .sleep (1 )
138
- wait_counter += 1
139
- if wait_counter > seconds :
140
- return False
141
- return True
142
-
143
169
144
170
class CwltoolTest (IntegrationTest ):
145
171
"""Test using cwltool."""
@@ -149,9 +175,13 @@ def setUp(self):
149
175
Start a (local) wes-service server to make requests against.
150
176
Use cwltool as the wes-service server 'backend'.
151
177
"""
178
+ if os .path .exists ('workflows' ):
179
+ shutil .rmtree ('workflows' )
152
180
self .wes_server_process = subprocess .Popen (
153
- 'python {}' .format (os .path .abspath ('wes_service/wes_service_main.py' )),
154
- shell = True )
181
+ ['python' , os .path .abspath ('wes_service/wes_service_main.py' ),
182
+ '--backend=wes_service.cwl_runner' ,
183
+ '--port=8080' ,
184
+ '--debug' ])
155
185
time .sleep (5 )
156
186
157
187
@@ -176,8 +206,31 @@ def test_local_wdl(self):
176
206
outfile_path , run_id = self .run_md5sum (wf_input = self .wdl_local_path ,
177
207
json_input = self .wdl_json_input ,
178
208
workflow_attachment = self .wdl_attachments )
179
- self .assertTrue (check_for_file (outfile_path ), 'Output file was not found: ' + str (outfile_path ))
209
+ self .assertTrue (self .check_for_file (outfile_path ), 'Output file was not found: ' + str (outfile_path ))
210
+
211
+
212
+ class ArvadosTest (IntegrationTest ):
213
+ """Test using arvados-cwl-runner."""
214
+
215
+ def setUp (self ):
216
+ """
217
+ Start a (local) wes-service server to make requests against.
218
+ Use arvados-cwl-runner as the wes-service server 'backend'.
219
+ Requires ARVADOS_API_HOST and ARVADOS_API_TOKEN to be set in the environment.
220
+ """
221
+ if os .path .exists ('workflows' ):
222
+ shutil .rmtree ('workflows' )
223
+ self .wes_server_process = subprocess .Popen (
224
+ ['python' , os .path .abspath ('wes_service/wes_service_main.py' ),
225
+ '--backend=wes_service.arvados_wes' ,
226
+ '--port=8080' ,
227
+ '--debug' ])
228
+ self .client .auth = {"Authorization" : "Bearer " + os .environ ["ARVADOS_API_TOKEN" ]}
229
+ time .sleep (5 )
180
230
231
+ def check_for_file (self , filepath , seconds = 120 ):
232
+ # Doesn't make sense for arvados
233
+ return True
181
234
182
235
# Prevent pytest/unittest's discovery from attempting to discover the base test class.
183
236
del IntegrationTest
0 commit comments