8
8
import signal
9
9
import requests
10
10
import shutil
11
+ import logging
12
+
13
+ logging .basicConfig (level = logging .INFO )
11
14
12
15
13
16
class IntegrationTest (unittest .TestCase ):
14
17
"""A baseclass that's inherited for use with different cwl backends."""
15
-
16
18
def setUp (self ):
17
19
"""Start a (local) wes-service server to make requests against."""
18
20
raise NotImplementedError
@@ -27,42 +29,40 @@ def tearDown(self):
27
29
time .sleep (3 )
28
30
except OSError as e :
29
31
print (e )
30
-
32
+ if os .path .exists ('workflows' ):
33
+ shutil .rmtree ('workflows' )
31
34
unittest .TestCase .tearDown (self )
32
35
33
36
def test_dockstore_md5sum (self ):
34
37
"""Fetch the md5sum cwl from dockstore, run it on the wes-service server, and check for the correct output."""
35
38
cwl_dockstore_url = 'https://dockstore.org:8443/api/ga4gh/v2/tools/quay.io%2Fbriandoconnor%2Fdockstore-tool-md5sum/versions/master/plain-CWL/descriptor/%2FDockstore.cwl'
36
- output_filepath , _ = run_md5sum (cwl_input = cwl_dockstore_url )
39
+ output_filepath , _ = run_cwl_md5sum (cwl_input = cwl_dockstore_url )
37
40
38
41
self .assertTrue (check_for_file (output_filepath ), 'Output file was not found: ' + str (output_filepath ))
39
- shutil .rmtree ('workflows' )
40
42
41
43
def test_local_md5sum (self ):
42
44
"""Pass a local md5sum cwl to the wes-service server, and check for the correct output."""
43
45
cwl_local_path = os .path .abspath ('testdata/md5sum.cwl' )
44
- output_filepath , _ = run_md5sum (cwl_input = 'file://' + cwl_local_path )
46
+ output_filepath , _ = run_cwl_md5sum (cwl_input = 'file://' + cwl_local_path )
45
47
46
48
self .assertTrue (check_for_file (output_filepath ), 'Output file was not found: ' + str (output_filepath ))
47
- shutil .rmtree ('workflows' )
48
49
49
50
def test_multipart_upload (self ):
50
51
"""Pass a local md5sum cwl to the wes-service server, and check for uploaded file in service."""
51
52
cwl_local_path = os .path .abspath ('testdata/md5sum.cwl' )
52
- _ , run_id = run_md5sum (cwl_input = 'file://' + cwl_local_path )
53
+ _ , run_id = run_cwl_md5sum (cwl_input = 'file://' + cwl_local_path )
53
54
54
55
get_response = get_log_request (run_id )["request" ]
55
56
56
57
self .assertTrue (check_for_file (get_response ["workflow_url" ][7 :]), 'Output file was not found: '
57
58
+ get_response ["workflow_url" ][:7 ])
58
- shutil .rmtree ('workflows' )
59
59
60
60
61
- def run_md5sum (cwl_input ):
61
+ def run_cwl_md5sum (cwl_input ):
62
62
"""Pass a local md5sum cwl to the wes-service server, and return the path of the output file that was created."""
63
63
endpoint = 'http://localhost:8080/ga4gh/wes/v1/runs'
64
64
params = {'output_file' : {'path' : '/tmp/md5sum.txt' , 'class' : 'File' },
65
- 'input_file' : {'path' : '../../ testdata/md5sum.input' , 'class' : 'File' }}
65
+ 'input_file' : {'path' : os . path . abspath ( ' testdata/md5sum.input') , 'class' : 'File' }}
66
66
67
67
parts = [("workflow_params" , json .dumps (params )), ("workflow_type" , "CWL" ), ("workflow_type_version" , "v1.0" )]
68
68
if cwl_input .startswith ("file://" ):
@@ -75,6 +75,25 @@ def run_md5sum(cwl_input):
75
75
return os .path .join (output_dir , 'md5sum.txt' ), response ['run_id' ]
76
76
77
77
78
+ def run_wdl_md5sum (wdl_input ):
79
+ """Pass a local md5sum wdl to the wes-service server, and return the path of the output file that was created."""
80
+ endpoint = 'http://localhost:8080/ga4gh/wes/v1/workflows'
81
+ params = '{"ga4ghMd5.inputFile": "' + os .path .abspath ('testdata/md5sum.input' ) + '"}'
82
+ parts = [("workflow_params" , params ),
83
+ ("workflow_type" , "WDL" ),
84
+ ("workflow_type_version" , "v1.0" ),
85
+ ("workflow_url" , wdl_input )]
86
+ response = requests .post (endpoint , files = parts ).json ()
87
+ output_dir = os .path .abspath (os .path .join ('workflows' , response ['workflow_id' ], 'outdir' ))
88
+ check_travis_log = os .path .join (output_dir , 'stderr' )
89
+ with open (check_travis_log , 'r' ) as f :
90
+ logging .info (f .read ())
91
+ logging .info (subprocess .check_output (['ls' , os .path .join ('workflows' , response ['workflow_id' ])]))
92
+ logging .info ('\n ' )
93
+ logging .info (subprocess .check_output (['ls' , output_dir ]))
94
+ return os .path .join (output_dir , 'md5sum.txt' ), response ['workflow_id' ]
95
+
96
+
78
97
def get_log_request (run_id ):
79
98
endpoint = 'http://localhost:8080/ga4gh/wes/v1/runs/{}' .format (run_id )
80
99
return requests .get (endpoint ).json ()
@@ -88,7 +107,7 @@ def get_server_pids():
88
107
return pids
89
108
90
109
91
- def check_for_file (filepath , seconds = 20 ):
110
+ def check_for_file (filepath , seconds = 40 ):
92
111
"""Return True if a file exists within a certain amount of time."""
93
112
wait_counter = 0
94
113
while not os .path .exists (filepath ):
@@ -117,14 +136,12 @@ def setUp(self):
117
136
118
137
class ToilTest (IntegrationTest ):
119
138
"""Test using Toil."""
120
-
121
139
def setUp (self ):
122
140
"""
123
141
Start a (local) wes-service server to make requests against.
124
142
Use toil as the wes-service server 'backend'.
125
143
"""
126
- self .wes_server_process = subprocess .Popen ('python {} '
127
- '--opt runner=cwltoil --opt extra=--logLevel=CRITICAL'
144
+ self .wes_server_process = subprocess .Popen ('python {} --backend=wes_service.toil_wes --opt="extra=--logLevel=CRITICAL"'
128
145
'' .format (os .path .abspath ('wes_service/wes_service_main.py' )),
129
146
shell = True )
130
147
time .sleep (5 )
0 commit comments