Skip to content

Commit 4c80da2

Browse files
🎨 Extend locust tests for testing individual endpoints (#7955)
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent dc56a2a commit 4c80da2

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

tests/performance/locustfiles/deployment_max_rps_single_endpoint.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
#
1010

1111

12+
import json
13+
from collections.abc import Callable
14+
1215
from common.base_user import OsparcWebUserBase
1316
from locust import events, task
1417
from locust.argument_parser import LocustArgumentParser
@@ -23,9 +26,30 @@ def _(parser: LocustArgumentParser) -> None:
2326
default="/",
2427
help="The endpoint to test (e.g., /v0/health)",
2528
)
29+
parser.add_argument(
30+
"--http-method",
31+
type=str,
32+
default="GET",
33+
help="The HTTP method to test ('GET', 'POST', 'PUT', 'PATCH' or 'DELETE')",
34+
)
35+
parser.add_argument(
36+
"--body",
37+
type=str,
38+
default="",
39+
help="The optional HTTP body as json string",
40+
)
2641

2742

2843
class WebApiUser(OsparcWebUserBase):
2944
@task
3045
def get_endpoint(self) -> None:
31-
self.authenticated_get(self.environment.parsed_options.endpoint)
46+
http_method = self.environment.parsed_options.http_method.lower()
47+
method = getattr(self, f"authenticated_{http_method}")
48+
if not isinstance(method, Callable):
49+
msg = f"Unsupported HTTP method: {http_method}"
50+
raise TypeError(msg)
51+
52+
kwargs = {}
53+
if len(self.environment.parsed_options.body) > 0:
54+
kwargs["json"] = json.loads(self.environment.parsed_options.body)
55+
method(self.environment.parsed_options.endpoint, **kwargs)

0 commit comments

Comments
 (0)