Skip to content

Commit

Permalink
test_log: Add test case for exceptions happening in on_start
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberw committed Nov 1, 2023
1 parent 0427175 commit 2493c56
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions locust/test/test_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,33 @@ def my_task(self):
f"{socket.gethostname()}/INFO/root: custom log message",
log_content,
)

def test_user_broken_on_start(self):
with temporary_file(
textwrap.dedent(
"""
from locust import HttpUser, task
class TestUser(HttpUser):
host = "invalidhost"
def on_start(self):
self.client.get("/")
"""
)
) as file_path:
output = subprocess.check_output(
[
"locust",
"-f",
file_path,
"-t",
"1",
"--headless",
],
stderr=subprocess.STDOUT,
timeout=10,
text=True,
)

self.assertIn("ERROR/locust.user.users: Invalid URL", output)

0 comments on commit 2493c56

Please sign in to comment.