diff options
author | Volodymyr Mytnyk <volodymyrx.mytnyk@intel.com> | 2019-01-30 13:18:22 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2019-01-30 13:18:22 +0000 |
commit | 9c1f115a5e6d6d47bc755da118e7b7f214351849 (patch) | |
tree | 32503668295bf615cae75e237931a0ae66156fd7 /yardstick/tests/unit/benchmark/runner | |
parent | 496777fc241939e9d9f1c592a94e24df621c0f2b (diff) | |
parent | 679b6d94288d801e84c0f22c6c0d712c08eb8458 (diff) |
Merge "NSB sync: clean-up draft IPC implementation (part 1)"
Diffstat (limited to 'yardstick/tests/unit/benchmark/runner')
-rw-r--r-- | yardstick/tests/unit/benchmark/runner/test_base.py | 56 | ||||
-rw-r--r-- | yardstick/tests/unit/benchmark/runner/test_iteration_ipc.py | 136 |
2 files changed, 0 insertions, 192 deletions
diff --git a/yardstick/tests/unit/benchmark/runner/test_base.py b/yardstick/tests/unit/benchmark/runner/test_base.py index 49ba1efe4..559c991f3 100644 --- a/yardstick/tests/unit/benchmark/runner/test_base.py +++ b/yardstick/tests/unit/benchmark/runner/test_base.py @@ -8,17 +8,12 @@ ############################################################################## import time -import uuid import mock -from oslo_config import cfg -import oslo_messaging import subprocess from yardstick.benchmark.runners import base as runner_base from yardstick.benchmark.runners import iteration -from yardstick.common import messaging -from yardstick.common.messaging import payloads from yardstick.tests.unit import base as ut_base @@ -99,54 +94,3 @@ class RunnerTestCase(ut_base.BaseUnitTestCase): with self.assertRaises(NotImplementedError): runner._run_benchmark(mock.Mock(), mock.Mock(), mock.Mock(), mock.Mock()) - - -class RunnerProducerTestCase(ut_base.BaseUnitTestCase): - - @mock.patch.object(oslo_messaging, 'Target', return_value='rpc_target') - @mock.patch.object(oslo_messaging, 'RPCClient') - @mock.patch.object(oslo_messaging, 'get_rpc_transport', - return_value='rpc_transport') - @mock.patch.object(cfg, 'CONF') - def test__init(self, mock_config, mock_transport, mock_rpcclient, - mock_target): - _id = uuid.uuid1().int - runner_producer = runner_base.RunnerProducer(_id) - mock_transport.assert_called_once_with( - mock_config, url='rabbit://yardstick:yardstick@localhost:5672/') - mock_target.assert_called_once_with(topic=messaging.TOPIC_RUNNER, - fanout=True, - server=messaging.SERVER) - mock_rpcclient.assert_called_once_with('rpc_transport', 'rpc_target') - self.assertEqual(_id, runner_producer._id) - self.assertEqual(messaging.TOPIC_RUNNER, runner_producer._topic) - - @mock.patch.object(oslo_messaging, 'Target', return_value='rpc_target') - @mock.patch.object(oslo_messaging, 'RPCClient') - @mock.patch.object(oslo_messaging, 'get_rpc_transport', - return_value='rpc_transport') - @mock.patch.object(payloads, 'RunnerPayload', return_value='runner_pload') - def test_start_iteration(self, mock_runner_payload, *args): - runner_producer = runner_base.RunnerProducer(uuid.uuid1().int) - with mock.patch.object(runner_producer, - 'send_message') as mock_message: - runner_producer.start_iteration(version=10) - - mock_message.assert_called_once_with( - messaging.RUNNER_METHOD_START_ITERATION, 'runner_pload') - mock_runner_payload.assert_called_once_with(version=10, data={}) - - @mock.patch.object(oslo_messaging, 'Target', return_value='rpc_target') - @mock.patch.object(oslo_messaging, 'RPCClient') - @mock.patch.object(oslo_messaging, 'get_rpc_transport', - return_value='rpc_transport') - @mock.patch.object(payloads, 'RunnerPayload', return_value='runner_pload') - def test_stop_iteration(self, mock_runner_payload, *args): - runner_producer = runner_base.RunnerProducer(uuid.uuid1().int) - with mock.patch.object(runner_producer, - 'send_message') as mock_message: - runner_producer.stop_iteration(version=15) - - mock_message.assert_called_once_with( - messaging.RUNNER_METHOD_STOP_ITERATION, 'runner_pload') - mock_runner_payload.assert_called_once_with(version=15, data={}) diff --git a/yardstick/tests/unit/benchmark/runner/test_iteration_ipc.py b/yardstick/tests/unit/benchmark/runner/test_iteration_ipc.py deleted file mode 100644 index 10d14a8a0..000000000 --- a/yardstick/tests/unit/benchmark/runner/test_iteration_ipc.py +++ /dev/null @@ -1,136 +0,0 @@ -# Copyright (c) 2018 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import multiprocessing -import time -import os -import uuid - -import mock - -from yardstick.benchmark.runners import iteration_ipc -from yardstick.common import messaging -from yardstick.common.messaging import payloads -from yardstick.tests.unit import base as ut_base - - -class RunnerIterationIPCEndpointTestCase(ut_base.BaseUnitTestCase): - - def setUp(self): - self._id = uuid.uuid1().int - self._ctx_ids = [uuid.uuid1().int, uuid.uuid1().int] - self._queue = multiprocessing.Queue() - self.runner = iteration_ipc.RunnerIterationIPCEndpoint( - self._id, self._ctx_ids, self._queue) - self._kwargs = {'version': 1, 'iteration': 10, 'kpi': {}} - self._pload_dict = payloads.TrafficGeneratorPayload.dict_to_obj( - self._kwargs).obj_to_dict() - - def test_tg_method_started(self): - self._queue.empty() - ctxt = {'id': self._ctx_ids[0]} - self.runner.tg_method_started(ctxt, **self._kwargs) - time.sleep(0.2) - - output = [] - while not self._queue.empty(): - output.append(self._queue.get(True, 1)) - - self.assertEqual(1, len(output)) - self.assertEqual(self._ctx_ids[0], output[0]['id']) - self.assertEqual(messaging.TG_METHOD_STARTED, output[0]['action']) - self.assertEqual(self._pload_dict, output[0]['payload'].obj_to_dict()) - - def test_tg_method_finished(self): - self._queue.empty() - ctxt = {'id': self._ctx_ids[0]} - self.runner.tg_method_finished(ctxt, **self._kwargs) - time.sleep(0.2) - - output = [] - while not self._queue.empty(): - output.append(self._queue.get(True, 1)) - - self.assertEqual(1, len(output)) - self.assertEqual(self._ctx_ids[0], output[0]['id']) - self.assertEqual(messaging.TG_METHOD_FINISHED, output[0]['action']) - self.assertEqual(self._pload_dict, output[0]['payload'].obj_to_dict()) - - def test_tg_method_iteration(self): - self._queue.empty() - ctxt = {'id': self._ctx_ids[0]} - self.runner.tg_method_iteration(ctxt, **self._kwargs) - time.sleep(0.2) - - output = [] - while not self._queue.empty(): - output.append(self._queue.get(True, 1)) - - self.assertEqual(1, len(output)) - self.assertEqual(self._ctx_ids[0], output[0]['id']) - self.assertEqual(messaging.TG_METHOD_ITERATION, output[0]['action']) - self.assertEqual(self._pload_dict, output[0]['payload'].obj_to_dict()) - - -class RunnerIterationIPCConsumerTestCase(ut_base.BaseUnitTestCase): - - def setUp(self): - self._id = uuid.uuid1().int - self._ctx_ids = [uuid.uuid1().int, uuid.uuid1().int] - self.consumer = iteration_ipc.RunnerIterationIPCConsumer( - self._id, self._ctx_ids) - self.consumer._queue = mock.Mock() - - def test__init(self): - self.assertEqual({self._ctx_ids[0]: [], self._ctx_ids[1]: []}, - self.consumer._kpi_per_id) - - def test_is_all_kpis_received_in_iteration(self): - payload = payloads.TrafficGeneratorPayload( - version=1, iteration=1, kpi={}) - msg1 = {'action': messaging.TG_METHOD_ITERATION, - 'id': self._ctx_ids[0], 'payload': payload} - msg2 = {'action': messaging.TG_METHOD_ITERATION, - 'id': self._ctx_ids[1], 'payload': payload} - self.consumer.iteration_index = 1 - - self.consumer._queue.empty.side_effect = [False, True] - self.consumer._queue.get.return_value = msg1 - self.assertFalse(self.consumer.is_all_kpis_received_in_iteration()) - - self.consumer._queue.empty.side_effect = [False, True] - self.consumer._queue.get.return_value = msg2 - self.assertTrue(self.consumer.is_all_kpis_received_in_iteration()) - - -class IterationIPCRunnerTestCase(ut_base.BaseUnitTestCase): - - @mock.patch.object(iteration_ipc, '_worker_process') - @mock.patch.object(os, 'getpid', return_value=12345678) - @mock.patch.object(multiprocessing, 'Process', return_value=mock.Mock()) - def test__run_benchmark(self, mock_process, mock_getpid, mock_worker): - method = 'method' - scenario_cfg = {'type': 'scenario_type'} - context_cfg = 'context_cfg' - name = '%s-%s-%s' % ('IterationIPC', 'scenario_type', 12345678) - runner = iteration_ipc.IterationIPCRunner(mock.ANY) - mock_getpid.reset_mock() - - runner._run_benchmark('class', method, scenario_cfg, context_cfg) - mock_process.assert_called_once_with( - name=name, - target=mock_worker, - args=(runner.result_queue, 'class', method, scenario_cfg, - context_cfg, runner.aborted, runner.output_queue)) - mock_getpid.assert_called_once() |