88import signal
99import requests
1010import shutil
11+ import logging
12+
13+ logging .basicConfig (level = logging .INFO )
1114
1215
1316class IntegrationTest (unittest .TestCase ):
1417 """A baseclass that's inherited for use with different cwl backends."""
15-
1618 def setUp (self ):
1719 """Start a (local) wes-service server to make requests against."""
1820 raise NotImplementedError
@@ -27,42 +29,40 @@ def tearDown(self):
2729 time .sleep (3 )
2830 except OSError as e :
2931 print (e )
30-
32+ if os .path .exists ('workflows' ):
33+ shutil .rmtree ('workflows' )
3134 unittest .TestCase .tearDown (self )
3235
3336 def test_dockstore_md5sum (self ):
3437 """Fetch the md5sum cwl from dockstore, run it on the wes-service server, and check for the correct output."""
3538 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 )
3740
3841 self .assertTrue (check_for_file (output_filepath ), 'Output file was not found: ' + str (output_filepath ))
39- shutil .rmtree ('workflows' )
4042
4143 def test_local_md5sum (self ):
4244 """Pass a local md5sum cwl to the wes-service server, and check for the correct output."""
4345 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 )
4547
4648 self .assertTrue (check_for_file (output_filepath ), 'Output file was not found: ' + str (output_filepath ))
47- shutil .rmtree ('workflows' )
4849
4950 def test_multipart_upload (self ):
5051 """Pass a local md5sum cwl to the wes-service server, and check for uploaded file in service."""
5152 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 )
5354
5455 get_response = get_log_request (run_id )["request" ]
5556
5657 self .assertTrue (check_for_file (get_response ["workflow_url" ][7 :]), 'Output file was not found: '
5758 + get_response ["workflow_url" ][:7 ])
58- shutil .rmtree ('workflows' )
5959
6060
61- def run_md5sum (cwl_input ):
61+ def run_cwl_md5sum (cwl_input ):
6262 """Pass a local md5sum cwl to the wes-service server, and return the path of the output file that was created."""
6363 endpoint = 'http://localhost:8080/ga4gh/wes/v1/runs'
6464 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' }}
6666
6767 parts = [("workflow_params" , json .dumps (params )), ("workflow_type" , "CWL" ), ("workflow_type_version" , "v1.0" )]
6868 if cwl_input .startswith ("file://" ):
@@ -75,6 +75,25 @@ def run_md5sum(cwl_input):
7575 return os .path .join (output_dir , 'md5sum.txt' ), response ['run_id' ]
7676
7777
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+
7897def get_log_request (run_id ):
7998 endpoint = 'http://localhost:8080/ga4gh/wes/v1/runs/{}' .format (run_id )
8099 return requests .get (endpoint ).json ()
@@ -88,7 +107,7 @@ def get_server_pids():
88107 return pids
89108
90109
91- def check_for_file (filepath , seconds = 20 ):
110+ def check_for_file (filepath , seconds = 40 ):
92111 """Return True if a file exists within a certain amount of time."""
93112 wait_counter = 0
94113 while not os .path .exists (filepath ):
@@ -117,14 +136,12 @@ def setUp(self):
117136
118137class ToilTest (IntegrationTest ):
119138 """Test using Toil."""
120-
121139 def setUp (self ):
122140 """
123141 Start a (local) wes-service server to make requests against.
124142 Use toil as the wes-service server 'backend'.
125143 """
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"'
128145 '' .format (os .path .abspath ('wes_service/wes_service_main.py' )),
129146 shell = True )
130147 time .sleep (5 )
0 commit comments