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

Change logging of call to sys.exit() to info level #2490

Merged
merged 1 commit into from
Nov 27, 2023
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/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def greenlet_exception_logger(logger, level=logging.CRITICAL):
def exception_handler(greenlet):
if greenlet.exc_info[0] == SystemExit:
logger.log(
level,
min(logging.INFO, level), # dont use higher than INFO for this, because it sounds way to urgent
"sys.exit(%s) called (exception callstack suppressed, use log level DEBUG for more info)"
% greenlet.exc_info[1],
)
Expand Down
44 changes: 44 additions & 0 deletions locust/test/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1948,3 +1948,47 @@ def test_processes_error_doesnt_blow_up_completely(self):
# the error message should repeat 4 times for the workers and once for the master
self.assertEqual(stderr.count("Unknown User(s): UserThatDoesntExist"), 5)
self.assertNotIn("Traceback", stderr)

def test_processes_workers_quit_unexpected(self):
content = """
from locust import runners, events, User
import sys

@events.test_start.add_listener
def on_test_start(environment, **_kwargs):
if isinstance(environment.runner, runners.WorkerRunner):
sys.exit(42)

class AnyUser(User):
pass
"""
with mock_locustfile(content=content) as mocked:
worker_proc = subprocess.Popen(
["locust", "-f", mocked.file_path, "--processes", "2", "--worker"],
stdout=PIPE,
stderr=PIPE,
text=True,
)
master_proc = subprocess.Popen(
["locust", "-f", mocked.file_path, "--master", "--headless", "-t", "5"],
stdout=PIPE,
stderr=PIPE,
text=True,
)
try:
_, stderr = worker_proc.communicate(timeout=3)
status_code = worker_proc.wait()
except Exception:
worker_proc.kill()
_, stderr = worker_proc.communicate()
assert False, f"worker process never finished: {stderr}"
finally:
gevent.sleep(4)
master_proc.kill()
_, master_stderr = master_proc.communicate()

self.assertNotIn("Traceback", stderr)
self.assertIn("INFO/locust.runners: sys.exit(42) called", stderr)
self.assertEqual(status_code, 42)
self.assertNotIn("Traceback", master_stderr)
self.assertIn("failed to send heartbeat, setting state to missing", master_stderr)
Loading