-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* rewrite of "request" events needed to simplify fix of #280. RestApiUser uses locust.contrib.fasthttp.FastHttpSession for synchronous requests as well. RequestLogger and RequestHandler is not inherited, but always added for users inheriting GrizzlyUser, and added as event listeners on the dedicated event hook. A new GrizzlyEventHook, so let through all exceptions. ResponseContextManager is only used with in RestApiUser._request, all events are fired from GrizzlyUser.request (final), so it's done the same for all users. * fixed tests * move the remains of grizzly.users.base to grizzly.users remove SftpUser, never used and does not work as intended as it was. remove unused interfaces, HttpRequests and FileRequests. * make sure that load users always have the "global" metadata dictionary and that any request tasks executed by a load user has a metadata dictionary that is the merged version of "global" metadata and any request specific metadata. where the request specific metadata has precedence over the global one. --------- Co-authored-by: boffman <[email protected]>
- Loading branch information
Showing
62 changed files
with
1,995 additions
and
3,452 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
"""Logic for grizzly specific events.""" | ||
from __future__ import annotations | ||
|
||
from abc import ABCMeta, abstractmethod | ||
from typing import TYPE_CHECKING, Any, List, Optional | ||
|
||
from locust.event import EventHook | ||
|
||
if TYPE_CHECKING: # pragma: no cover | ||
from grizzly.tasks import RequestTask | ||
from grizzly.types import GrizzlyResponse | ||
from grizzly.users import GrizzlyUser | ||
|
||
class GrizzlyEventHook(EventHook): | ||
"""Override locust.events.EventHook to get types, and not to catch any exceptions.""" | ||
|
||
_handlers: List[GrizzlyEventHandler] | ||
|
||
def __init__(self) -> None: | ||
self._handlers = [] | ||
|
||
def add_listener(self, handler: GrizzlyEventHandler) -> None: | ||
super().add_listener(handler) | ||
|
||
def remove_listener(self, handler: GrizzlyEventHandler) -> None: | ||
super().remove_listener(handler) | ||
|
||
def fire(self, *, reverse: bool = False, **kwargs: Any) -> None: | ||
handlers = reversed(self._handlers) if reverse else self._handlers | ||
|
||
for handler in handlers: | ||
handler(**kwargs) | ||
|
||
|
||
class GrizzlyEventHandler(metaclass=ABCMeta): | ||
user: GrizzlyUser | ||
event_hook: EventHook | ||
|
||
def __init__(self, user: GrizzlyUser) -> None: | ||
self.user = user | ||
self.event_hook = user.event_hook | ||
|
||
@abstractmethod | ||
def __call__( | ||
self, | ||
name: str, | ||
context: GrizzlyResponse, | ||
request: RequestTask, | ||
exception: Optional[Exception] = None, | ||
**kwargs: Any, | ||
) -> None: | ||
... | ||
|
||
|
||
from .request_logger import RequestLogger | ||
from .response_handler import ResponseHandler | ||
|
||
__all__ = [ | ||
'RequestLogger', | ||
'ResponseHandler', | ||
] |
Oops, something went wrong.