allow specifying a minimum/maximum for 'sleep-*' options (#1835)

for example '"sleep-request": [5.0, 10.0]' to wait between 5 and 10
seconds between each HTTP request
This commit is contained in:
Mike Fährmann
2021-09-14 17:40:05 +02:00
parent bd845303ad
commit c9e6693530
4 changed files with 57 additions and 18 deletions

View File

@@ -409,6 +409,24 @@ def compile_expression(expr, name="<expr>", globals=GLOBALS):
return functools.partial(eval, code_object, globals)
def build_duration_func(duration, min=0.0):
if not duration:
return None
try:
lower, upper = duration
except TypeError:
pass
else:
return functools.partial(
random.uniform,
lower if lower > min else min,
upper if upper > min else min,
)
return functools.partial(identity, duration if duration > min else min)
def build_predicate(predicates):
if not predicates:
return lambda url, kwdict: True