コード例 #1
0
    def test__run_scenario(self, mock__run_scenario_once, mock_deque_as_queue):
        times = 5
        result = {"duration": 10., "idle_duration": 0., "error": [],
                  "output": {"additive": [], "complete": []},
                  "atomic_actions": [],
                  "timestamp": 1.}
        mock__run_scenario_once.return_value = result
        deque_as_queue_inst = mock_deque_as_queue.return_value
        expected_results = [[result] for i in range(times)]
        runner = serial.SerialScenarioRunner(mock.MagicMock(),
                                             {"times": times})

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

        self.assertEqual(len(runner.result_queue), times)
        results = list(runner.result_queue)
        self.assertEqual(results, expected_results)
        expected_calls = []
        for i in range(times):
            ctxt = fakes.FakeContext().context
            ctxt["iteration"] = i + 1
            ctxt["task"] = mock.ANY
            expected_calls.append(
                mock.call(fakes.FakeScenario, "do_it", ctxt, {},
                          deque_as_queue_inst)
            )
        mock__run_scenario_once.assert_has_calls(expected_calls)
        mock_deque_as_queue.assert_called_once_with(runner.event_queue)
コード例 #2
0
ファイル: test_base.py プロジェクト: sahanasj/rally
    def test_gt(self):
        class FakeBiggerContext(fakes.FakeContext):
            __ctx_order__ = fakes.FakeContext.get_order() + 1

        ctx = mock.MagicMock()
        self.assertTrue(FakeBiggerContext(ctx) > fakes.FakeContext(ctx))
        self.assertFalse(fakes.FakeContext(ctx) > FakeBiggerContext(ctx))
        self.assertFalse(fakes.FakeContext(ctx) > fakes.FakeContext(ctx))
コード例 #3
0
ファイル: test_base.py プロジェクト: sahanasj/rally
    def test_lt(self):
        class FakeLowerContext(fakes.FakeContext):
            __ctx_order__ = fakes.FakeContext.get_order() - 1

        ctx = mock.MagicMock()
        self.assertTrue(FakeLowerContext(ctx) < fakes.FakeContext(ctx))
        self.assertFalse(fakes.FakeContext(ctx) < FakeLowerContext(ctx))
        self.assertFalse(fakes.FakeContext(ctx) < fakes.FakeContext(ctx))
コード例 #4
0
ファイル: test_context.py プロジェクト: NaliniKrishna/Rally
    def test_lt(self):
        @context.configure(name="lt", order=fakes.FakeContext.get_order() - 1)
        class FakeLowerContext(fakes.FakeContext):
            pass

        ctx = mock.MagicMock()
        self.assertTrue(FakeLowerContext(ctx) < fakes.FakeContext(ctx))
        self.assertFalse(fakes.FakeContext(ctx) < FakeLowerContext(ctx))
        self.assertFalse(fakes.FakeContext(ctx) < fakes.FakeContext(ctx))
コード例 #5
0
ファイル: test_context.py プロジェクト: NaliniKrishna/Rally
    def test_gt(self):
        @context.configure(name="f", order=fakes.FakeContext.get_order() + 1)
        class FakeBiggerContext(fakes.FakeContext):
            pass

        ctx = mock.MagicMock()
        self.assertTrue(FakeBiggerContext(ctx) > fakes.FakeContext(ctx))
        self.assertFalse(fakes.FakeContext(ctx) > FakeBiggerContext(ctx))
        self.assertFalse(fakes.FakeContext(ctx) > fakes.FakeContext(ctx))
コード例 #6
0
 def test__run_scenario_aborted(self):
     runner = serial.SerialScenarioRunner(mock.MagicMock(),
                                          {"times": 5})
     runner.abort()
     runner._run_scenario(fakes.FakeScenario, "do_it",
                          fakes.FakeContext().context, {})
     self.assertEqual(len(runner.result_queue), 0)
コード例 #7
0
ファイル: test_base.py プロジェクト: sahanasj/rally
    def test_eq(self):
        class FakeOtherContext(fakes.FakeContext):
            __ctx_order__ = fakes.FakeContext.get_order() + 1

        ctx = mock.MagicMock()
        self.assertFalse(FakeOtherContext(ctx) == fakes.FakeContext(ctx))
        self.assertTrue(FakeOtherContext(ctx) == FakeOtherContext(ctx))
コード例 #8
0
 def setUp(self):
     super(ConstantForDurationScenarioRunnerTestCase, self).setUp()
     self.config = {"duration": 0, "concurrency": 2,
                    "timeout": 2, "type": "constant_for_duration"}
     self.context = fakes.FakeContext({"task": {"uuid": "uuid"}}).context
     self.context["iteration"] = 14
     self.args = {"a": 1}
     self.task = mock.MagicMock()
コード例 #9
0
ファイル: test_context.py プロジェクト: yongfengdu/rally
    def test_eq(self):
        @context.context(name="fake2", order=fakes.FakeContext.get_order() + 1)
        class FakeOtherContext(fakes.FakeContext):
            pass

        ctx = mock.MagicMock()
        self.assertFalse(FakeOtherContext(ctx) == fakes.FakeContext(ctx))
        self.assertTrue(FakeOtherContext(ctx) == FakeOtherContext(ctx))
コード例 #10
0
    def test___gt__(self):
        @context.configure(name="bargt", order=0)
        class BarContext(fakes.FakeContext):
            pass

        foo_context = fakes.FakeContext()
        bar_context = BarContext()
        self.assertTrue(foo_context > bar_context)
