Skip to content

Commit

Permalink
Fixed bug introduced by #451 causing request stats endpoint to break …
Browse files Browse the repository at this point in the history
…when there were any failures.

Fixes #481
  • Loading branch information
heyman committed Sep 21, 2016
1 parent baf25dd commit c54b35f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 3 additions & 3 deletions locust/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,15 +366,15 @@ def __init__(self, method, name, error, occurences=0):

@classmethod
def parse_error(cls, error):
string_error = str(error)
string_error = repr(error)
target = "object at 0x"
target_index = string_error.find(target)
if target_index < 0:
return error
return string_error
start = target_index + len(target) - 2
end = string_error.find(">", start)
if end < 0:
return error
return string_error
hex_address = string_error[start:end]
return string_error.replace(hex_address, "0x....")

Expand Down
9 changes: 9 additions & 0 deletions locust/test/test_web.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# encoding: utf-8

import csv
import json
import sys
Expand All @@ -23,6 +25,8 @@ def setUp(self):
options = parser.parse_args([])[0]
runners.locust_runner = LocustRunner([], options)

web.request_stats.clear_cache()

self._web_ui_server = wsgi.WSGIServer(('127.0.0.1', 0), web.app, log=None)
gevent.spawn(lambda: self._web_ui_server.serve_forever())
gevent.sleep(0.01)
Expand Down Expand Up @@ -76,6 +80,11 @@ def test_distribution_stats_csv(self):
response = requests.get("http://127.0.0.1:%i/stats/distribution/csv" % self.web_port)
self.assertEqual(200, response.status_code)

def test_request_stats_with_errors(self):
stats.global_stats.get("/", "GET").log_error(Exception("Error1337"))
response = requests.get("http://127.0.0.1:%i/stats/requests" % self.web_port)
self.assertEqual(200, response.status_code)

def test_exceptions(self):
try:
raise Exception(u"A cool test exception")
Expand Down

0 comments on commit c54b35f

Please sign in to comment.