Skip to content

Commit 08faf79

Browse files
committed
login
1 parent ef693a8 commit 08faf79

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

tests/performance2/common/deploy_auth.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,12 @@ class MonitoringBasicAuth(BaseSettings):
99

1010
def to_auth(self) -> tuple[str, str]:
1111
return (self.SC_USER_NAME, self.SC_PASSWORD)
12+
13+
14+
class OsparcAuth(BaseSettings):
15+
model_config = SettingsConfigDict(extra="ignore")
16+
OSPARC_USER_NAME: str = Field(default=..., examples=["<your username>"])
17+
OSPARC_PASSWORD: str = Field(default=..., examples=["<your password>"])
18+
19+
def to_auth(self) -> tuple[str, str]:
20+
return (self.OS_USER_NAME, self.OS_PASSWORD)

tests/performance2/locustfiles/deployment_max_rps_single_endpoint.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import logging
1212

1313
import locust_plugins
14-
from common.deploy_auth import MonitoringBasicAuth
14+
from common.deploy_auth import MonitoringBasicAuth, OsparcAuth
1515
from locust import events, task
1616
from locust.contrib.fasthttp import FastHttpUser
1717

@@ -26,7 +26,7 @@
2626
_endpoint_holder = {"endpoint": "/"}
2727

2828

29-
def add_endpoint_argument(parser):
29+
def add_endpoint_argument(parser) -> None:
3030
parser.add_argument(
3131
"--endpoint",
3232
type=str,
@@ -42,7 +42,7 @@ def _(parser):
4242

4343

4444
@events.init.add_listener
45-
def _(environment, **_kwargs):
45+
def _(environment, **_kwargs) -> None:
4646
_endpoint_holder["endpoint"] = environment.parsed_options.endpoint
4747
logging.info("Testing endpoint: %s", _endpoint_holder["endpoint"])
4848

@@ -52,7 +52,25 @@ def __init__(self, *args, **kwargs):
5252
super().__init__(*args, **kwargs)
5353
self.auth = MonitoringBasicAuth().to_auth()
5454
self.endpoint = _endpoint_holder["endpoint"]
55+
self.osparc_auth = OsparcAuth()
56+
self.requires_login = False
5557

5658
@task
57-
def get_endpoint(self):
59+
def get_endpoint(self) -> None:
5860
self.client.get(self.endpoint, auth=self.auth)
61+
62+
def _login(self) -> None:
63+
# Implement login logic here
64+
logging.info("Logging in user with email: %s", self.osparc_auth)
65+
66+
def _logout(self) -> None:
67+
# Implement logout logic here
68+
logging.info("Logging out user with email: %s", self.osparc_auth)
69+
70+
def on_start(self) -> None:
71+
if self.requires_login:
72+
self._login()
73+
74+
def on_stop(self) -> None:
75+
if self.requires_login:
76+
self._logout()

0 commit comments

Comments
 (0)