Skip to content

Commit

Permalink
Fix issue 1944 -- make config option of html effect
Browse files Browse the repository at this point in the history
If running locust will be CTRL+C, `get_html_report` will be received by catching the exception.

Signed-off-by: Chenyang Yan <[email protected]>
  • Loading branch information
uddmorningsun committed Jan 30, 2022
1 parent ac80e3e commit 33083d2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion locust/argument_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ def setup_parser_arguments(parser):
stats_group.add_argument(
"--html",
dest="html_file",
help="Store HTML report file",
help="Store HTML report to file path specified",
env_var="LOCUST_HTML",
)

Expand Down
13 changes: 9 additions & 4 deletions locust/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,12 @@ def sig_term_handler():
logger.info("Got SIGTERM signal")
shutdown()

def save_html_report():
html_report = get_html_report(environment, show_download_link=False)
logger.info("writing html report to file: %s", options.html_file)
with open(options.html_file, "w", encoding="utf-8") as file:
file.write(html_report)

gevent.signal_handler(signal.SIGTERM, sig_term_handler)

try:
Expand All @@ -466,11 +472,10 @@ def sig_term_handler():

main_greenlet.join()
if options.html_file:
html_report = get_html_report(environment, show_download_link=False)
with open(options.html_file, "w", encoding="utf-8") as file:
file.write(html_report)
save_html_report()
except KeyboardInterrupt:
pass
if options.html_file:
save_html_report()
except Exception:
raise
shutdown()
4 changes: 3 additions & 1 deletion locust/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def __init__(
self.auth.init_app(self.app)
else:
raise AuthCredentialsError(
"Invalid auth_credentials. It should be a string in the following format: 'user.pass'"
"Invalid auth_credentials. It should be a string in the following format: 'user:pass'"
)
if environment.runner:
self.update_template_args()
Expand Down Expand Up @@ -174,6 +174,8 @@ def stop():
self._swarm_greenlet.kill(block=True)
self._swarm_greenlet = None
environment.runner.stop()
if self.greenlet is not None:
self.greenlet.kill(block=True)
return jsonify({"success": True, "message": "Test stopped"})

@app.route("/stats/reset")
Expand Down

0 comments on commit 33083d2

Please sign in to comment.