def test_run_scenario_once_internal_logic(self): context = runner._get_scenario_context( 12, fakes.FakeContext({}).context) scenario_cls = mock.MagicMock() runner._run_scenario_once(scenario_cls, "test", context, {}) expected_calls = [ mock.call(context), mock.call().test(), mock.call().idle_duration(), mock.call().idle_duration(), mock.call().atomic_actions() ] scenario_cls.assert_has_calls(expected_calls, any_order=True)
def _run_scenario(self, cls, method_name, context, args): """Runs the specified scenario with given arguments. The scenario iterations are executed one-by-one in the same python interpreter process as Rally. This allows you to execute scenario without introducing any concurrent operations as well as interactively debug the scenario from the same command that you use to start Rally. :param cls: The Scenario class where the scenario is implemented :param method_name: Name of the method that implements the scenario :param context: context that contains users, admin & other information, that was created before scenario execution starts. :param args: Arguments to call the scenario method with :returns: List of results fore each single scenario iteration, where each result is a dictionary """ times = self.config.get("times", 1) event_queue = rutils.DequeAsQueue(self.event_queue) for i in range(times): if self.aborted.is_set(): break result = runner._run_scenario_once( cls, method_name, runner._get_scenario_context(i, context), args, event_queue) self._send_result(result) self._flush_results()
def _run_scenario_once_with_sleep(args): iteration, cls, method_name, context_obj, kwargs, pause = args # Time to take a break time.sleep(pause) args = (iteration, cls, method_name, context_obj, kwargs) return runner._run_scenario_once(args)
def _run_scenario_once_with_unpack_args(args): # NOTE(andreykurilin): `pool.imap` is used in # ConstantForDurationScenarioRunner. It does not want to work with # instance-methods, class-methods and static-methods. Also, it can't # transmit positional or keyword arguments to destination function. # While original `rally.task.runner._run_scenario_once` accepts # multiple arguments instead of one big tuple with all arguments, we # need to hardcode unpacking here(all other runners are able to # transmit arguments in proper way). return runner._run_scenario_once(*args)
def _run_scenario(self, cls, method_name, context, args): # runners settings are stored in self.config min_times = self.config.get("min_times", 1) max_times = self.config.get("max_times", 1) for i in range(random.randrange(min_times, max_times)): run_args = (i, cls, method_name, runner._get_scenario_context(context), args) result = runner._run_scenario_once(run_args) # use self.send_result for result of each iteration self._send_result(result)
def test_run_scenario_once_internal_logic(self): context = runner._get_scenario_context( 12, fakes.FakeContext({}).context) scenario_cls = mock.MagicMock() event_queue = mock.MagicMock() runner._run_scenario_once( scenario_cls, "test", context, {}, event_queue) expected_calls = [ mock.call(context), mock.call().test(), mock.call().idle_duration(), mock.call().idle_duration(), mock.call().atomic_actions() ] scenario_cls.assert_has_calls(expected_calls, any_order=True) event_queue.put.assert_called_once_with( {"type": "iteration", "value": 13})
def test_run_scenario_once_without_scenario_output(self, mock_timer): result = runner._run_scenario_once( fakes.FakeScenario, "do_it", mock.MagicMock(), {}) expected_result = { "duration": fakes.FakeTimer().duration(), "timestamp": fakes.FakeTimer().timestamp(), "idle_duration": 0, "error": [], "output": {"additive": [], "complete": []}, "atomic_actions": {} } self.assertEqual(expected_result, result)
def test_run_scenario_once_without_scenario_output(self, mock_timer): args = (1, fakes.FakeScenario, "do_it", mock.MagicMock(), {}) result = runner._run_scenario_once(args) expected_result = { "duration": fakes.FakeTimer().duration(), "timestamp": fakes.FakeTimer().timestamp(), "idle_duration": 0, "error": [], "scenario_output": {"errors": "", "data": {}}, "atomic_actions": {} } self.assertEqual(expected_result, result)
def test_run_scenario_once_exception(self, mock_timer): result = runner._run_scenario_once( fakes.FakeScenario, "something_went_wrong", mock.MagicMock(), {}) expected_error = result.pop("error") expected_result = { "duration": fakes.FakeTimer().duration(), "timestamp": fakes.FakeTimer().timestamp(), "idle_duration": 0, "output": {"additive": [], "complete": []}, "atomic_actions": {} } self.assertEqual(expected_result, result) self.assertEqual(expected_error[:2], ["Exception", "Something went wrong"])
def test_run_scenario_once_with_scenario_output(self, mock_timer): context = runner._get_scenario_context( fakes.FakeUserContext({}).context) args = (1, fakes.FakeScenario, "with_output", context, {}) result = runner._run_scenario_once(args) expected_result = { "duration": fakes.FakeTimer().duration(), "timestamp": fakes.FakeTimer().timestamp(), "idle_duration": 0, "error": [], "scenario_output": fakes.FakeScenario().with_output(), "atomic_actions": {} } self.assertEqual(expected_result, result)
def test_run_scenario_once_exception(self, mock_timer): context = runner._get_scenario_context( fakes.FakeUserContext({}).context) args = (1, fakes.FakeScenario, "something_went_wrong", context, {}) result = runner._run_scenario_once(args) expected_error = result.pop("error") expected_result = { "duration": fakes.FakeTimer().duration(), "timestamp": fakes.FakeTimer().timestamp(), "idle_duration": 0, "scenario_output": {"errors": "", "data": {}}, "atomic_actions": {} } self.assertEqual(expected_result, result) self.assertEqual(expected_error[:2], ["Exception", "Something went wrong"])
def test_run_scenario_once_with_returned_scenario_output(self, mock_timer): args = (1, fakes.FakeScenario, "with_output", mock.MagicMock(), {}) result = runner._run_scenario_once(args) expected_result = { "duration": fakes.FakeTimer().duration(), "timestamp": fakes.FakeTimer().timestamp(), "idle_duration": 0, "error": [], "output": {"additive": [{"chart_plugin": "StackedArea", "description": "", "data": [["a", 1]], "title": "Scenario output"}], "complete": []}, "atomic_actions": {} } self.assertEqual(expected_result, result)
def test_run_scenario_once_exception(self, mock_timer): result = runner._run_scenario_once(fakes.FakeScenario, "something_went_wrong", mock.MagicMock(), {}) expected_error = result.pop("error") expected_result = { "duration": fakes.FakeTimer().duration(), "timestamp": fakes.FakeTimer().timestamp(), "idle_duration": 0, "output": { "additive": [], "complete": [] }, "atomic_actions": {} } self.assertEqual(expected_result, result) self.assertEqual(expected_error[:2], ["Exception", "Something went wrong"])
def test_run_scenario_once_with_added_scenario_output(self, mock_timer): result = runner._run_scenario_once( fakes.FakeScenario, "with_add_output", mock.MagicMock(), {}) expected_result = { "duration": fakes.FakeTimer().duration(), "timestamp": fakes.FakeTimer().timestamp(), "idle_duration": 0, "error": [], "output": {"additive": [{"chart_plugin": "FooPlugin", "description": "Additive description", "data": [["a", 1]], "title": "Additive"}], "complete": [{"data": [["a", [[1, 2], [2, 3]]]], "description": "Complete description", "title": "Complete", "chart_plugin": "BarPlugin"}]}, "atomic_actions": {} } self.assertEqual(expected_result, result)
def test_run_scenario_once_with_returned_scenario_output(self, mock_timer): args = (1, fakes.FakeScenario, "with_output", mock.MagicMock(), {}) result = runner._run_scenario_once(args) expected_result = { "duration": fakes.FakeTimer().duration(), "timestamp": fakes.FakeTimer().timestamp(), "idle_duration": 0, "error": [], "output": { "additive": [{ "chart_plugin": "StackedArea", "description": "", "data": [["a", 1]], "title": "Scenario output" }], "complete": [] }, "atomic_actions": {} } self.assertEqual(expected_result, result)