Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_evaluate_with_launcher_error_on_stop(self, get_verdict, create_launcher):
get_verdict.return_value = "g"
launcher = Mock(stop=Mock(side_effect=errors.LauncherError))
create_launcher.return_value = Launcher(launcher)
build_infos = mockinfo()
result = self.runner.evaluate(build_infos)
# the LauncherError is silently ignore here
launcher.stop.assert_called_with()
self.assertEqual(result[0], "g")
def test_stop_fail(self):
launcher = MyLauncher("/foo/persist.zip")
launcher._stop = Mock(side_effect=Exception)
launcher.start()
with self.assertRaises(LauncherError):
launcher.stop()
def test_install_fail(self):
class FailingLauncher(MyLauncher):
def _install(self, dest):
raise Exception()
with self.assertRaises(LauncherError):
FailingLauncher("/foo/persist.zip")
def test__bisect_with_launcher_exception(self):
test_result = self.do__bisect(MyBuildData([1, 2, 3, 4, 5]), ["g", LauncherError("err")])
# check that set_build_range was called
self.handler.set_build_range.assert_has_calls(
[
# first call
call(MyBuildData([1, 2, 3, 4, 5])),
# we answered good
call(MyBuildData([3, 4, 5])),
# launcher exception, equivalent to a skip
call(MyBuildData([3, 5])),
]
)
# ensure that we called the handler's methods
self.handler.initialize.assert_called_with()
self.handler.build_good.assert_called_with(2, MyBuildData([3, 4, 5]))
self.handler.build_skip.assert_called_with(1)
self.assertTrue(self.handler.build_range.ensure_limits_called)
def finish(self, verdict):
if self.launcher:
try:
self.launcher.stop()
except LauncherError:
pass # silently pass stop process error
self.launcher.cleanup()
self.verdict = verdict
if verdict is not None:
self.evaluate_finished.emit()
if previous_verdict != "r" and build_info:
# if the last verdict was retry, do not download
# the build. Futhermore trying to download if we are
# in background download mode would stop the next builds
# from downloading.
index_promise, build_info = bisection.download_build(
index, allow_bg_download=allow_bg_download
)
if not build_info:
LOG.info("Unable to find build info. Skipping this build...")
verdict = "s"
else:
try:
verdict = bisection.evaluate(build_info)
except LauncherError as exc:
# we got an unrecoverable error while trying
# to run the tested app. We can just fallback
# to skip the build.
LOG.info("Error: %s. Skipping this build..." % exc)
verdict = "s"
finally:
# be sure to terminate the index_promise thread in all
# circumstances.
if index_promise:
index = index_promise()
previous_verdict = verdict
result = bisection.handle_verdict(index, verdict)
if result != bisection.RUNNING:
return result
def stop(self):
"""
Stop the application.
"""
if self._running:
self._stopping = True
try:
self._stop()
except Exception as e:
msg = "Unable to stop the application (error: {})".format(e)
LOG.error(msg)
raise LauncherError(msg).with_traceback(sys.exc_info()[2])
self._running = False
self._stopping = False
def start(self, **kwargs):
"""
Start the application.
"""
if not self._running:
try:
self._start(**kwargs)
except Exception as e:
msg = "Unable to start the application (error: {})".format(e)
LOG.error(msg)
raise LauncherError(msg).with_traceback(sys.exc_info()[2])
self._running = True
def __init__(self, dest, **kwargs):
self._running = False
self._stopping = False
try:
self._install(dest)
except Exception as e:
msg = "Unable to install {} (error: {})".format(dest, e)
LOG.error(msg)
raise LauncherError(msg).with_traceback(sys.exc_info()[2])