started loadtesting implementation

This commit is contained in:
kolaente 2018-12-09 23:23:42 +01:00
commit 0f354d84fd
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
2 changed files with 63 additions and 0 deletions

8
create_users.sh Executable file
View File

@ -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

55
locust_file.py Normal file
View File

@ -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