-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ce5059a
commit 68df0e6
Showing
4 changed files
with
176 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |