From 9b0603ee4f6f44e45a680400c19345df826e1643 Mon Sep 17 00:00:00 2001 From: Arseniy Fomchenko Date: Tue, 1 Nov 2016 19:17:06 +0300 Subject: [PATCH] monitoring unnecessary, instance plan test --- yandextank/core/tankcore.py | 5 +++- .../stepper/tests/test_instance_plan.py | 28 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 yandextank/stepper/tests/test_instance_plan.py diff --git a/yandextank/core/tankcore.py b/yandextank/core/tankcore.py index dd90482..ef85d21 100644 --- a/yandextank/core/tankcore.py +++ b/yandextank/core/tankcore.py @@ -45,7 +45,10 @@ class Job(object): def subscribe_plugin(self, plugin): self.aggregator_plugin.add_result_listener(plugin) - self.monitoring_plugin.monitoring.add_listener(plugin) + try: + self.monitoring_plugin.monitoring.add_listener(plugin) + except AttributeError: + logging.warning('Monitoring plugin is not enabled') @property def phantom_info(self): diff --git a/yandextank/stepper/tests/test_instance_plan.py b/yandextank/stepper/tests/test_instance_plan.py new file mode 100644 index 0000000..c6e4709 --- /dev/null +++ b/yandextank/stepper/tests/test_instance_plan.py @@ -0,0 +1,28 @@ +import pytest +from yandextank.stepper.instance_plan import LoadPlanBuilder, create + +from yandextank.stepper.util import take + +class TestCreate(object): + + @pytest.mark.parametrize('n, loadplan, expected', [ + (7, LoadPlanBuilder().ramp(5, 4000).create(), [0, 1000, 2000, 3000, 4000, 0, 0]), + (7, create(['ramp(5, 4s)']), [0, 1000, 2000, 3000, 4000, 0, 0]), + (12, create(['ramp(5, 4s)', 'wait(5s)', 'ramp(5,4s)']), [0, 1000, 2000, 3000, 4000, 9000, 10000, 11000, 12000, 13000, 0, 0]), + (7, create(['wait(5s)', 'ramp(5, 0)']), [5000, 5000, 5000, 5000, 5000, 0, 0]), + (7, create([]), [0, 0, 0, 0, 0, 0, 0]), + (12, create(['line(1, 9, 4s)']), [0, 500, 1000, 1500, 2000, 2500, 3000, 3500, 4000, 0, 0, 0]), + (12, create(['const(3, 5s)', 'line(7, 11, 2s)']), [0, 0, 0, 5000, 5000, 5000, 5000, 5500, 6000, 6500, 7000, 0]), + (12, create(['step(2, 10, 2, 3s)']), [0, 0, 3000, 3000, 6000, 6000, 9000, 9000, 12000, 12000, 0, 0]), + (12, LoadPlanBuilder().const(3, 1000).line(5, 10, 5000).steps, [(3, 1), (5, 1), (6, 1), (7, 1), (8, 1), (9, 1), (10, 1)]), + (12, LoadPlanBuilder().stairway(100, 950, 100, 30000).steps, [(100, 30), (200, 30), (300, 30), (400, 30), (500, 30), (600, 30), (700, 30), (800, 30), (900, 30), (950, 30)])]) + def test_steps(self, n, loadplan, expected): + assert take(n, loadplan) == expected + + @pytest.mark.parametrize('loadplan, expected', [ + (LoadPlanBuilder().stairway(100, 950, 100, 30000), 950), + (LoadPlanBuilder().const(3, 1000).line(5, 10, 5000), 10), + (LoadPlanBuilder().line(1, 100, 60000), 100) + ]) + def test_instances(self, loadplan, expected): + assert loadplan.instances == expected