Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix --html report in web mode #1992

Merged
merged 1 commit into from
Jan 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... I'm worried this might cause issues with repeated gui runs. Have you tried that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does meaning of repeated gui runs? I guess that different --web-port to run?

I have tried that it's normal to start again after sending the stop button, even for different ports.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tried that it's normal to start again after sending the stop button, even for different ports.

That's all I meant :) Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, it's my fault 😐 for the issue #1995. Again, I understood the meaning of with repeated gui runs, run multiple tests in one running locust environment.

return jsonify({"success": True, "message": "Test stopped"})

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