Beispiel #1
0
    def test_run_scenario_internal_logic(self, mock_time, mock_pool,
                                         mock_result):
        context = fakes.FakeUserContext({}).context
        config = {"times": 4, "period": 0, "timeout": 5}
        runner = periodic.PeriodicScenarioRunner(
                        None, [context["admin"]["endpoint"]], config)

        mock_pool_inst = mock.MagicMock()
        mock_pool.ThreadPool.return_value = mock_pool_inst

        runner._run_scenario(fakes.FakeScenario, "do_it", context, {})

        exptected_pool_inst_call = []
        for i in range(config["times"]):
            args = (
                base._run_scenario_once,
                ((i, fakes.FakeScenario, "do_it",
                  base._get_scenario_context(context), {}),)
            )
            exptected_pool_inst_call.append(mock.call.apply_async(*args))

        for i in range(config["times"]):
            call = mock.call.apply_async().get(timeout=5)
            exptected_pool_inst_call.append(call)

        mock_pool.assert_has_calls([mock.call.ThreadPool(processes=1)])
        mock_pool_inst.assert_has_calls(exptected_pool_inst_call)
        mock_time.assert_has_calls([])
Beispiel #2
0
    def test_run_scenario(self):
        context = fakes.FakeUserContext({}).context
        config = {"times": 3, "period": 0, "timeout": 5}
        runner = periodic.PeriodicScenarioRunner(
                        None, [context["admin"]["endpoint"]], config)

        result = runner._run_scenario(fakes.FakeScenario, "do_it", context, {})
        self.assertEqual(len(result), config["times"])
        self.assertIsNotNone(base.ScenarioRunnerResult(result))
Beispiel #3
0
    def test_run_scenario_exception(self):
        context = fakes.FakeUserContext({}).context

        config = {"times": 4, "period": 0}
        runner = periodic.PeriodicScenarioRunner(
                        None, [context["admin"]["endpoint"]], config)

        result = runner._run_scenario(fakes.FakeScenario,
                                      "something_went_wrong", context, {})
        self.assertEqual(len(result), config["times"])
        self.assertIsNotNone(base.ScenarioRunnerResult(result))