Skip to content

Commit

Permalink
Merge pull request #3020 from locustio/optimize-run-time-of-unit-tests
Browse files Browse the repository at this point in the history
Optimize run time of some unit tests
  • Loading branch information
cyberw authored Jan 5, 2025
2 parents 77ac16a + 5a6def7 commit e5c99eb
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ jobs:
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.8.5
virtualenvs-create: true
virtualenvs-in-project: true
virtualenvs-path: .venv
Expand Down Expand Up @@ -165,6 +166,7 @@ jobs:
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.8.5
virtualenvs-create: true
virtualenvs-in-project: true
virtualenvs-path: .venv
Expand Down
2 changes: 1 addition & 1 deletion docs/developing-locust.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Fork Locust on `GitHub <https://github.com/locustio/locust/>`_ and then
# clone the repo:
$ git clone git://github.com/<YourName>/locust.git
# install the poetry build system, see https://python-poetry.org/docs/#installation
# install the poetry build system, version 1.8.5, see https://python-poetry.org/docs/#installation
# install the required poetry plugins:
$ poetry self add "poethepoet[poetry_plugin]"
Expand Down
7 changes: 7 additions & 0 deletions locust/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,10 @@
changed_rlimit = True
except Exception:
changed_rlimit = False

import os

# Clean environment from stuff you might have lying around
os.environ.pop("LOCUST_WEB_LOGIN", None)
# Ensure locust-cloud is not loaded during tests
os.environ.pop("PGHOST", None)
24 changes: 14 additions & 10 deletions locust/test/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,14 +613,14 @@ def test_autostart_wo_run_time(self):
response = requests.get(f"http://localhost:{port}/")
except Exception:
pass
self.assertEqual(200, response.status_code)
proc.send_signal(signal.SIGTERM)
stdout, stderr = proc.communicate()
self.assertIn("Starting Locust", stderr)
self.assertIn("No run time limit set, use CTRL+C to interrupt", stderr)
self.assertIn("Shutting down ", stderr)
self.assertNotIn("Traceback", stderr)
# check response afterwards, because it really isn't as informative as stderr
self.assertEqual(200, response.status_code)
d = pq(response.content.decode("utf-8"))

self.assertEqual(200, response.status_code)
Expand Down Expand Up @@ -885,7 +885,7 @@ def t(self):
mocked.file_path,
"--headless",
"--run-time",
"7s",
"6s",
"-u",
"0",
"--loglevel",
Expand Down Expand Up @@ -999,7 +999,7 @@ def test_spawing_with_fixed_multiple_locustfiles(self):
f"{mocked1.file_path},{mocked2.file_path}",
"--headless",
"--run-time",
"5s",
"2s",
"-u",
"10",
"-r",
Expand Down Expand Up @@ -1053,7 +1053,7 @@ def t(self):
mocked.file_path,
"--headless",
"--run-time",
"1s",
"0.5",
"-u",
"3",
],
Expand Down Expand Up @@ -1674,8 +1674,10 @@ def t(self):
"1",
"-u",
"3",
"-r",
"99",
"-t",
"5s",
"1s",
],
stderr=STDOUT,
stdout=PIPE,
Expand Down Expand Up @@ -1737,8 +1739,10 @@ def t(self):
"1",
"-u",
"3",
"-r",
"99",
"-t",
"5s",
"1s",
],
stderr=STDOUT,
stdout=PIPE,
Expand All @@ -1759,7 +1763,7 @@ def t(self):
proc_worker.communicate()

self.assertIn(
'Spawning is complete and report waittime is expired, but not all reports received from workers: {"User1": 2} (2 total users)',
"Spawning is complete and report waittime is expired, but not all reports received from workers:",
stdout,
)
self.assertIn("Shutting down (exit code 0)", stdout)
Expand Down Expand Up @@ -1808,7 +1812,7 @@ def t(self):
stdout=PIPE,
text=True,
)
gevent.sleep(2)
gevent.sleep(1)
proc_worker2 = subprocess.Popen(
[
"locust",
Expand Down Expand Up @@ -1858,7 +1862,7 @@ def t(self):
stdout=PIPE,
text=True,
)
gevent.sleep(2)
gevent.sleep(1)
proc = subprocess.Popen(
[
"locust",
Expand Down Expand Up @@ -1916,7 +1920,6 @@ def t(self):
stdout=PIPE,
text=True,
)
gevent.sleep(2)
proc_worker = subprocess.Popen(
[
"locust",
Expand Down Expand Up @@ -1998,6 +2001,7 @@ def hello_world(self):
self.assertEqual(dict, type(result["num_reqs_per_sec"]))
self.assertEqual(dict, type(result["num_fail_per_sec"]))

@unittest.skipIf(True, reason="This test is too slow for the value it provides")
def test_worker_indexes(self):
content = """
from locust import HttpUser, task, between
Expand Down

0 comments on commit e5c99eb

Please sign in to comment.