mirror of
https://github.com/Dispatcharr/Dispatcharr.git
synced 2026-07-17 16:50:53 +00:00
- Added a new function `_is_uwsgi_worker` to accurately identify when the application is running within a uWSGI worker. - Updated `get_process_role` to label processes as "uwsgi" based on the new function or command-line arguments, improving process role accuracy. - Expanded unit tests to cover various scenarios for uWSGI role detection, ensuring robust validation of the new logic.
29 lines
1.2 KiB
Python
29 lines
1.2 KiB
Python
from unittest.mock import patch
|
|
|
|
from django.test import SimpleTestCase
|
|
|
|
from dispatcharr.db.process_label import get_process_role
|
|
|
|
|
|
class ProcessLabelTests(SimpleTestCase):
|
|
def test_celery_worker_not_labeled_as_uwsgi(self):
|
|
role = get_process_role(
|
|
["/dispatcharrpy/bin/celery", "-A", "dispatcharr", "worker"]
|
|
)
|
|
self.assertEqual(role, "celery-worker")
|
|
|
|
def test_uwsgi_labeled_from_argv(self):
|
|
role = get_process_role(["/dispatcharrpy/bin/uwsgi", "--ini", "/app/docker/uwsgi.ini"])
|
|
self.assertEqual(role, "uwsgi")
|
|
|
|
def test_uwsgi_labeled_when_worker_module_present(self):
|
|
fake_uwsgi = type("uwsgi", (), {"worker_id": lambda: 2})()
|
|
with patch.dict("sys.modules", {"uwsgi": fake_uwsgi}):
|
|
role = get_process_role(["/dispatcharrpy/bin/python", "-c", "pass"])
|
|
self.assertEqual(role, "uwsgi")
|
|
|
|
def test_uwsgi_master_not_labeled_as_uwsgi(self):
|
|
fake_uwsgi = type("uwsgi", (), {"worker_id": lambda: 0})()
|
|
with patch.dict("sys.modules", {"uwsgi": fake_uwsgi}):
|
|
role = get_process_role(["/dispatcharrpy/bin/python", "-c", "pass"])
|
|
self.assertEqual(role, "django")
|