From 7e268fa795f263de2c7755ebd3a30567ae33f56e Mon Sep 17 00:00:00 2001 From: Alan Rominger Date: Sat, 8 Feb 2025 21:07:56 -0500 Subject: [PATCH] Make awx/main/tests/live dramatically faster (#15780) * Make awx/main/tests/live dramatically faster * Add new setting to exclude list --- awx/main/dispatch/publish.py | 4 ++-- awx/main/tests/settings_for_test.py | 3 +++ awx/main/tests/unit/test_settings.py | 1 + awx/settings/defaults.py | 5 +++++ 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/awx/main/dispatch/publish.py b/awx/main/dispatch/publish.py index 8ff158eafae6..df39e06de3c1 100644 --- a/awx/main/dispatch/publish.py +++ b/awx/main/dispatch/publish.py @@ -5,9 +5,9 @@ from uuid import uuid4 from django_guid import get_guid +from django.conf import settings from . import pg_bus_conn -from awx.main.utils import is_testing logger = logging.getLogger('awx.main.dispatch') @@ -101,7 +101,7 @@ def apply_async(cls, args=None, kwargs=None, queue=None, uuid=None, **kw): obj = cls.get_async_body(args=args, kwargs=kwargs, uuid=uuid, **kw) if callable(queue): queue = queue() - if not is_testing(): + if not settings.DISPATCHER_MOCK_PUBLISH: with pg_bus_conn() as conn: conn.notify(queue, json.dumps(obj)) return (obj, queue) diff --git a/awx/main/tests/settings_for_test.py b/awx/main/tests/settings_for_test.py index 5634494c3373..b7d5cdf0235f 100644 --- a/awx/main/tests/settings_for_test.py +++ b/awx/main/tests/settings_for_test.py @@ -7,6 +7,9 @@ # Some things make decisions based on settings.SETTINGS_MODULE, so this is done for that SETTINGS_MODULE = 'awx.settings.development' +# Turn off task submission, because sqlite3 does not have pg_notify +DISPATCHER_MOCK_PUBLISH = True + # Use SQLite for unit tests instead of PostgreSQL. If the lines below are # commented out, Django will create the test_awx-dev database in PostgreSQL to # run unit tests. diff --git a/awx/main/tests/unit/test_settings.py b/awx/main/tests/unit/test_settings.py index dae59296551b..7ff2e3f4abf6 100644 --- a/awx/main/tests/unit/test_settings.py +++ b/awx/main/tests/unit/test_settings.py @@ -11,6 +11,7 @@ 'CACHES', 'DEBUG', 'NAMED_URL_GRAPH', + 'DISPATCHER_MOCK_PUBLISH', ) diff --git a/awx/settings/defaults.py b/awx/settings/defaults.py index 7f542a916f2e..98ecd29497ed 100644 --- a/awx/settings/defaults.py +++ b/awx/settings/defaults.py @@ -423,6 +423,11 @@ # Amount of time dispatcher will try to reconnect to database for jobs and consuming new work DISPATCHER_DB_DOWNTIME_TOLERANCE = 40 +# If you set this, nothing will ever be sent to pg_notify +# this is not practical to use, although periodic schedules may still run slugish but functional tasks +# sqlite3 based tests will use this +DISPATCHER_MOCK_PUBLISH = False + BROKER_URL = 'unix:///var/run/redis/redis.sock' CELERYBEAT_SCHEDULE = { 'tower_scheduler': {'task': 'awx.main.tasks.system.awx_periodic_scheduler', 'schedule': timedelta(seconds=30), 'options': {'expires': 20}},