Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbaldwin44 committed Jul 31, 2024
1 parent b02474c commit 6200118
Showing 1 changed file with 37 additions and 48 deletions.
85 changes: 37 additions & 48 deletions locust/test/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1721,11 +1721,6 @@ def t(self):
text=True,
)
gevent.sleep(2)
# modify the locustfile to trigger warning about file change when the second worker connects
with open(mocked.file_path, "w") as locustfile:
locustfile.write(LOCUSTFILE_CONTENT)
locustfile.write("\n# New comment\n")
gevent.sleep(2)
proc_worker2 = subprocess.Popen(
[
"locust",
Expand All @@ -1742,7 +1737,6 @@ def t(self):
stdout_worker2 = proc_worker2.communicate()[0]

self.assertIn('All users spawned: {"User1": 1} (1 total users)', stdout)
self.assertIn("Locustfile contents changed on disk after first worker requested locustfile", stdout)
self.assertIn("Shutting down (exit code 0)", stdout)
self.assertNotIn("Traceback", stdout)
self.assertNotIn("Traceback", stdout_worker)
Expand Down Expand Up @@ -1818,49 +1812,44 @@ def t(self):
"""
)
with mock_locustfile(content=LOCUSTFILE_CONTENT) as mocked:
with mock_locustfile() as mocked2:
proc = subprocess.Popen(
[
"locust",
"-f",
f"{mocked.file_path}, {mocked2.file_path}",
"--headless",
"--master",
"-L",
"debug",
],
stderr=STDOUT,
stdout=PIPE,
text=True,
)
proc_worker = subprocess.Popen(
[
"locust",
"-f",
"-",
"--worker",
],
stderr=STDOUT,
stdout=PIPE,
text=True,
)
proc = subprocess.Popen(
[
"locust",
"-f",
f"{mocked.file_path},{mocked.file_path}",
"--headless",
"--master",
"--expect-workers",
"1",
"-t",
"1s",
],
stderr=STDOUT,
stdout=PIPE,
text=True,
)
proc_worker = subprocess.Popen(
[
"locust",
"-f",
"-",
"--worker",
],
stderr=STDOUT,
stdout=PIPE,
text=True,
)

try:
stdout = proc_worker.communicate(timeout=15)[0]
self.assertIn(
"Got error from master: locustfile must be a full path to a single locustfile for file distribution to work",
stdout,
)
proc.kill()
master_stdout = proc.communicate()[0]
self.assertIn(
"--locustfile must be a full path to a single locustfile for file distribution", master_stdout
)
except Exception:
proc.kill()
proc_worker.kill()
stdout, worker_stderr = proc_worker.communicate()
assert False, f"worker never finished: {stdout}"
stdout = proc.communicate()[0]
stdout_worker = proc_worker.communicate()[0]

self.assertIn('All users spawned: {"User1": 1} (1 total users)', stdout)
self.assertIn("Shutting down (exit code 0)", stdout)
self.assertNotIn("Traceback", stdout)
self.assertNotIn("Traceback", stdout_worker)

self.assertEqual(0, proc.returncode)
self.assertEqual(0, proc_worker.returncode)

def test_json_schema(self):
LOCUSTFILE_CONTENT = textwrap.dedent(
Expand Down

0 comments on commit 6200118

Please sign in to comment.