diff --git a/locust/event.py b/locust/event.py index 679936bd0f..fc1f9be4e8 100644 --- a/locust/event.py +++ b/locust/event.py @@ -73,33 +73,6 @@ class Events: :param exception: Exception instance that was thrown. None if request was successful. """ - request_success: DeprecatedEventHook - """ - DEPRECATED. Fired when a request is completed successfully. This event is typically used to report requests - when writing custom clients for locust. - - Event arguments: - - :param request_type: Request type method used - :param name: Path to the URL that was called (or override name if it was used in the call to the client) - :param response_time: Response time in milliseconds - :param response_length: Content-length of the response - """ - - request_failure: DeprecatedEventHook - """ - DEPRECATED. Fired when a request fails. This event is typically used to report failed requests when writing - custom clients for locust. - - Event arguments: - - :param request_type: Request type method used - :param name: Path to the URL that was called (or override name if it was used in the call to the client) - :param response_time: Time in milliseconds until exception was thrown - :param response_length: Content-length of the response - :param exception: Exception instance that was thrown - """ - user_error: EventHook """ Fired when an exception occurs inside the execution of a User class. @@ -169,8 +142,7 @@ class Events: """ Fired when Locust is started, once the Environment instance and locust runner instance have been created. This hook can be used by end-users' code to run code that requires access to - the Environment. For example to register listeners to request_success, request_failure - or other events. + the Environment. For example to register listeners to other events. Event arguments: @@ -221,28 +193,3 @@ def __init__(self): for name, value in self.__annotations__.items(): if value == EventHook: setattr(self, name, value()) - - self.request_success = DeprecatedEventHook("request_success event deprecated. Use the request event.") - - self.request_failure = DeprecatedEventHook("request_failure event deprecated. Use the request event.") - - def fire_deprecated_request_handlers( - request_type, name, response_time, response_length, exception, context, **kwargs - ): - if exception: - self.request_failure.fire( - request_type=request_type, - name=name, - response_time=response_time, - response_length=response_length, - exception=exception, - ) - else: - self.request_success.fire( - request_type=request_type, - name=name, - response_time=response_time, - response_length=response_length, - ) - - self.request.add_listener(fire_deprecated_request_handlers) diff --git a/locust/runners.py b/locust/runners.py index 63f3465139..78db6749a3 100644 --- a/locust/runners.py +++ b/locust/runners.py @@ -130,19 +130,12 @@ def __init__(self, environment: "Environment") -> None: self._users_dispatcher: Optional[UsersDispatcher] = None # set up event listeners for recording requests - def on_request_success(request_type, name, response_time, response_length, **_kwargs): + def on_request(request_type, name, response_time, response_length, exception=None, **_kwargs): self.stats.log_request(request_type, name, response_time, response_length) + if exception: + self.stats.log_error(request_type, name, exception) - def on_request_failure(request_type, name, response_time, response_length, exception, **_kwargs): - self.stats.log_request(request_type, name, response_time, response_length) - self.stats.log_error(request_type, name, exception) - - # temporarily set log level to ignore warnings to suppress deprecation message - loglevel = logging.getLogger().level - logging.getLogger().setLevel(logging.ERROR) - self.environment.events.request_success.add_listener(on_request_success) - self.environment.events.request_failure.add_listener(on_request_failure) - logging.getLogger().setLevel(loglevel) + self.environment.events.request.add_listener(on_request) self.connection_broken = False self.final_user_classes_count: Dict[str, int] = {} # just for the ratio report, fills before runner stops diff --git a/locust/test/test_fasthttp.py b/locust/test/test_fasthttp.py index 2c64acf996..70f5d37f45 100644 --- a/locust/test/test_fasthttp.py +++ b/locust/test/test_fasthttp.py @@ -693,25 +693,6 @@ def test_catch_response_missing_with_block(self): self.assertRaises(LocustError, r.success) self.assertRaises(LocustError, r.failure, "") - def test_deprecated_request_events(self): - status = {"success_amount": 0, "failure_amount": 0} - - def on_success(**kw): - status["success_amount"] += 1 - - def on_failure(**kw): - status["failure_amount"] += 1 - - self.environment.events.request_success.add_listener(on_success) - self.environment.events.request_failure.add_listener(on_failure) - with self.user.client.get("/ultra_fast", catch_response=True) as response: - pass - with self.user.client.get("/wrong_url", catch_response=True) as response: - pass - - self.assertEqual(1, status["success_amount"]) - self.assertEqual(1, status["failure_amount"]) - def test_missing_catch_response_true(self): # incorrect usage, missing catch_response=True with self.user.client.get("/fail") as resp: diff --git a/locust/test/test_http.py b/locust/test/test_http.py index f402d94b53..0cf7d71728 100644 --- a/locust/test/test_http.py +++ b/locust/test/test_http.py @@ -145,23 +145,6 @@ def on_request(**kw): s.request("get", "/wrong_url") self.assertEqual("Not Found", kwargs["response"].text) - def test_deprecated_request_events(self): - s = self.get_client() - status = {"success_amount": 0, "failure_amount": 0} - - def on_success(**kw): - status["success_amount"] += 1 - - def on_failure(**kw): - status["failure_amount"] += 1 - - self.environment.events.request_success.add_listener(on_success) - self.environment.events.request_failure.add_listener(on_failure) - s.request("get", "/request_method") - s.request("get", "/wrong_url") - self.assertEqual(1, status["success_amount"]) - self.assertEqual(1, status["failure_amount"]) - def test_error_message_with_name_replacement(self): s = self.get_client() kwargs = {}