forked from locustio/locust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add programmatic way to run locust PR locustio#805
- Loading branch information
Showing
7 changed files
with
286 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
.. _running-locust-programmatically: | ||
|
||
=============================== | ||
Running Locust programmatically | ||
=============================== | ||
|
||
All of the options for running locust from the command-line can be used | ||
programmatically within Python using the `locust.run_locust` function. | ||
|
||
`locust.create_options()` will set up an options object with default | ||
values filled in. See below for API reference. | ||
|
||
API Reference | ||
============= | ||
|
||
.. automodule:: locust.main | ||
:members: run_locust, create_options |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from locust import HttpLocust, TaskSet, task, create_options, run_locust | ||
|
||
def index(l): | ||
l.client.get("/") | ||
|
||
def stats(l): | ||
l.client.get("/stats/requests") | ||
|
||
class UserTasks(TaskSet): | ||
# one can specify tasks like this | ||
tasks = [index, stats] | ||
|
||
# but it might be convenient to use the @task decorator | ||
@task | ||
def page404(self): | ||
self.client.get("/does_not_exist") | ||
|
||
class WebsiteUser(HttpLocust): | ||
""" | ||
Locust user class that does requests to the locust web server running on localhost | ||
""" | ||
host = "http://127.0.0.1:8089" | ||
min_wait = 2000 | ||
max_wait = 5000 | ||
task_set = UserTasks | ||
|
||
options = create_options(locust_classes = [WebsiteUser]) | ||
run_locust(options) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
__version__ = "0.8.1" | ||
|
||
from .core import HttpLocust, Locust, TaskSet, TaskSequence, task, seq_task | ||
from .exception import InterruptTaskSet, ResponseError, RescheduleTaskImmediately | ||
|
||
__version__ = "0.8.1" | ||
from .main import run_locust, create_options, parse_options |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from locust import HttpLocust, Locust, TaskSet | ||
|
||
class MyTaskSet(TaskSet): | ||
pass | ||
|
||
class LocustfileHttpLocust(HttpLocust): | ||
task_set = MyTaskSet | ||
|
||
class LocustfileLocust(Locust): | ||
task_set = MyTaskSet |
Oops, something went wrong.