Skip to content

Commit

Permalink
Merge pull request #690 from fomars/develop
Browse files Browse the repository at this point in the history
fix schedule parsing + tests
  • Loading branch information
fomars committed Dec 11, 2018
2 parents 5debfb3 + 32a4ad5 commit a140508
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
27 changes: 15 additions & 12 deletions yandextank/stepper/load_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ def get_rps_list(self):

class Stairway(Composite):
def __init__(self, minrps, maxrps, increment, step_duration):
self.duration = step_duration
if maxrps < minrps:
increment = -increment
n_steps = int((maxrps - minrps) / increment)
Expand All @@ -164,23 +165,25 @@ def __init__(self, minrps, maxrps, increment, step_duration):


class StepFactory(object):
@staticmethod
def line(params):
template = re.compile(r'([0-9.]+),\s*([0-9.]+),\s*([0-9.]+[dhms]?)+\)')
minrps, maxrps, duration = template.search(params).groups()
DURATION_RE = r'([0-9.]+d)?([0-9.]+h)?([0-9.]+m)?([0-9.]+s?)?'

@classmethod
def line(cls, params):
template = re.compile(r'([0-9.]+),\s*([0-9.]+),\s*({})\)'.format(cls.DURATION_RE))
minrps, maxrps, duration = template.search(params).groups()[:3]
return Line(float(minrps), float(maxrps), parse_duration(duration))

@staticmethod
def const(params):
template = re.compile(r'([0-9.]+),\s*([0-9.]+[dhms]?)+\)')
rps, duration = template.search(params).groups()
@classmethod
def const(cls, params):
template = re.compile(r'([0-9.]+),\s*({})\)'.format(cls.DURATION_RE))
rps, duration = template.search(params).groups()[:2]
return Const(float(rps), parse_duration(duration))

@staticmethod
def stairway(params):
@classmethod
def stairway(cls, params):
template = re.compile(
r'([0-9.]+),\s*([0-9.]+),\s*([0-9.]+),\s*([0-9.]+[dhms]?)+\)')
minrps, maxrps, increment, duration = template.search(params).groups()
r'([0-9.]+),\s*([0-9.]+),\s*([0-9.]+),\s*({})\)'.format(cls.DURATION_RE))
minrps, maxrps, increment, duration = template.search(params).groups()[:4]
return Stairway(
float(minrps),
float(maxrps), float(increment), parse_duration(duration))
Expand Down
13 changes: 12 additions & 1 deletion yandextank/stepper/tests/test_load_plan.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from yandextank.stepper.load_plan import create, Const, Line, Composite, Stairway
from yandextank.stepper.load_plan import create, Const, Line, Composite, Stairway, StepFactory
from yandextank.stepper.util import take


Expand Down Expand Up @@ -146,3 +146,14 @@ class TestCreate(object):
def test_create(self, rps_schedule, check_point, expected):
# pytest.set_trace()
assert take(check_point, (create(rps_schedule))) == expected


# ([0-9.]+d)?([0-9.]+h)?([0-9.]+m)?([0-9.]+s)?
@pytest.mark.parametrize('step_config, expected_duration', [
('line(1,500,1m30s)', 90),
('const(50,1h30s)', 3630 * 1000),
('step(10,200,10,1h20m)', 4800 * 1000)
])
def test_step_factory(step_config, expected_duration):
steps = StepFactory.produce(step_config)
assert steps.duration == expected_duration

0 comments on commit a140508

Please sign in to comment.