from locust import HttpLocust, TaskSet, task
class UserBehaviour(TaskSet):
@task(30)
def index_page(self):
self.client.get("/")
@task(10)
def press_page(self):
self.client.get("/press")
class WebUser(HttpLocust):
task_set = UserBehaviour
min_wait = 5 * 1000
max_wait = 60 * 1000
$ locust -f locustfile.py --host http://instagram.com
class ApiDocs(TaskSet):
@task
def overview(self):
self.client.get("/developer/")
@task
def authentication(self):
self.client.get("/developer/authentication")
@task
def endpoints(self):
self.client.get("/developer/endpoints")
@task
def stop(self):
self.interrupt()
class UserBehaviour(TaskSet):
tasks = {ApiDocs: 10}
@task(30)
def index_page(self):
self.client.get("/")
@task(10)
def press_page(self):
self.client.get("/press")
class WebUser(HttpLocust):
task_set = UserBehaviour
min_wait = 5 * 1000
max_wait = 60 * 1000
import random
from locust import HttpLocust, TaskSet, task
from pyquery import PyQuery
class ApiDocs(TaskSet):
def on_start(self):
self.overview()
@task
def overview(self):
response = self.client.get("/developer/")
pq = PyQuery(response.content)
self.locust.doc_pages = []
for link in pq(".sidebar-content li a"):
self.locust.doc_pages.append(link.attrib["href"])
@task
def sub_page(self):
url = random.choice(self.locust_doc_pages)
self.client.get(url)