Skip to content

Commit

Permalink
Merge pull request #1784 from mboutet/fix-html-download
Browse files Browse the repository at this point in the history
Ensure that the exception dictionaries are not mutated when generating a html report
  • Loading branch information
cyberw authored Jun 11, 2021
2 parents 088a98b + 08716b2 commit 198fc7c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 3 additions & 4 deletions locust/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ def get_html_report(environment, show_download_link=True):

requests_statistics = list(chain(sort_stats(stats.entries), [stats.total]))
failures_statistics = sort_stats(stats.errors)
exceptions_statistics = []
for exc in environment.runner.exceptions.values():
exc["nodes"] = ", ".join(exc["nodes"])
exceptions_statistics.append(exc)
exceptions_statistics = [
{**exc, "nodes": ", ".join(exc["nodes"])} for exc in environment.runner.exceptions.values()
]

history = stats.history

Expand Down
8 changes: 8 additions & 0 deletions locust/test/test_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,14 @@ def test_report_exceptions(self):
# self.assertEqual(200, r.status_code)
self.assertIn("<h2>Exceptions Statistics</h2>", r.text)

# Prior to 088a98bf8ff4035a0de3becc8cd4e887d618af53, the "nodes" field for each exception in
# "self.runner.exceptions" was accidentally mutated in "get_html_report" to a string.
# This assertion reproduces the issue and it is left there to make sure there's no
# regression in the future.
self.assertTrue(
isinstance(next(iter(self.runner.exceptions.values()))["nodes"], set), "exception object has been mutated"
)


class TestWebUIAuth(LocustTestCase):
def setUp(self):
Expand Down

0 comments on commit 198fc7c

Please sign in to comment.