From 2bf7ffa220cb339a66565e765398cc2ccf2a3322 Mon Sep 17 00:00:00 2001 From: Lars Holmberg Date: Sun, 4 Feb 2024 15:40:29 +0100 Subject: [PATCH 1/6] GH actions: run tests on macos --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a4ae171656..df4cc2f25e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -15,7 +15,7 @@ jobs: matrix: include: - {name: Windows, python: '3.12', os: windows-latest, tox: fail_fast_test_main} - #- {name: Mac, python: '3.9', os: macos-latest, tox: py39} + - {name: Mac, python: '3.12', os: macos-latest, tox: fail_fast_test_main} - { name: "ruff", python: "3.11", os: ubuntu-latest, tox: "ruff" } - { name: "mypy", python: "3.10", os: ubuntu-latest, tox: "mypy" } # run some integration tests and abort immediately if they fail, for faster feedback From 7c884287b7d3d6ff29e4cb299d6bd6d221948a54 Mon Sep 17 00:00:00 2001 From: Lars Holmberg Date: Sun, 4 Feb 2024 16:43:42 +0100 Subject: [PATCH 2/6] unit tests: avoid warning in test --- locust/test/test_main.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/locust/test/test_main.py b/locust/test/test_main.py index 87d7eef687..8329a7d8e8 100644 --- a/locust/test/test_main.py +++ b/locust/test/test_main.py @@ -2011,7 +2011,7 @@ def test_processes_error_doesnt_blow_up_completely(self): @unittest.skipIf(os.name == "nt", reason="--processes doesnt work on windows") def test_processes_workers_quit_unexpected(self): content = """ -from locust import runners, events, User +from locust import runners, events, User, task import sys @events.test_start.add_listener @@ -2020,7 +2020,9 @@ def on_test_start(environment, **_kwargs): sys.exit(42) class AnyUser(User): - pass + @task + def mytask(self): + pass """ with mock_locustfile(content=content) as mocked: worker_proc = subprocess.Popen( From 4d5537deee678382d43c505d294cb8dc7985e762 Mon Sep 17 00:00:00 2001 From: Lars Holmberg Date: Sun, 4 Feb 2024 21:05:27 +0100 Subject: [PATCH 3/6] fix test stability on macos: Try setting a lower heartbeat interval --- locust/test/test_main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/locust/test/test_main.py b/locust/test/test_main.py index 8329a7d8e8..23973de897 100644 --- a/locust/test/test_main.py +++ b/locust/test/test_main.py @@ -2013,6 +2013,7 @@ def test_processes_workers_quit_unexpected(self): content = """ from locust import runners, events, User, task import sys +runners.HEARTBEAT_INTERVAL = 0.1 @events.test_start.add_listener def on_test_start(environment, **_kwargs): From 984ea84fc44520719903e4f28b41eb8473c572c0 Mon Sep 17 00:00:00 2001 From: Lars Holmberg Date: Sun, 4 Feb 2024 21:21:31 +0100 Subject: [PATCH 4/6] fix test stability on macos by setting a lower MASTER_HEARTBEAT_TIMEOUT --- locust/test/test_main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/locust/test/test_main.py b/locust/test/test_main.py index 23973de897..58004ad7c0 100644 --- a/locust/test/test_main.py +++ b/locust/test/test_main.py @@ -1932,7 +1932,7 @@ def test_processes_ctrl_c(self): def test_workers_shut_down_if_master_is_gone(self): content = """ from locust import HttpUser, task, constant, runners -runners.MASTER_HEARTBEAT_TIMEOUT = 3 +runners.MASTER_HEARTBEAT_TIMEOUT = 2 class AnyUser(HttpUser): host = "http://127.0.0.1:8089" From aa51e9ca72b330850f2a1774cf9598f074ede697 Mon Sep 17 00:00:00 2001 From: Lars Holmberg Date: Sun, 4 Feb 2024 21:30:04 +0100 Subject: [PATCH 5/6] Unit tests: when the worker doesnt stop on its own, kill it in a way that works properly for forked applications --- locust/test/test_main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/locust/test/test_main.py b/locust/test/test_main.py index 58004ad7c0..6939976419 100644 --- a/locust/test/test_main.py +++ b/locust/test/test_main.py @@ -1970,6 +1970,7 @@ def my_task(self): stdout=PIPE, stderr=PIPE, text=True, + start_new_session=True, ) gevent.sleep(1) master_proc.kill() @@ -1977,7 +1978,7 @@ def my_task(self): try: _, worker_stderr = worker_parent_proc.communicate(timeout=7) except Exception: - worker_parent_proc.kill() + os.killpg(worker_parent_proc.pid, signal.SIGTERM) _, worker_stderr = worker_parent_proc.communicate() assert False, f"worker never finished: {worker_stderr}" From 804edc0efb9a690eeb0b27c1f7098d71cacd3527 Mon Sep 17 00:00:00 2001 From: Lars Holmberg Date: Sun, 4 Feb 2024 21:43:06 +0100 Subject: [PATCH 6/6] Unit test: give potentially better error messages. fix typo --- locust/test/test_main.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/locust/test/test_main.py b/locust/test/test_main.py index 6939976419..1b07120f0b 100644 --- a/locust/test/test_main.py +++ b/locust/test/test_main.py @@ -756,7 +756,7 @@ def tick(self): self.assertIn('', response.text) self.assertTrue(success, "got timeout and had to kill the process") - def test_autostart_mutliple_locustfiles_with_shape(self): + def test_autostart_multiple_locustfiles_with_shape(self): port = get_free_tcp_port() content = textwrap.dedent( """ @@ -806,9 +806,12 @@ def my_task(self): text=True, ) gevent.sleep(1.9) - response = requests.get(f"http://localhost:{port}/") + success = True + try: + response = requests.get(f"http://localhost:{port}/") + except ConnectionError: + succcess = False try: - success = True _, stderr = proc.communicate(timeout=5) except subprocess.TimeoutExpired: success = False