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

Log a message if total fixed_count is higher than number of users to spawn #2793

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
7 changes: 7 additions & 0 deletions locust/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,13 @@ def kill_workers(children):
# list() call is needed to consume the dict_view object in Python 3
user_classes = list(user_classes.values())

if not shape_class and options.num_users:
fixed_count_total = sum([user_class.fixed_count for user_class in user_classes])
if fixed_count_total > options.num_users:
logger.info(
f"Total fixed_count of User classes ({fixed_count_total}) is greater than the specified number of users ({options.num_users}), so not all will be spawned."
)

if os.name != "nt" and not options.master:
try:
import resource
Expand Down
50 changes: 50 additions & 0 deletions locust/test/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,48 @@ def test_spawing_with_fixed_multiple_locustfiles(self):
self.assertIn("Shutting down (exit code 0)", output)
self.assertEqual(0, proc.returncode)

def test_warning_with_lower_user_count_than_fixed_count(self):
LOCUSTFILE_CONTENT = textwrap.dedent(
"""
from locust import User, task, constant

class User1(User):
fixed_count = 2
wait_time = constant(1)

@task
def t(self):
pass

class User2(User):
fixed_count = 2
wait_time = constant(1)

@task
def t(self):
pass
"""
)
with mock_locustfile(content=LOCUSTFILE_CONTENT) as mocked:
proc = subprocess.Popen(
[
"locust",
"-f",
mocked.file_path,
"--headless",
"--run-time",
"1s",
"-u",
"3",
],
stderr=STDOUT,
stdout=PIPE,
text=True,
)

output = proc.communicate()[0]
self.assertIn("Total fixed_count of User classes (4) is greater than ", output)

def test_with_package_as_locustfile(self):
with TemporaryDirectory() as temp_dir:
with open(f"{temp_dir}/__init__.py", mode="w"):
Expand Down Expand Up @@ -1612,6 +1654,14 @@ def t(self):
stdout=PIPE,
text=True,
)
try:
stdout = proc.communicate(timeout=9)[0]
except Exception:
proc.kill()
proc_worker.kill()
stdout = proc.communicate()[0]
worker_stdout = proc_worker.communicate()[0]
assert False, f"master never finished: {stdout}, worker output: {worker_stdout}"
stdout = proc.communicate()[0]
proc_worker.communicate()

Expand Down
Loading