Merge "[docs] Update on Yardstick NSB installation"
[yardstick.git] / yardstick / tests / unit / benchmark / runner / test_iteration.py
1 ##############################################################################
2 # Copyright (c) 2018 Huawei Technologies Co.,Ltd and others.
3 #
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 ##############################################################################
9
10 import mock
11 import unittest
12 import multiprocessing
13 from yardstick.benchmark.runners import iteration
14 from yardstick.common import exceptions as y_exc
15
16
17 class IterationRunnerTest(unittest.TestCase):
18     def setUp(self):
19         self.scenario_cfg = {
20             'runner': {'interval': 0, "duration": 0},
21             'type': 'some_type'
22         }
23
24         self.benchmark = mock.Mock()
25         self.benchmark_cls = mock.Mock(return_value=self.benchmark)
26
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()
30
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({})
34
35     def test__worker_process_broad_exception(self):
36         self.benchmark.my_method = mock.Mock(
37             side_effect=y_exc.YardstickException)
38
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())
43
44         self._assert_defaults__worker_run_one_iteration()
45         self._assert_defaults__worker_run_setup_and_teardown()