summaryrefslogtreecommitdiff
path: root/benchmarks/py-locust/files/extra-EXAMPLES-browse_docs_test.py
diff options
context:
space:
mode:
authorVinícius Zavam <egypcio@FreeBSD.org>2019-01-20 12:54:30 +0000
committerVinícius Zavam <egypcio@FreeBSD.org>2019-01-20 12:54:30 +0000
commitf20baa6ebd75e5a55ec1d3755ef4c61b83fd5924 (patch)
treecf48db9b35cfc5a7de462164883277362c465afe /benchmarks/py-locust/files/extra-EXAMPLES-browse_docs_test.py
parentUpdate files/patch-spe-config (and with that our local adjustments to (diff)
[NEW] benchmarks/py-locust: Python utility for doing distributed load tests
Locust is an easy-to-use, distributed, user load testing tool. It is intended for load-testing web sites (or other systems) and figuring out how many concurrent users a system can handle. The behavior of each locust (or test user if you will) is defined by you and the swarming process is monitored from a web UI in real-time. This will help you battle test and identify bottlenecks in your code before letting real users in. WWW: https://locust.io/ Approved by: araujo (mentor), rene (mentor) Sponsored by: cleverbridge AG Differential Revision: https://reviews.freebsd.org/D18895
Diffstat (limited to 'benchmarks/py-locust/files/extra-EXAMPLES-browse_docs_test.py')
-rw-r--r--benchmarks/py-locust/files/extra-EXAMPLES-browse_docs_test.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/benchmarks/py-locust/files/extra-EXAMPLES-browse_docs_test.py b/benchmarks/py-locust/files/extra-EXAMPLES-browse_docs_test.py
new file mode 100644
index 000000000000..b8a42a7c2bd1
--- /dev/null
+++ b/benchmarks/py-locust/files/extra-EXAMPLES-browse_docs_test.py
@@ -0,0 +1,49 @@
+# This locust test script example will simulate a user
+# browsing the Locust documentation on https://docs.locust.io/
+
+import random
+from locust import HttpLocust, TaskSet, task
+from pyquery import PyQuery
+
+
+class BrowseDocumentation(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("/")
+ pq = PyQuery(r.content)
+ link_elements = pq(".toctree-wrapper a.internal")
+ self.toc_urls = [
+ l.attrib["href"] for l in link_elements
+ ]
+
+ @task(50)
+ def load_page(self, url=None):
+ url = random.choice(self.toc_urls)
+ r = self.client.get(url)
+ pq = PyQuery(r.content)
+ link_elements = pq("a.internal")
+ self.urls_on_current_page = [
+ l.attrib["href"] for l in link_elements
+ ]
+
+ @task(30)
+ def load_sub_page(self):
+ url = random.choice(self.urls_on_current_page)
+ r = self.client.get(url)
+
+
+class AwesomeUser(HttpLocust):
+ task_set = BrowseDocumentation
+ host = "https://docs.locust.io/en/latest/"
+
+ # 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 = 20 * 1000
+ max_wait = 600 * 1000