1 ##############################################################################
2 # Copyright (c) 2018 Huawei Technologies Co.,Ltd and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
12 import multiprocessing
13 from yardstick.benchmark.runners import iteration
14 from yardstick.common import exceptions as y_exc
17 class IterationRunnerTest(unittest.TestCase):
20 'runner': {'interval': 0, "duration": 0},
24 self.benchmark = mock.Mock()
25 self.benchmark_cls = mock.Mock(return_value=self.benchmark)
27 def _assert_defaults__worker_run_setup_and_teardown(self):
28 self.benchmark_cls.assert_called_once_with(self.scenario_cfg, {})
29 self.benchmark.setup.assert_called_once()
31 def _assert_defaults__worker_run_one_iteration(self):
32 self.benchmark.pre_run_wait_time.assert_called_once_with(0)
33 self.benchmark.my_method.assert_called_once_with({})
35 def test__worker_process_broad_exception(self):
36 self.benchmark.my_method = mock.Mock(
37 side_effect=y_exc.YardstickException)
39 with self.assertRaises(Exception):
40 iteration._worker_process(mock.Mock(), self.benchmark_cls, 'my_method',
41 self.scenario_cfg, {},
42 multiprocessing.Event(), mock.Mock())
44 self._assert_defaults__worker_run_one_iteration()
45 self._assert_defaults__worker_run_setup_and_teardown()