Created
August 2, 2016 18:59
-
-
Save wehappyfew/db6b35c1bc64e312de353023f0c6ab35 to your computer and use it in GitHub Desktop.
Simple locust scenario to build upon.
This file contains hidden or 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
__author__ = 'wehappyfew' | |
import time | |
from locust import HttpLocust, TaskSet, task | |
class UserBehavior(TaskSet): | |
def on_start(self): | |
# The scenario always starts by executing this function | |
# The way I load-test is creating a scenario function and running it from inside the on_start function. | |
# Notice: Inside the scenario function will reside ALL the steps of the load test. | |
# The entire load test scenario will run from the scenario function! | |
# That way each locust will run only once. | |
self.the_scenario() | |
def the_scenario(self): | |
# Step 1 | |
# Login to my site | |
self.client.get("login.php") | |
time.sleep(5) | |
# Step 2 | |
# do some action | |
self.client.get("why_us") | |
time.sleep(5) | |
# Step 3 | |
# do some action | |
self.client.get("pricing") | |
time.sleep(5) | |
# Step 4 | |
# do some action | |
self.client.get("community") | |
time.sleep(5) | |
# Step 5 | |
# do some action | |
self.client.get("help") | |
# Notice: This is needed for the locustfile to work like this (only one time) | |
@task(1) | |
def index(self): | |
return True | |
class WebsiteUser(HttpLocust): | |
# State the target website here so you do not have to provide it every time in the console as argument | |
host = 'https://www.some-site.com/' | |
task_set = UserBehavior | |
# According to documentation.. | |
# These are the minimum and maximum time, in milliseconds, that a simulated user will wait between executing each task. | |
# They are not needed the way I use locust | |
# min_wait = 1000 | |
# max_wait = 5000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment