def test_validate(self): config = [{ "duration": 1.0, "idle_duration": 1.0, "scenario_output": { "data": { "test": 1.0 }, "errors": "test error string 1" }, "atomic_actions": { "test1": 1.0 }, "error": [] }, { "duration": 2.0, "idle_duration": 2.0, "scenario_output": { "data": { "test": 2.0 }, "errors": "test error string 2" }, "atomic_actions": { "test2": 2.0 }, "error": ["a", "b", "c"] }] self.assertEqual(config[0], runner.ScenarioRunnerResult(config[0])) self.assertEqual(config[1], runner.ScenarioRunnerResult(config[1]))
def test_validate(self): config = [{ "duration": 1.0, "idle_duration": 1.0, "output": { "additive": [], "complete": [] }, "atomic_actions": { "test1": 1.0 }, "error": [] }, { "duration": 2.0, "idle_duration": 2.0, "output": { "additive": [{ "chart_plugin": "StackedArea", "data": [["a", 1]], "title": "Scenario output", "description": "" }], "complete": [] }, "atomic_actions": { "test2": 2.0 }, "error": ["a", "b", "c"] }] self.assertEqual(config[0], runner.ScenarioRunnerResult(config[0])) self.assertEqual(config[1], runner.ScenarioRunnerResult(config[1]))
def test__run_scenario(self): runner_obj = constant.ConstantScenarioRunner(self.task, self.config) runner_obj._run_scenario( fakes.FakeScenario, "do_it", self.context, self.args) self.assertEqual(len(runner_obj.result_queue), self.config["times"]) for result in runner_obj.result_queue: self.assertIsNotNone(runner.ScenarioRunnerResult(result))
def test__run_scenario_exception(self): runner_obj = constant.ConstantScenarioRunner(self.task, self.config) runner_obj._run_scenario(fakes.FakeScenario, "something_went_wrong", self.context, self.args) self.assertEqual(len(runner_obj.result_queue), self.config["times"]) for result in runner_obj.result_queue: self.assertIsNotNone(runner.ScenarioRunnerResult(result)) self.assertIn("error", runner_obj.result_queue[0])
def test__run_scenario_exception(self, mock_sleep): config = {"times": 4, "rps": 10} runner_obj = rps.RPSScenarioRunner(self.task, config) runner_obj._run_scenario(fakes.FakeScenario, "something_went_wrong", fakes.FakeContext({}).context, {}) self.assertEqual(len(runner_obj.result_queue), config["times"]) for result in runner_obj.result_queue: self.assertIsNotNone(runner.ScenarioRunnerResult(result))
def test_run_scenario_constantly_for_duration(self): runner_obj = constant.ConstantForDurationScenarioRunner( None, self.config) runner_obj._run_scenario(fakes.FakeScenario, "do_it", self.context, self.args) # NOTE(mmorais): when duration is 0, scenario executes exactly 1 time expected_times = 1 self.assertEqual(len(runner_obj.result_queue), expected_times) for result in runner_obj.result_queue: self.assertIsNotNone(runner.ScenarioRunnerResult(result))
def test__run_scenario(self, mock_sleep): config = {"times": 20, "rps": 20, "timeout": 5, "max_concurrency": 15} runner_obj = rps.RPSScenarioRunner(self.task, config) runner_obj._run_scenario(fakes.FakeScenario, "do_it", fakes.FakeContext({}).context, {}) self.assertEqual(len(runner_obj.result_queue), config["times"]) for result in runner_obj.result_queue: self.assertIsNotNone(runner.ScenarioRunnerResult(result))
def test__run_scenario_aborted(self, mock_sleep): config = {"times": 20, "rps": 20, "timeout": 5} runner_obj = rps.RPSScenarioRunner(self.task, config) runner_obj.abort() runner_obj._run_scenario(fakes.FakeScenario, "do_it", fakes.FakeUser().context, {}) self.assertEqual(len(runner_obj.result_queue), 0) for result in runner_obj.result_queue: self.assertIsNotNone(runner.ScenarioRunnerResult(result))
def test_run_scenario_constantly_for_duration_exception(self): runner_obj = constant.ConstantForDurationScenarioRunner( None, self.config) runner_obj._run_scenario(fakes.FakeScenario, "something_went_wrong", self.context, self.args) # NOTE(mmorais): when duration is 0, scenario executes exactly 1 time expected_times = 1 self.assertEqual(len(runner_obj.result_queue), expected_times) for result_batch in runner_obj.result_queue: for result in result_batch: self.assertIsNotNone(runner.ScenarioRunnerResult(result)) self.assertIn("error", runner_obj.result_queue[0][0])