diff options
author | cope.li <cope.li@huawei.com> | 2018-11-23 16:34:23 +0800 |
---|---|---|
committer | Emma Foley <emma.l.foley@intel.com> | 2018-12-13 14:54:23 +0000 |
commit | 337eab4eb00aab01f6f5b36523248ac792b99581 (patch) | |
tree | 474acbc3bfa909796aec54fe236cd58a5a2fa01e | |
parent | edb66ef37f9d89a783f3eda15d82d6fcebd7598e (diff) |
Add raise for iteration exception in IterationRunner
When we run the testcase, if there was a exception in iteration
_work_process, the process will still run on ,and the test result will
not affected by the exception.
JIRA: YARDSTICK-1555
Change-Id: I03803c0473015379bb0eb20ed7d474a2d923a4e3
Signed-off-by: cope.li <cope.li@huawei.com>
-rw-r--r-- | yardstick/benchmark/runners/iteration.py | 1 | ||||
-rw-r--r-- | yardstick/tests/unit/benchmark/runner/test_iteration.py | 45 |
2 files changed, 46 insertions, 0 deletions
diff --git a/yardstick/benchmark/runners/iteration.py b/yardstick/benchmark/runners/iteration.py index 4c88f3671..58ab06a32 100644 --- a/yardstick/benchmark/runners/iteration.py +++ b/yardstick/benchmark/runners/iteration.py @@ -96,6 +96,7 @@ def _worker_process(queue, cls, method_name, scenario_cfg, except Exception: # pylint: disable=broad-except errors = traceback.format_exc() LOG.exception("") + raise else: if result: # add timeout for put so we don't block test diff --git a/yardstick/tests/unit/benchmark/runner/test_iteration.py b/yardstick/tests/unit/benchmark/runner/test_iteration.py new file mode 100644 index 000000000..783b236f5 --- /dev/null +++ b/yardstick/tests/unit/benchmark/runner/test_iteration.py @@ -0,0 +1,45 @@ +############################################################################## +# Copyright (c) 2018 Huawei Technologies Co.,Ltd and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +import mock +import unittest +import multiprocessing +from yardstick.benchmark.runners import iteration +from yardstick.common import exceptions as y_exc + + +class IterationRunnerTest(unittest.TestCase): + def setUp(self): + self.scenario_cfg = { + 'runner': {'interval': 0, "duration": 0}, + 'type': 'some_type' + } + + self.benchmark = mock.Mock() + self.benchmark_cls = mock.Mock(return_value=self.benchmark) + + def _assert_defaults__worker_run_setup_and_teardown(self): + self.benchmark_cls.assert_called_once_with(self.scenario_cfg, {}) + self.benchmark.setup.assert_called_once() + + def _assert_defaults__worker_run_one_iteration(self): + self.benchmark.pre_run_wait_time.assert_called_once_with(0) + self.benchmark.my_method.assert_called_once_with({}) + + def test__worker_process_broad_exception(self): + self.benchmark.my_method = mock.Mock( + side_effect=y_exc.YardstickException) + + with self.assertRaises(Exception): + iteration._worker_process(mock.Mock(), self.benchmark_cls, 'my_method', + self.scenario_cfg, {}, + multiprocessing.Event(), mock.Mock()) + + self._assert_defaults__worker_run_one_iteration() + self._assert_defaults__worker_run_setup_and_teardown() |