From: Fred Date: Tue, 19 Feb 2013 06:08:55 +0000 (+0800) Subject: No need to kill mdk behat after tests X-Git-Tag: v0.3-beta~8 X-Git-Url: https://git.cameron1729.xyz/?a=commitdiff_plain;h=0c53053524fd0207967ccaf16efcbb9bafe457d0;p=mdk.git No need to kill mdk behat after tests --- diff --git a/lib/tools.py b/lib/tools.py index 15d69ec..f50b2dc 100644 --- a/lib/tools.py +++ b/lib/tools.py @@ -117,12 +117,26 @@ def stableBranch(version): class ProcessInThread(threading.Thread): """Executes a process in a separate thread""" - cli = None - loop = True + cmd = None + cwd = None + stdout = None + stderr = None + _kill = False - def __init__(self, cli): + def __init__(self, cmd, cwd=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE): threading.Thread.__init__(self) - self.cli = cli + if type(cmd) != 'list': + cmd = shlex.split(str(cmd)) + self.cmd = cmd + self.cwd = None + self.stdout = stdout + self.stderr = stderr + + def kill(self): + self._kill = True def run(self): - process(self.cli) + proc = subprocess.Popen(self.cmd, cwd=self.cwd, stdout=self.stdout, stderr=self.stderr) + while proc.poll(): + if self._kill: + proc.kill() diff --git a/moodle-behat.py b/moodle-behat.py index c6de9c1..edca598 100755 --- a/moodle-behat.py +++ b/moodle-behat.py @@ -114,11 +114,24 @@ try: seleniumServer.start() debug('Running Behat tests') + # Sleep for a few seconds before starting Behat if phpServer or seleniumServer: sleep(3) + # Running the tests process(cmd, M.path, None, None) + + # Kill the remaining processes + if phpServer: + phpServer.kill() + if seleniumServer: + seleniumServer.kill() + + # Remove the switch completely tag + if M.get('behat_switchcompletely'): + M.updateConfig('behat_switchcompletely', False) + else: debug('Behat command: %s' % (cmd))