commit 0f354d84fd867f9dbb9e60c6f35d6ffd0e6cc240 Author: kolaente Date: Sun Dec 9 23:23:42 2018 +0100 started loadtesting implementation diff --git a/create_users.sh b/create_users.sh new file mode 100755 index 0000000..c7b464f --- /dev/null +++ b/create_users.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +for f in {1..10}; +do + data="{\"username\":\"testuser${f}\",\"email\":\"testuser${f}@kolaente.de\",\"password\":\"1234\"}" + #echo $data + curl 'http://localhost:8080/api/v1/register' -H "accept: application/json" -H "Content-Type: application/json" -X POST -d ${data} +done diff --git a/locust_file.py b/locust_file.py new file mode 100644 index 0000000..dfdb0d8 --- /dev/null +++ b/locust_file.py @@ -0,0 +1,55 @@ +from locust import Locust, TaskSequence, task, HttpLocust, seq_task +import os +import json +import random + +#HOST_NAME = os.environ['HOST'] + + +class VikunjaTaskSet(TaskSequence): + def on_start(self): + # Called everytime when a simulated user starts executing TaskSet class + self.headers = { + 'accept': "application/json", + 'content-type': "application/json", + 'Authorization': "" + } + # Append your login or authentication keys to header + self.get_authentication_keys() + self.listIDs = [] + self.namespaces = {} + + def get_authentication_keys(self): + response = self.client.post("/login", {"username":"testuser1", "password":"1234"}) + data = json.loads(response.text) + self.headers["Authorization"] = 'Bearer ' + data["token"] + + @task + @seq_task(1) + def dashboard(self): + self.client.get("/tasks", headers=self.headers) + response = self.client.get("/namespaces", headers=self.headers) + self.namespaces = json.loads(response.text) + + @seq_task(2) + @task(10) # 10 new lists + def new_list(self): + response = self.client.put("/namespaces/" + str(self.namespaces[0]["id"]) + "/lists", + data=json.dumps({"title": "created by locust"}), + headers=self.headers) + data = json.loads(response.text) + self.listIDs.append(data["id"]) + + @seq_task + @task(1000) + def add_task(self): + self.client.put("/lists/" + str(random.choice(self.listIDs)), + data=json.dumps({"text": "task created by locust"}), + headers=self.headers) + + + +class VikunjaLocust(HttpLocust): + task_set = VikunjaTaskSet + min_wait = 100 + max_wait = 5000