Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add errors grouping for dynamic endpoint #993

Merged
merged 1 commit into from
Oct 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions locust/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ def request(self, method, url, name=None, catch_response=False, **kwargs):
return ResponseContextManager(response)
else:
try:
if name:
orig_url = response.url
response.url = name
response.raise_for_status()
except RequestException as e:
events.request_failure.fire(
Expand All @@ -146,6 +149,8 @@ def request(self, method, url, name=None, catch_response=False, **kwargs):
response_time=request_meta["response_time"],
response_length=request_meta["content_size"],
)
if name:
response.url = orig_url
return response

def _send_request_safe_mode(self, method, url, **kwargs):
Expand Down
16 changes: 15 additions & 1 deletion locust/test/test_client.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from requests.exceptions import (InvalidSchema, InvalidURL, MissingSchema,
RequestException)

from locust import events
from locust.clients import HttpSession
from locust.stats import global_stats

from .testcases import WebserverTestCase


Expand Down Expand Up @@ -97,3 +97,17 @@ def test_options(self):
set(["OPTIONS", "DELETE", "PUT", "GET", "POST", "HEAD"]),
set(r.headers["allow"].split(", ")),
)

def test_error_message_with_name_replacment(self):
s = HttpSession("http://127.0.0.1:%i" % self.port)
my_event = events.EventHook()
kwargs = {}
def on_my_event(**kw):
kwargs.update(kw)

my_event += on_my_event
orig_events = events.request_failure
events.request_failure = my_event
s.request('get', '/wrong_url/01', name='replaced_url_name')
events.request_failure = orig_events
self.assertIn('for url: replaced_url_name', str(kwargs['exception']))