88import shutil
99import logging
1010import sys
11+ import requests
1112
1213pkg_root = os .path .abspath (os .path .join (os .path .dirname (__file__ ), '..' )) # noqa
1314sys .path .insert (0 , pkg_root ) # noqa
@@ -23,7 +24,7 @@ class IntegrationTest(unittest.TestCase):
2324 def setUpClass (cls ):
2425 # cwl
2526 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' )
2728 cls .cwl_json_input = "file://" + os .path .abspath ('testdata/md5sum.json' )
2829 cls .cwl_attachments = ['file://' + os .path .abspath ('testdata/md5sum.input' ),
2930 'file://' + os .path .abspath ('testdata/dockstore-tool-md5sum.cwl' )]
@@ -52,33 +53,37 @@ def tearDown(self):
5253 time .sleep (3 )
5354 except OSError as e :
5455 print (e )
55- if os .path .exists ('workflows' ):
56- shutil .rmtree ('workflows' )
5756 unittest .TestCase .tearDown (self )
5857
5958 def test_dockstore_md5sum (self ):
6059 """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 ,
6261 json_input = self .cwl_json_input ,
6362 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 ))
6566
6667 def test_local_md5sum (self ):
6768 """LOCAL md5sum cwl to the wes-service server, and check for the correct output."""
6869 outfile_path , run_id = self .run_md5sum (wf_input = self .cwl_local_path ,
6970 json_input = self .cwl_json_input ,
7071 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 ))
7275
7376 def test_run_attachments (self ):
7477 """LOCAL md5sum cwl to the wes-service server, check for attachments."""
7578 outfile_path , run_id = self .run_md5sum (wf_input = self .cwl_local_path ,
7679 json_input = self .cwl_json_input ,
7780 workflow_attachment = self .cwl_attachments )
7881 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" ])
8085 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" ])
8287
8388 def test_get_service_info (self ):
8489 """
@@ -90,7 +95,7 @@ def test_get_service_info(self):
9095 assert 'workflow_type_versions' in r
9196 assert 'supported_wes_versions' in r
9297 assert 'supported_filesystem_protocols' in r
93- assert 'engine_versions ' in r
98+ assert 'workflow_engine_versions ' in r
9499
95100 def test_list_runs (self ):
96101 """
@@ -121,6 +126,37 @@ def run_md5sum(self, wf_input, json_input, workflow_attachment=None):
121126 output_dir = os .path .abspath (os .path .join ('workflows' , response ['run_id' ], 'outdir' ))
122127 return os .path .join (output_dir , 'md5sum.txt' ), response ['run_id' ]
123128
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+
124160
125161def get_server_pids ():
126162 try :
@@ -130,16 +166,6 @@ def get_server_pids():
130166 return pids
131167
132168
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-
143169
144170class CwltoolTest (IntegrationTest ):
145171 """Test using cwltool."""
@@ -149,9 +175,13 @@ def setUp(self):
149175 Start a (local) wes-service server to make requests against.
150176 Use cwltool as the wes-service server 'backend'.
151177 """
178+ if os .path .exists ('workflows' ):
179+ shutil .rmtree ('workflows' )
152180 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' ])
155185 time .sleep (5 )
156186
157187
@@ -176,8 +206,31 @@ def test_local_wdl(self):
176206 outfile_path , run_id = self .run_md5sum (wf_input = self .wdl_local_path ,
177207 json_input = self .wdl_json_input ,
178208 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 )
180230
231+ def check_for_file (self , filepath , seconds = 120 ):
232+ # Doesn't make sense for arvados
233+ return True
181234
182235# Prevent pytest/unittest's discovery from attempting to discover the base test class.
183236del IntegrationTest
0 commit comments