Merge "Adding 2 node ixia generic scale-out test case generation"
[yardstick.git] / tests / unit / common / test_process.py
1 # Copyright (c) 2017 Intel Corporation
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #      http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 import unittest
15
16 import mock
17
18 from yardstick.common import process
19
20
21 class ProcessTestcase(unittest.TestCase):
22     def test_check_if_procces_failed_None(self):
23         p = mock.MagicMock(**{"exitcode": None, "name": "debug"})
24         process.check_if_process_failed(p)
25
26     def test_check_if_procces_failed_0(self):
27         p = mock.MagicMock(**{"exitcode": 0, "name": "debug"})
28         process.check_if_process_failed(p)
29
30     def test_check_if_procces_failed_1(self):
31         p = mock.MagicMock(**{"exitcode": 1, "name": "debug"})
32         with self.assertRaises(RuntimeError):
33             process.check_if_process_failed(p)
34
35
36 @mock.patch("yardstick.common.process.multiprocessing")
37 class TerminateChildrenTestcase(unittest.TestCase):
38     def test_some_children(self, mock_multiprocessing):
39         p1 = mock.MagicMock()
40         p2 = mock.MagicMock()
41         mock_multiprocessing.active_children.return_value = [p1, p2]
42         process.terminate_children()
43
44     def test_no_children(self, mock_multiprocessing):
45         mock_multiprocessing.active_children.return_value = []
46         process.terminate_children()