-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1266 from locustio/v1.0
Work towards 1.0. Refactoring of runners/events/web ui. Getting rid of global state.
- Loading branch information
Showing
39 changed files
with
1,853 additions
and
1,473 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
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 |
---|---|---|
|
@@ -56,6 +56,7 @@ Other functionalities | |
testing-other-systems | ||
extending-locust | ||
logging | ||
use-as-lib | ||
API | ||
|
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
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
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,46 @@ | ||
========================== | ||
Using Locust as a library | ||
========================== | ||
|
||
It's possible to use Locust as a library instead of running Locust by invoking the ``locust`` command. | ||
|
||
Here's an example:: | ||
|
||
import gevent | ||
from locust import HttpLocust, TaskSet, task, between | ||
from locust.runners import LocalLocustRunner | ||
from locust.env import Environment | ||
from locust.stats import stats_printer | ||
from locust.log import setup_logging | ||
from locust.web import WebUI | ||
setup_logging("INFO", None) | ||
class User(HttpLocust): | ||
wait_time = between(1, 3) | ||
host = "https://docs.locust.io" | ||
class task_set(TaskSet): | ||
@task | ||
def my_task(self): | ||
self.client.get("/") | ||
@task | ||
def task_404(self): | ||
self.client.get("/non-existing-path") | ||
# setup Environment and Runner | ||
env = Environment(locust_classes=[User]) | ||
runner = LocalLocustRunner(environment=env) | ||
# start a WebUI instance | ||
web_ui = WebUI(runner=runner, environment=env) | ||
gevent.spawn(lambda: web_ui.start("127.0.0.1", 8089)) | ||
# start a greenlet that periodically outputs the current stats | ||
gevent.spawn(stats_printer(env.stats)) | ||
# start the test | ||
runner.start(1, hatch_rate=10) | ||
# wait for the greenlets (indefinitely) | ||
runner.greenlet.join() |
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,26 @@ | ||
from locust import HttpLocust, TaskSet, task, between | ||
from locust import events | ||
|
||
|
||
@events.init_command_line_parser.add_listener | ||
def _(parser): | ||
parser.add_argument( | ||
'--custom-argument', | ||
help="It's working" | ||
) | ||
|
||
@events.init.add_listener | ||
def _(environment, **kw): | ||
print("Custom argument supplied: %s" % environment.options.custom_argument) | ||
|
||
|
||
class WebsiteUser(HttpLocust): | ||
""" | ||
Locust user class that does requests to the locust web server running on localhost | ||
""" | ||
host = "http://127.0.0.1:8089" | ||
wait_time = between(2, 5) | ||
class task_set(TaskSet): | ||
@task | ||
def my_task(self): | ||
pass |
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
Oops, something went wrong.