-
-
Notifications
You must be signed in to change notification settings - Fork 278
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
ba39a87
commit 729cd6b
Showing
4 changed files
with
86 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FROM python:3.11-slim | ||
WORKDIR /app/locust | ||
RUN pip install locust |
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,15 @@ | ||
version: '3.8' | ||
|
||
services: | ||
locust: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
ports: | ||
- "8089:8089" # Expose Locust web UI | ||
volumes: | ||
- ./:/app/locust | ||
working_dir: /app/locust | ||
entrypoint: locust -f /app/locust/locustfile.py | ||
environment: | ||
LOCUST_HOST: "https://tm.naxa.com.np" |
Empty file.
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,68 @@ | ||
import os | ||
from locust import HttpUser, TaskSet, task, between | ||
|
||
class ProjectAndComments(TaskSet): | ||
@task | ||
def get_project(self): | ||
self.client.get("/api/v2/projects/114/") | ||
|
||
@task | ||
def get_comments(self): | ||
self.client.get("/api/v2/projects/114/comments/") | ||
|
||
class GetSimilarProjects(TaskSet): | ||
@task | ||
def get_similar_projects(self): | ||
self.client.get("/api/v2/projects/queries/114/similar-projects/") | ||
|
||
class GetContributions(TaskSet): | ||
@task | ||
def get_contributions(self): | ||
self.client.get("/api/v2/projects/114/contributions/") | ||
|
||
class GetContributionsByDay(TaskSet): | ||
@task | ||
def get_contributions_by_day(self): | ||
self.client.get("/api/v2/projects/114/contributions/queries/day/") | ||
|
||
class GetStatistics(TaskSet): | ||
@task | ||
def get_statistics(self): | ||
self.client.get("/api/v2/system/statistics/") | ||
|
||
class GetActionAny(TaskSet): | ||
@task | ||
def get_action_any(self): | ||
self.client.get("/api/v2/projects/?action=any") | ||
|
||
# Mapping task names to classes | ||
task_mapping = { | ||
"project_and_comments": ProjectAndComments, | ||
"similar_projects": GetSimilarProjects, | ||
"contributions": GetContributions, | ||
"contributions_by_day": GetContributionsByDay, | ||
"statistics": GetStatistics, | ||
"action_any": GetActionAny, | ||
} | ||
|
||
# User class | ||
class ApiBenchmarkUser(HttpUser): | ||
wait_time = between(1, 2) | ||
|
||
# Dynamically select tasks based on environment variable or CLI parameter | ||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
task_name = os.getenv("TASK_SET", "project_and_comments").lower() | ||
self.tasks = [task_mapping.get(task_name, ProjectAndComments)] | ||
|
||
|
||
''' | ||
/api/v2/projects/?action=any&omitMapResults=true | ||
/api/v2/projects/114/ | ||
/api/v2/projects/114/comments/ | ||
/api/v2/projects/queries/114/similar-projects/ | ||
/api/v2/projects/114/contributions/ | ||
/api/v2/projects/114/contributions/queries/day/ | ||
/api/v2/system/statistics/ | ||
/api/v2/projects/?action=any | ||
''' |