Reject a non-positive rate in constant_throughput() by Lesereingrape · Pull Request #3534 · locustio/locust · GitHub
Skip to content

Reject a non-positive rate in constant_throughput() - #3534

Merged
cyberw merged 1 commit into
locustio:masterfrom
Lesereingrape:fix/constant-throughput-positive-rate
Oct 3, 2026
Merged

cyberw merged 1 commit into
locustio:masterfrom
Lesereingrape:fix/constant-throughput-positive-rate

Conversation

@Lesereingrape

Copy link
Copy Markdown
Contributor

Reject a non-positive rate in constant_throughput(), using the same guard poisson() in
this module already has.

Without it:

  • constant_throughput(-0.1) becomes constant_pacing(-10), whose max(0, wait_time - run_time)
    returns 0 every time, so the load runs flat out with no warning — the opposite of what was
    configured;
  • constant_throughput(0) raises a bare ZeroDivisionError: division by zero while the locustfile
    is imported, naming neither the function nor the argument.

constant_throughput() is documented as the mathematical inverse of constant_pacing() and the
fixed-rate sibling of poisson(), so the positive-rate requirement belongs in the same place.

Fixes #3533

How was it checked

On master at d7842f50, before the change (baseline file restored from HEAD):

locust/test/test_wait_time.py  ->  1 failed, 14 passed
FAILED TestWaitTime::test_constant_throughput_invalid_rate
    return constant_pacing(1 / task_runs_per_second)
E   ZeroDivisionError: division by zero

after the change:

locust/test/test_wait_time.py  ->  15 passed
ruff check locust/             ->  All checks passed
ruff format --check            ->  2 files already formatted
mypy locust/user/wait_time.py  ->  Success: no issues found in 1 source file

No other call site in the repository passes a non-positive rate, and the documented examples
(constant_throughput(0.1), constant_throughput(2), constant_throughput(10)) are unaffected.


Drafted with AI assistance in this session; no human reviewed it before submission.

constant_throughput(-0.1) turned into constant_pacing(-10), whose max(0, ...)
silently returned a zero wait, so the load ran as fast as possible instead of
raising or throttling. constant_throughput(0) raised a bare ZeroDivisionError
that named neither the function nor the argument.
@cyberw
cyberw merged commit c6c5148 into locustio:master Oct 3, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

constant_throughput() accepts a non-positive rate: silent zero pacing, or a bare ZeroDivisionError at import

2 participants