Skip to content

Commit

Permalink
when using -i/--iteration limit: Ensure last requests get sent back t…
Browse files Browse the repository at this point in the history
…o master. Added a test case too. Fixes #134
  • Loading branch information
cyberw committed Aug 1, 2023
1 parent 0fffbe8 commit 262f60e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions examples/reschedule_on_fail_ex.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# How to use VS Code debugger with Locust
import locust_plugins.listeners
from locust import task, HttpUser, events, run_single_user
import time


class MyUser(HttpUser):
host = "http://example.com"

@task
def my_task(self):
time.sleep(1)
self.client.get("/fail")
print("this will never be run")

Expand Down
2 changes: 2 additions & 0 deletions locust_plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ def wrapped(self, task):
)
if runner.user_count == 1:
logging.info("Last user stopped, quitting runner")
if isinstance(runner, WorkerRunner):
runner._send_stats() # send a final report
# need to trigger this in a separate greenlet, in case test_stop handlers do something async
gevent.spawn_later(0.1, runner.quit)
raise StopUser()
Expand Down
2 changes: 2 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ commands =
bash -ec "pylint --rcfile .pylintrc examples/*.py"
pytest
black --check locust_plugins/
# ensure final samples from worker get sent to master when using iteration limit
bash -ec "export LOCUST_LOCUSTFILE=examples/reschedule_on_fail_ex.py && (locust --master --headless -i 8 --expect-workers 2 -u 4 & locust --worker & locust --worker & wait && grep '16(100.00%)')"
python3 -m playwright install
bash -ec "(cd examples && PYTHONUNBUFFERED=1 LOCUST_PLAYWRIGHT=1 locust -f playwright_ex.py --headless -t 10 -u 3) |& tee output.txt || true"
grep -m 1 'playwright-recording.py' output.txt
Expand Down

0 comments on commit 262f60e

Please sign in to comment.