From d1fcea563296b26126aa254bb814f15edc0097c8 Mon Sep 17 00:00:00 2001 From: Eliot Berriot Date: Mon, 21 Oct 2019 11:01:50 +0200 Subject: [PATCH] Added load testing test case --- api/tests/loadtesting/library.py | 38 ++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 api/tests/loadtesting/library.py diff --git a/api/tests/loadtesting/library.py b/api/tests/loadtesting/library.py new file mode 100644 index 000000000..6413a161f --- /dev/null +++ b/api/tests/loadtesting/library.py @@ -0,0 +1,38 @@ +import os +import urllib.parse + +from locust import HttpLocust, TaskSet, task + +JWT_TOKEN = os.environ.get("JWT_TOKEN") + +DATA = {"playable": True} +HEADERS = {} +if JWT_TOKEN: + print("Starting authenticated session") + HEADERS["authorization"] = "JWT {}".format(JWT_TOKEN) + + +class WebsiteTasks(TaskSet): + @task + def albums(self): + self.client.get( + "/api/v1/albums?" + urllib.parse.urlencode(DATA), headers=HEADERS + ) + + @task + def artists(self): + self.client.get( + "/api/v1/artists?" + urllib.parse.urlencode(DATA), headers=HEADERS + ) + + @task + def tracks(self): + self.client.get( + "/api/v1/tracks?" + urllib.parse.urlencode(DATA), headers=HEADERS + ) + + +class WebsiteUser(HttpLocust): + task_set = WebsiteTasks + min_wait = 1000 + max_wait = 3000