Skip to content

Commit

Permalink
Properly kill non-daemon Galaxy and fail if Galaxy couldn't be started
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdbeek committed Oct 1, 2018
1 parent 2334277 commit 978672b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
21 changes: 20 additions & 1 deletion tests/test_cmd_serve.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os
import time
import uuid
import psutil
import signal

from planemo import network_util
from planemo.galaxy import api
Expand All @@ -22,18 +24,34 @@
TEST_HISTORY_NAME = "Cool History 42"


def kill_process_on_port(port):
# based on https://stackoverflow.com/a/20691431
processes = []
for proc in psutil.process_iter():
try:
for conns in proc.connections(kind='inet'):
if conns.laddr.port == port:
proc.send_signal(signal.SIGTERM)
processes.append(proc)
continue
except Exception:
pass


class ServeTestCase(CliTestCase):

@skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS")
@mark.tests_galaxy_branch
def test_serve(self):
self._launch_thread_and_wait(self._run)
kill_process_on_port(self._port)

@skip_if_environ("PLANEMO_SKIP_GALAXY_TEST")
@skip_unless_executable("python3")
def test_serve_python3(self):
extra_args = ['--galaxy_python_version', '3', '--galaxy_branch', 'release_18.09']
self._launch_thread_and_wait(self._run, extra_args)
kill_process_on_port(self._port)

@skip_if_environ("PLANEMO_SKIP_GALAXY_TESTS")
@mark.tests_galaxy_branch
Expand Down Expand Up @@ -125,7 +143,8 @@ def _user_gi(self):
return user_gi

def _launch_thread_and_wait(self, func, args=[]):
launch_and_wait_for_galaxy(self._port, func, [args])
t = launch_and_wait_for_galaxy(self._port, func, [args])
t.join(timeout=10)

def _run_shed(self, serve_args=[]):
return self._run(serve_args=serve_args, serve_cmd="shed_serve")
Expand Down
3 changes: 2 additions & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,8 @@ def launch_and_wait_for_galaxy(port, func, args=[]):
t = threading.Thread(target=target)
t.daemon = True
t.start()
sleep("http://localhost:%d" % port, timeout=600)
if not sleep("http://localhost:%d" % port, timeout=600):
raise Exception('Galaxy failed to start')
return t


Expand Down

0 comments on commit 978672b

Please sign in to comment.