Skip to content

Commit

Permalink
Min and max response times rounded to nearest int in web view
Browse files Browse the repository at this point in the history
  • Loading branch information
ajt89 authored and cgoldberg committed Sep 24, 2019
1 parent 610a87f commit 3b2fd9f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
10 changes: 10 additions & 0 deletions locust/test/test_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ def test_stats_cache(self):
data = json.loads(requests.get("http://127.0.0.1:%i/stats/requests" % self.web_port).text)
self.assertEqual(3, len(data["stats"])) # this should no longer be cached

def test_stats_rounding(self):
stats.global_stats.log_request("GET", "/test", 1.5, 15)
stats.global_stats.log_request("GET", "/test", 999.99, 99999)
response = requests.get("http://127.0.0.1:%i/stats/requests" % self.web_port)
self.assertEqual(200, response.status_code)

data = json.loads(response.text)
self.assertEqual(2, data["stats"][0]["min_response_time"])
self.assertEqual(1000, data["stats"][0]["max_response_time"])

def test_request_stats_csv(self):
stats.global_stats.log_request("GET", "/test2", 120, 5612)
response = requests.get("http://127.0.0.1:%i/stats/requests/csv" % self.web_port)
Expand Down
5 changes: 3 additions & 2 deletions locust/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,15 @@ def request_stats():
stats = []

for s in chain(sort_stats(runners.locust_runner.request_stats), [runners.locust_runner.stats.total]):
0 if s.min_response_time is None else round(s.min_response_time)
stats.append({
"method": s.method,
"name": s.name,
"num_requests": s.num_requests,
"num_failures": s.num_failures,
"avg_response_time": s.avg_response_time,
"min_response_time": s.min_response_time or 0,
"max_response_time": s.max_response_time,
"min_response_time": 0 if s.min_response_time is None else round(s.min_response_time),
"max_response_time": round(s.max_response_time),
"current_rps": s.current_rps,
"median_response_time": s.median_response_time,
"avg_content_length": s.avg_content_length,
Expand Down

0 comments on commit 3b2fd9f

Please sign in to comment.