Skip to content

Commit

Permalink
Correct fail ratio calculation. Fixes locustio#991.
Browse files Browse the repository at this point in the history
  • Loading branch information
genericmoniker committed Apr 7, 2019
1 parent 8b17c28 commit ecd46b2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion locust/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def log_error(self, error):
@property
def fail_ratio(self):
try:
return float(self.num_failures) / (self.num_requests + self.num_failures)
return float(self.num_failures) / self.num_requests
except ZeroDivisionError:
if self.num_failures > 0:
return 1.0
Expand Down
12 changes: 12 additions & 0 deletions locust/test/test_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,18 @@ def test_diff_response_times_dicts(self):
))


class TestStatsEntry(unittest.TestCase):
def setUp(self, *args, **kwargs):
super(TestStatsEntry, self).setUp(*args, **kwargs)
self.stats = RequestStats()

def test_fail_ratio_with_failures(self):
s = StatsEntry(self.stats, "/", "GET")
s.num_requests = 10
s.num_failures = 5
self.assertAlmostEqual(s.fail_ratio, 0.5)


class TestRequestStatsWithWebserver(WebserverTestCase):
def test_request_stats_content_length(self):
class MyLocust(HttpLocust):
Expand Down

0 comments on commit ecd46b2

Please sign in to comment.