Skip to content

Commit

Permalink
added load testing
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedsadman committed Oct 26, 2019
1 parent ce5059a commit 68df0e6
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 0 deletions.
13 changes: 13 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,48 @@ appdirs==1.4.3
astroid==2.2.5
attrs==19.1.0
black==19.3b0
certifi==2019.9.11
cffi==1.13.1
chardet==3.0.4
Click==7.0
colorama==0.4.1
Flask==1.1.1
Flask-JWT-Extended==3.22.0
Flask-Migrate==2.5.2
Flask-RESTful==0.3.7
Flask-SQLAlchemy==2.4.0
gevent==1.4.0
geventhttpclient-wheels==1.3.1.dev2
greenlet==0.4.15
idna==2.8
isort==4.3.21
itsdangerous==1.1.0
Jinja2==2.10.1
lazy-object-proxy==1.4.2
locustio==0.12.1
Mako==1.1.0
MarkupSafe==1.1.1
marshmallow==3.0.0
mccabe==0.6.1
msgpack-python==0.5.6
pep8==1.7.1
psycopg2==2.8.3
pycodestyle==2.5.0
pycparser==2.19
PyJWT==1.7.1
python-dateutil==2.8.0
python-dotenv==0.10.3
python-editor==1.0.4
python-http-client==3.1.0
pytz==2019.2
pyzmq==18.1.0
requests==2.22.0
sendgrid==6.0.5
six==1.12.0
SQLAlchemy==1.3.6
toml==0.10.0
typed-ast==1.4.0
urllib3==1.25.6
Werkzeug==0.15.5
wrapt==1.11.2
uwsgi
74 changes: 74 additions & 0 deletions tests/loadtest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
"""Tests server load by applying read/write operations"""

from locust import HttpLocust, TaskSet, task
import random
import string


class UserBehavior(TaskSet):
EVENT_IDS = [1, 2, 3]
PAYMENT_STATUS = ["pending", "waiting", "ok"]

def _random_string(self, n):
return "".join(random.choices(string.ascii_uppercase, k=n))

def generate_data(self):
return {
"participants": [
{
"name": self._random_string(10),
"email": "{}@gmail.com".format(self._random_string(6)),
"tshirt_size": "l",
"institute": "IUT",
"contact_no": "01715002073",
},
{
"name": self._random_string(10),
"email": "{}@gmail.com".format(self._random_string(6)),
"tshirt_size": "l",
"institute": "IUT",
"contact_no": "01715002073",
},
],
"team_name": self._random_string(5),
}

@task
def index(self):
response = self.client.get("/")

@task
def list_events(self):
response = self.client.get("/events")

@task
def find_team_by_event(self):
event_id = random.choice(self.EVENT_IDS)
response = self.client.get("/team/find?event_id={}".format(event_id))

@task
def find_team_by_payment(self):
status = random.choice(self.PAYMENT_STATUS)
response = self.client.get(
"/team/find?payment_status={}".format(status)
)

@task
def find_participant_by_event(self):
event_id = random.choice(self.EVENT_IDS)
response = self.client.get(
"/participant/find?event_id={}".format(event_id)
)

@task
def event_register(self):
response = self.client.post(
"/event/register/1", json=self.generate_data()
)
print(response)


class WebsiteUser(HttpLocust):
task_set = UserBehavior
min_wait = 3000
max_wait = 7000
42 changes: 42 additions & 0 deletions tests/loadtest_read.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""Tests server load by applying various read operations only"""

from locust import HttpLocust, TaskSet, task
from random import choice


class UserBehavior(TaskSet):
EVENT_IDS = [1, 2, 3]
PAYMENT_STATUS = ["pending", "waiting", "ok"]

@task(1)
def index(self):
response = self.client.get("/")

@task(1)
def list_events(self):
response = self.client.get("/events")

@task(2)
def find_team_by_event(self):
event_id = choice(self.EVENT_IDS)
response = self.client.get("/team/find?event_id={}".format(event_id))

@task(2)
def find_team_by_payment(self):
status = choice(self.PAYMENT_STATUS)
response = self.client.get(
"/team/find?payment_status={}".format(status)
)

@task(2)
def find_participant_by_event(self):
event_id = choice(self.EVENT_IDS)
response = self.client.get(
"/participant/find?event_id={}".format(event_id)
)


class WebsiteUser(HttpLocust):
task_set = UserBehavior
min_wait = 2000
max_wait = 5000
47 changes: 47 additions & 0 deletions tests/loadtest_write.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""Tests server load by applying various write operations only"""

from locust import HttpLocust, TaskSet, task
import string
import random


class UserBehavior(TaskSet):
EVENT_IDS = [1, 2, 3]
PAYMENT_STATUS = ["pending", "waiting", "ok"]

def _random_string(self, n):
return "".join(random.choices(string.ascii_uppercase, k=n))

def generate_data(self):
return {
"participants": [
{
"name": self._random_string(10),
"email": "{}@gmail.com".format(self._random_string(6)),
"tshirt_size": "l",
"institute": "IUT",
"contact_no": "01715002073",
},
{
"name": self._random_string(10),
"email": "{}@gmail.com".format(self._random_string(6)),
"tshirt_size": "l",
"institute": "IUT",
"contact_no": "01715002073",
},
],
"team_name": self._random_string(5),
}

@task
def event_register(self):
response = self.client.post(
"/event/register/1", json=self.generate_data()
)
print(response)


class WebsiteUser(HttpLocust):
task_set = UserBehavior
min_wait = 2000
max_wait = 5000

0 comments on commit 68df0e6

Please sign in to comment.