forked from carlgieringer/newsdiffs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocustfile.py
40 lines (32 loc) · 1.2 KB
/
locustfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# This locust test script example will simulate a user
# browsing the Locust documentation on http://docs.locust.io
import random
from locust import HttpLocust, TaskSet, task
from pyquery import PyQuery
class BrowseLinks(TaskSet):
def on_start(self):
# assume all users arrive at the index page
self.index_page()
self.urls_on_current_page = self.toc_urls
@task(10)
def index_page(self):
r = self.client.get("/browse/")
pq = PyQuery(r.content)
link_elements = pq("a")
self.toc_urls = [l.attrib["href"] for l in link_elements if 'href' in l.attrib]
@task(50)
def load_page(self):
url = random.choice(self.toc_urls)
r = self.client.get(url)
pq = PyQuery(r.content)
link_elements = pq("a")
self.urls_on_current_page = [l.attrib["href"] for l in link_elements if 'href' in l.attrib]
class AwesomeUser(HttpLocust):
task_set = BrowseLinks
host = "http://127.0.0.1:8000"
# we assume someone who is browsing the Locust docs,
# generally has a quite long waiting time (between
# 20 and 600 seconds), since there's a bunch of text
# on each page
min_wait = 1 * 1000
max_wait = 5 * 1000