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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user