Skip to content

Commit fabf13e

Browse files
committed
extend locust test
1 parent 6903354 commit fabf13e

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

tests/performance/locustfiles/deployment_max_rps_single_endpoint.py

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

1111

12+
from collections.abc import Callable
13+
1214
from common.base_user import OsparcWebUserBase
1315
from locust import events, task
1416
from locust.argument_parser import LocustArgumentParser
@@ -23,9 +25,30 @@ def _(parser: LocustArgumentParser) -> None:
2325
default="/",
2426
help="The endpoint to test (e.g., /v0/health)",
2527
)
28+
parser.add_argument(
29+
"--http-method",
30+
type=str,
31+
default="GET",
32+
help="The HTTP method to test ('GET', 'POST', 'PUT', 'PATCH' or 'DELETE')",
33+
)
34+
parser.add_argument(
35+
"--body",
36+
type=str,
37+
default="",
38+
help="The optional HTTP body as json string",
39+
)
2640

2741

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

0 commit comments

Comments
 (0)