Skip to content

Commit

Permalink
TRQ-005: Add performance test (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
godcrampy authored May 19, 2024
1 parent e1d1b9a commit 85d2299
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
32 changes: 32 additions & 0 deletions performance/locustfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import random
import threading

from locust import HttpUser, TaskSet, task


class TokenTaskSet(TaskSet):
received_tokens = set()
token_lock = threading.Lock()
hosts = ["http://localhost:8080", "http://localhost:8081"]

@task
def get_token(self):
host = random.choice(self.hosts)
with self.client.get(host + "/api/v1/token", catch_response=True) as response:
if response.status_code == 200:
token = response.text.strip()
with self.token_lock:
if token in self.received_tokens:
response.failure(f"Duplicate token found: {token}")
else:
response.success()
self.received_tokens.add(token)
else:
response.failure(f"Failed to get token from {host}, status code: {response.status_code}")


class User(HttpUser):
tasks = [TokenTaskSet]

def on_start(self):
self.host = None
25 changes: 25 additions & 0 deletions performance/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
blinker==1.8.2
Brotli==1.1.0
certifi==2024.2.2
charset-normalizer==3.3.2
click==8.1.7
ConfigArgParse==1.7
Flask==3.0.3
Flask-Cors==4.0.1
Flask-Login==0.6.3
gevent==24.2.1
geventhttpclient==2.2.1
greenlet==3.0.3
idna==3.7
itsdangerous==2.2.0
Jinja2==3.1.4
locust==2.27.0
MarkupSafe==2.1.5
msgpack==1.0.8
psutil==5.9.8
pyzmq==26.0.3
requests==2.31.0
urllib3==2.2.1
Werkzeug==3.0.3
zope.event==5.0
zope.interface==6.4

0 comments on commit 85d2299

Please sign in to comment.