Merge "Bugfix: HA kill process recovery has a conflict"
[yardstick.git] / yardstick / tests / unit / benchmark / runner / test_duration.py
1 ##############################################################################
2 # Copyright (c) 2018 Nokia 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 import os
14
15 from yardstick.benchmark.runners import duration
16
17
18 class DurationRunnerTest(unittest.TestCase):
19     def setUp(self):
20         self.scenario_cfg = {
21             'runner': {'interval': 0, "duration": 0},
22             'type': 'some_type'
23         }
24
25     @mock.patch.object(os, 'getpid')
26     @mock.patch.object(multiprocessing, 'Process')
27     def test__run_benchmark_called_with(self, mock_multiprocessing_process,
28                                         mock_os_getpid):
29         mock_os_getpid.return_value = 101
30
31         runner = duration.DurationRunner({})
32         benchmark_cls = mock.Mock()
33         runner._run_benchmark(benchmark_cls, 'my_method', self.scenario_cfg,
34                               {})
35         mock_multiprocessing_process.assert_called_once_with(
36             name='Duration-some_type-101',
37             target=duration._worker_process,
38             args=(runner.result_queue, benchmark_cls, 'my_method',
39                   self.scenario_cfg, {}, runner.aborted, runner.output_queue))