コード例 #11
0
 def setUp(self):
     super(ConstantScenarioRunnerTestCase, self).setUp()
     self.config = {"times": 4, "concurrency": 2,
                    "timeout": 2, "type": "constant",
                    "max_cpu_count": 2}
     self.context = fakes.FakeContext({"task": {"uuid": "uuid"}}).context
     self.args = {"a": 1}
     self.task = mock.MagicMock()
コード例 #12
0
ファイル: test_context.py プロジェクト: robertgitlab/rally
 def test_init_empty_context(self):
     ctx0 = {
         "task": mock.MagicMock(),
         "config": {"fake": {"foo": 42}}
     }
     ctx = fakes.FakeContext(ctx0)
     self.assertEqual(ctx0["config"]["fake"], ctx.config)
     self.assertEqual(ctx0["task"], ctx.task)
     self.assertEqual(ctx0, ctx.context)
コード例 #13
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))
コード例 #14
0
    def test_with_statement(self):
        ctx0 = {"task": mock.MagicMock()}
        ctx = fakes.FakeContext(ctx0)
        ctx.setup = mock.MagicMock()
        ctx.cleanup = mock.MagicMock()

        with ctx as entered_ctx:
            self.assertEqual(ctx, entered_ctx)

        ctx.cleanup.assert_called_once_with()
コード例 #15
0
ファイル: test_rps.py プロジェクト: sapcc/rally
    def test__run_scenario(self, mock_sleep, config):
        runner_obj = rps.RPSScenarioRunner(self.task, config)

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

        self.assertEqual(config["times"], len(runner_obj.result_queue))

        for result_batch in runner_obj.result_queue:
            for result in result_batch:
                self.assertIsNotNone(result)
コード例 #16
0
    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))
コード例 #17
0
ファイル: test_context.py プロジェクト: yongfengdu/rally
    def test_init(self):
        ctx0 = {
            "config": {
                "a": 1,
                "fake": mock.MagicMock()
            },
            "task": mock.MagicMock()
        }

        ctx = fakes.FakeContext(ctx0)
        self.assertEqual(ctx.config, ctx0["config"]["fake"])
        self.assertEqual(ctx.task, ctx0["task"])
        self.assertEqual(ctx.context, ctx0)
コード例 #18
0
    def test_run_scenario_once_internal_logic(self):
        context = runner._get_scenario_context(fakes.FakeContext({}).context)
        scenario_cls = mock.MagicMock()
        args = (2, scenario_cls, "test", context, {})
        runner._run_scenario_once(args)

        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)
コード例 #19
0
    def test___ge__(self):
        @context.configure(name="barge", order=0)
        class BarContext(fakes.FakeContext):
            pass

        @context.configure(name="bazge", order=-1)
        class BazContext(fakes.FakeContext):
            pass

        foo_context = fakes.FakeContext()
        bar_context = BarContext()
        baz_context = BazContext()
        self.assertTrue(foo_context >= bar_context)
        self.assertTrue(foo_context >= baz_context)
コード例 #20
0
    def test___le__(self):
        @context.configure(name="barle", order=1)
        class BarContext(fakes.FakeContext):
            pass

        @context.configure(name="bazle", order=2)
        class BazContext(fakes.FakeContext):
            pass

        foo_context = fakes.FakeContext()
        bar_context = BarContext()
        baz_context = BazContext()
        self.assertTrue(foo_context <= bar_context)
        self.assertTrue(foo_context <= baz_context)
コード例 #21
0
 def test_get_owner_id(self):
     ctx = {
         "config": {
             "fake": {
                 "test": 10
             }
         },
         "task": {
             "uuid": "task_uuid"
         },
         "owner_id": "foo_uuid"
     }
     ins = fakes.FakeContext(ctx)
     self.assertEqual("foo_uuid", ins.get_owner_id())
コード例 #22
0
ファイル: test_serial.py プロジェクト: lihaijing/rally
    def test__run_scenario(self, mock__run_scenario_once):
        times = 5
        result = {"duration": 10., "idle_duration": 0., "error": [],
                  "output": {"additive": [], "complete": []},
                  "atomic_actions": {},
                  "timestamp": 1.}
        mock__run_scenario_once.return_value = result
        expected_results = [[result] for i in range(times)]

        runner = serial.SerialScenarioRunner(mock.MagicMock(),
                                             {"times": times})
        runner._run_scenario(fakes.FakeScenario, "do_it",
                             fakes.FakeContext().context, {})
        self.assertEqual(len(runner.result_queue), times)
        results = list(runner.result_queue)
        self.assertEqual(results, expected_results)
コード例 #23
0
    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})
コード例 #24
0
 def test_init_empty_context(self):
     ctx0 = {"task": mock.MagicMock(), "config": {"fake": "test"}}
     ctx = fakes.FakeContext(ctx0)
     self.assertEqual(ctx.config, ctx0["config"]["fake"])
     self.assertEqual(ctx.task, ctx0["task"])
     self.assertEqual(ctx.context, ctx0)
コード例 #25
0
 def test_init(self, config, expected):
     ctx = {"config": {"foo": 42, "fake": config}, "task": "foo_task"}
     ins = fakes.FakeContext(ctx)
     self.assertEqual(expected, ins.config)
     self.assertEqual("foo_task", ins.task)
     self.assertEqual(ctx, ins.context)
コード例 #26
0
ファイル: test_context.py プロジェクト: yongfengdu/rally
 def test_init_empty_context(self):
     ctx0 = {"task": mock.MagicMock()}
     ctx = fakes.FakeContext(ctx0)
     self.assertEqual(ctx.config, {})
     self.assertEqual(ctx.task, ctx0["task"])
     self.assertEqual(ctx.context, ctx0)