Skip to content

Commit

Permalink
When making requests that’s redirected, use the last URL in the redir…
Browse files Browse the repository at this point in the history
…ect chain as name/label in the statistics.

Fixes #174
  • Loading branch information
heyman committed Sep 6, 2014
1 parent 25537b2 commit a912f5a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
10 changes: 10 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
Changelog
##########

In development
==============

* When making an HTTP request to an endpoint that responds with a redirect, the original
URL that was requested is now used as the name for that entry in the statistics (unless
an explicit override is specified through the *name* argument). Previously, the last
URL in the redirect chain was used to label the request(s) in the statistics.



0.7.1
=====

Expand Down
2 changes: 1 addition & 1 deletion locust/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def request(self, method, url, name=None, catch_response=False, **kwargs):
response = self._send_request_safe_mode(method, url, **kwargs)

request_meta["method"] = response.request.method
request_meta["name"] = name or response.request.path_url
request_meta["name"] = name or (response.history and response.history[0] or response).request.path_url

# record the consumed time
request_meta["response_time"] = timedelta_to_ms(response.elapsed)
Expand Down
12 changes: 12 additions & 0 deletions locust/test/test_locust_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,18 @@ class MyLocust(Locust):
self.assertRaises(LocustError, lambda: my_locust.client.get("/"))
my_taskset = MyTaskSet(my_locust)
self.assertRaises(LocustError, lambda: my_taskset.client.get("/"))

def test_redirect_url_original_path_as_name(self):
class MyLocust(HttpLocust):
host = "http://127.0.0.1:%i" % self.port

l = MyLocust()
l.client.get("/redirect")

from locust.stats import global_stats
self.assertEqual(1, len(global_stats.entries))
self.assertEqual(1, global_stats.get("/redirect", "GET").num_requests)
self.assertEqual(0, global_stats.get("/ultra_fast", "GET").num_requests)


class TestCatchResponse(WebserverTestCase):
Expand Down

0 comments on commit a912f5a

Please sign in to comment.