Skip to content

Commit 5ddb5ea

Browse files
committed
add option to generate random body and specify headers
1 parent 029dae0 commit 5ddb5ea

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

tests/performance/locustfiles/deployment_max_rps_single_endpoint.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import json
1313
from collections.abc import Callable
1414

15+
import jsf
1516
from common.base_user import OsparcWebUserBase
1617
from locust import events, task
1718
from locust.argument_parser import LocustArgumentParser
@@ -36,7 +37,19 @@ def _(parser: LocustArgumentParser) -> None:
3637
"--body",
3738
type=str,
3839
default="",
39-
help="The optional HTTP body as json string",
40+
help="Optional HTTP body as json string",
41+
)
42+
parser.add_argument(
43+
"--body-json-schema",
44+
type=str,
45+
default="",
46+
help="Optional JSON schema for the request body. If specified, the request data will be randomly generated from this schema.",
47+
)
48+
parser.add_argument(
49+
"--headers",
50+
type=str,
51+
default="",
52+
help="Optional HTTP headers as json string",
4053
)
4154

4255

@@ -52,4 +65,11 @@ def get_endpoint(self) -> None:
5265
kwargs = {}
5366
if len(self.environment.parsed_options.body) > 0:
5467
kwargs["json"] = json.loads(self.environment.parsed_options.body)
68+
if len(self.environment.parsed_options.body_json_schema) > 0:
69+
faker = jsf.JSF(
70+
json.loads(self.environment.parsed_options.body_json_schema)
71+
)
72+
kwargs["json"] = faker.generate()
73+
if len(self.environment.parsed_options.headers) > 0:
74+
kwargs["headers"] = json.loads(self.environment.parsed_options.headers)
5575
method(self.environment.parsed_options.endpoint, **kwargs)

0 commit comments

Comments
 (0)