From 4c98f9ad50f9dbb8d994dd554a6d61f662ccc9d1 Mon Sep 17 00:00:00 2001 From: Henrik Skupin Date: Wed, 4 Apr 2018 15:04:42 +0200 Subject: [PATCH] Bug 1451310 - [mozrunner] Catch exceptions when starting the client process. r=ahal If a ProcessHandler instance has been created, but mozprocess fails to start the child process, a dangling process_handler instance is attached to the runner instance. This should be avoided, and a RunnerNotStartedError has to be thrown. MozReview-Commit-ID: LgNFVaT9qVs --HG-- extra : rebase_source : c06aef08d7619ac9d3fe94ad29bdae06f0f79364 --- testing/mozbase/mozrunner/mozrunner/base/runner.py | 13 +++++++++++-- testing/mozbase/mozrunner/setup.py | 1 + 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/testing/mozbase/mozrunner/mozrunner/base/runner.py b/testing/mozbase/mozrunner/mozrunner/base/runner.py index e887331afffa..6c2a391b198b 100644 --- a/testing/mozbase/mozrunner/mozrunner/base/runner.py +++ b/testing/mozbase/mozrunner/mozrunner/base/runner.py @@ -17,6 +17,7 @@ try: import mozcrash except ImportError: mozcrash = None +from six import reraise from ..application import DefaultContext from ..errors import RunnerNotStartedError @@ -97,6 +98,8 @@ class BaseRunner(object): :param timeout: see process_handler.run() :param outputTimeout: see process_handler.run() :returns: the process id + + :raises: RunnerNotStartedError """ self.timeout = timeout self.output_timeout = outputTimeout @@ -126,8 +129,14 @@ class BaseRunner(object): # TODO: other arguments else: # this run uses the managed processhandler - self.process_handler = self.process_class(cmd, env=encoded_env, **self.process_args) - self.process_handler.run(self.timeout, self.output_timeout) + try: + process = self.process_class(cmd, env=encoded_env, **self.process_args) + process.run(self.timeout, self.output_timeout) + + self.process_handler = process + except Exception: + _, value, tb = sys.exc_info() + reraise(RunnerNotStartedError, "Failed to start the process: %s" % value, tb) self.crashed = 0 return self.process_handler.pid diff --git a/testing/mozbase/mozrunner/setup.py b/testing/mozbase/mozrunner/setup.py index 0d1def1a3b1f..58a8e540888e 100644 --- a/testing/mozbase/mozrunner/setup.py +++ b/testing/mozbase/mozrunner/setup.py @@ -18,6 +18,7 @@ deps = ['mozdevice >= 0.37', 'mozlog >= 3.0', 'mozprocess >= 0.23', 'mozprofile >= 0.18', + 'six >= 1.10.0', ] EXTRAS_REQUIRE = {'crash': ['mozcrash >= 1.0']}