Skip to content

Commit 64635ff

Browse files
committed
ongoing
1 parent 0aa9a44 commit 64635ff

File tree

3 files changed

+33
-40
lines changed

3 files changed

+33
-40
lines changed

tests/performance/common/base_user.py

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
1+
import json
12
import logging
3+
from typing import Any
24

3-
from locust import FastHttpUser
5+
import locust_plugins
6+
from locust import FastHttpUser, events
7+
from locust.env import Environment
48

59
from .auth_settings import DeploymentAuth, OsparcAuth
610

711
_logger = logging.getLogger(__name__)
812

13+
# NOTE: 'import locust_plugins' is necessary to use --check-fail-ratio
14+
# this assert is added to avoid that pycln pre-commit hook does not
15+
# remove the import (the tool assumes the import is not necessary)
16+
assert locust_plugins # nosec
17+
918

1019
class OsparcUserBase(FastHttpUser):
1120
"""
@@ -49,6 +58,23 @@ def authenticated_patch(self, url, **kwargs):
4958
return self.client.patch(url, **kwargs)
5059

5160

61+
@events.init_command_line_parser.add_listener
62+
def _(parser) -> None:
63+
parser.add_argument(
64+
"--requires-login",
65+
action="store_true",
66+
default=False,
67+
help="Indicates if the user requires login before accessing the endpoint",
68+
)
69+
70+
71+
@events.init.add_listener
72+
def _(environment: Environment, **_kwargs: Any) -> None:
73+
# Only log the parsed options, as the full environment is not JSON serializable
74+
options_dict: dict[str, Any] = vars(environment.parsed_options)
75+
_logger.debug("Testing environment options: %s", json.dumps(options_dict, indent=2))
76+
77+
5278
class OsparcWebUserBase(OsparcUserBase):
5379
"""
5480
Base class for web users in Locust that provides common functionality.
@@ -85,10 +111,6 @@ def on_stop(self) -> None:
85111

86112
def _login(self) -> None:
87113
# Implement login logic here
88-
logging.info(
89-
"Logging in user with email: %s",
90-
self.osparc_auth.OSPARC_USER_NAME,
91-
)
92114
response = self.authenticated_post(
93115
"/v0/auth/login",
94116
json={
@@ -97,11 +119,13 @@ def _login(self) -> None:
97119
},
98120
)
99121
response.raise_for_status()
100-
logging.info("Logged in user with email: %s", self.osparc_auth.OSPARC_USER_NAME)
122+
logging.debug(
123+
"Logged in user with email: %s", self.osparc_auth.OSPARC_USER_NAME
124+
)
101125

102126
def _logout(self) -> None:
103127
# Implement logout logic here
104128
self.authenticated_post("/v0/auth/logout")
105-
logging.info(
129+
logging.debug(
106130
"Logged out user with email: %s", self.osparc_auth.OSPARC_USER_NAME
107131
)

tests/performance/locustfiles/deployment_max_rps_single_endpoint.py

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,41 +8,21 @@
88
# If no endpoint is specified, the root endpoint ("/") will be used by default.
99
#
1010

11-
import logging
1211

13-
import locust_plugins
1412
from common.base_user import OsparcWebUserBase
1513
from locust import events, task
16-
17-
_logger = logging.getLogger(__name__)
18-
19-
# NOTE: 'import locust_plugins' is necessary to use --check-fail-ratio
20-
# this assert is added to avoid that pycln pre-commit hook does not
21-
# remove the import (the tool assumes the import is not necessary)
22-
assert locust_plugins # nosec
14+
from locust.argument_parser import LocustArgumentParser
2315

2416

2517
# Register the custom argument with Locust's parser
2618
@events.init_command_line_parser.add_listener
27-
def _(parser) -> None:
19+
def _(parser: LocustArgumentParser) -> None:
2820
parser.add_argument(
2921
"--endpoint",
3022
type=str,
3123
default="/",
3224
help="The endpoint to test (e.g., /v0/health)",
3325
)
34-
parser.add_argument(
35-
"--requires-login",
36-
action="store_true",
37-
default=False,
38-
help="Indicates if the user requires login before accessing the endpoint",
39-
)
40-
41-
42-
@events.init.add_listener
43-
def _(environment, **_kwargs) -> None:
44-
_logger.info("Testing endpoint: %s", environment.parsed_options.endpoint)
45-
_logger.info("Requires login: %s", environment.parsed_options.requires_login)
4626

4727

4828
class WebApiUser(OsparcWebUserBase):

tests/performance/locustfiles/webserver_services.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,13 @@
66
import urllib
77
import urllib.parse
88

9-
import faker
109
import locust
1110
from common.base_user import OsparcWebUserBase
12-
from dotenv import load_dotenv
1311

1412
_logger = logging.getLogger(__name__)
1513

16-
fake = faker.Faker()
17-
18-
load_dotenv() # take environment variables from .env
19-
2014

2115
class WebApiUser(OsparcWebUserBase):
22-
def __init__(self, *args, **kwargs):
23-
super().__init__(*args, **kwargs)
24-
self.email = fake.email()
25-
self.password = "testtesttest" # noqa: S105
26-
2716
@locust.task
2817
def list_latest_services(self):
2918
base_url = "/v0/catalog/services/-/latest"

0 commit comments

Comments
 (0)