Skip to content

Commit

Permalink
🐛 (loadtesting) use self.interrupt to allow user to change task and t…
Browse files Browse the repository at this point in the history
…askset
  • Loading branch information
Tobias-Pe committed Jul 14, 2024
1 parent f29acd7 commit f7ea5da
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions loadtesting/common/feedservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ def get_users_feed(self):
return
feeds[user_id] = response.json().get('content')
response.success()
self.interrupt()
2 changes: 2 additions & 0 deletions loadtesting/common/notificationservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def count_notifications(self):
user_id = random.choice(list(users.keys()))
self.client.post(f"/notificationservice/notifications/count?userId={user_id}",
name="/notificationservice/notifications/count")
self.interrupt()

@task
def get_notifications(self):
Expand All @@ -31,6 +32,7 @@ def get_notifications(self):
return
notification_id = random.choice(notifications).get("id")
self.change_notification_read_status(notification_id)
self.interrupt()

def change_notification_read_status(self, notification_id):
self.client.post(f"/notificationservice/notifications/{notification_id}?isRead={fake.boolean()}",
Expand Down
7 changes: 7 additions & 0 deletions loadtesting/common/postservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def create_post(self):
else:
posts[response.json().get("id")] = response.json()
response.success()
self.interrupt()

def generate_post_data(self):
words = fake.words(nb=fake.random_int(1, 6, 1), unique=True)
Expand Down Expand Up @@ -61,18 +62,21 @@ def if_no_post_exists_create(self):
def like_post(self):
post_id, user_id = self.get_post_and_user_pair()
self.client.post(f"/postservice/posts/{post_id}/like?userId={user_id}", name="/postservice/posts/{id}/like")
self.interrupt()

@task
def get_post(self):
self.if_no_post_exists_create()
post_id = random.choice(list(posts.keys()))
self.client.get(f"/postservice/posts/{post_id}", name="/postservice/posts/{id}")
self.interrupt()

@task
def get_post_image(self):
self.if_no_post_exists_create()
post_id = random.choice(list(posts.keys()))
self.client.get(f"/postservice/posts/{post_id}/image", name="/postservice/posts/{id}/image")
self.interrupt()

@task
def comment_post(self):
Expand All @@ -81,6 +85,7 @@ def comment_post(self):
self.client.post(f"/postservice/posts/{post_id}/comments",
json={"userId": user_id, "text": text},
name="/postservice/posts/{id}/comments")
self.interrupt()

def get_post_and_user_pair(self):
if len(feeds) > 0 and fake.boolean(50):
Expand All @@ -96,6 +101,7 @@ def get_post_and_user_pair(self):
@task
def get_categories(self):
self.get_categories_paginated(0)
self.interrupt()

def get_categories_paginated(self, page):
with self.client.get(f"/postservice/categories",
Expand All @@ -120,6 +126,7 @@ def get_posts(self):
category = random.choice(categories)

self.get_posts_paginated_filtered(0, category=category, user_id=user_id)
self.interrupt()

def get_posts_paginated_filtered(self, page, category=None, user_id=None):
params = f"?page={page}"
Expand Down
6 changes: 6 additions & 0 deletions loadtesting/common/userservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def create_user(self):
with self.client.post("/userservice/users", json={"username": fake.user_name()}, name="/userservice/users",
catch_response=True) as response:
handle_user_response(response)
self.interrupt()

def if_no_user_exists_create(self):
for _ in range(10):
Expand All @@ -39,6 +40,7 @@ def edit_profile(self):
name="/userservice/users/{id}",
catch_response=True) as response:
handle_user_response(response)
self.interrupt()

@task(8)
def follow(self):
Expand All @@ -52,18 +54,21 @@ def follow(self):
response.success()
return
response.failure(response.text)
self.interrupt()

@task
def get_followers(self):
self.if_no_user_exists_create()
user_id = random.choice(list(users.keys()))
self.client.get(f"/userservice/users/{user_id}/followers", name="/userservice/users/{id}/followers")
self.interrupt()

@task
def get_user(self):
self.if_no_user_exists_create()
user_id = random.choice(list(users.keys()))
self.client.get(f"/userservice/users/{user_id}", name="/userservice/users/{id}")
self.interrupt()

@task(2)
def search_user(self):
Expand All @@ -76,6 +81,7 @@ def search_user(self):
else:
letters = "%" + letters + "%"
self.search_user_paginated(letters, 0)
self.interrupt()

def search_user_paginated(self, query, page):
with self.client.post(f"/userservice/users/search?page={page}&query={query}", name="/userservice/users/search",
Expand Down
2 changes: 1 addition & 1 deletion loadtesting/locustfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class GatewayUser(HttpUser):
wait_time = between(0.5, 5)
tasks = {UserActions: 30, PostActions: 30, FeedActions: 15, NotificationActions: 10}
tasks = {UserActions: 20, PostActions: 30, FeedActions: 15, NotificationActions: 10}

minutes = 30

Expand Down

0 comments on commit f7ea5da

Please sign in to comment.