From 6fc51b6d25b5bf3ad7efa66cc4e62bdb27177027 Mon Sep 17 00:00:00 2001 From: Hao Liu <44379968+TheRealHaoLiu@users.noreply.github.com> Date: Thu, 15 Oct 2026 11:24:47 -0400 Subject: [PATCH] Warm the settings cache before measuring bulk job launch queries (#16744) test_bulk_job_launch_queries asserts django_assert_max_num_queries(25), but the first request in a pytest process pays one extra query per database-backed setting it reads. The settings wrapper's in-process memoized TTL cache (awx/conf/settings.py, _awx_conf_memoizedcache) starts cold and survives the per-test cache.clear() in awx/main/tests/conftest.py, so cold = 26 queries and warm = 25. The budget only holds when an earlier test in the same xdist worker already warmed the cache, which is luck of the -n auto draw. Make one untimed launch of the same endpoint before the measured loop, so the assertion measures steady state regardless of which test ran first in the worker. The budget stays at 25. The warm-up job is a separate bulk job; the assertions after the task manager run still use the measured response's data and its own workflow_nodes list, so they are unaffected. This is the same fix already applied to the sibling test test_bulk_host_create_num_queries in #16741. --- awx/main/tests/functional/test_bulk.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/awx/main/tests/functional/test_bulk.py b/awx/main/tests/functional/test_bulk.py index fcf03df180..368ceea7df 100644 --- a/awx/main/tests/functional/test_bulk.py +++ b/awx/main/tests/functional/test_bulk.py @@ -107,6 +107,17 @@ def test_bulk_job_launch_queries(job_template, organization, inventory, project, inventory.save() jobs = [{'unified_job_template': jt.id, 'inventory': inventory.id} for _ in range(num_jobs)] + # The first request in a process pays one query per database-backed + # setting it reads; later ones hit the settings wrapper's in-memory + # cache. Warm it so the budget below measures steady state regardless + # of which test ran first in this xdist worker. + post( + reverse('api:bulk_job_launch'), + {'name': 'Bulk Job Launch Warmup', 'jobs': [{'unified_job_template': jt.id, 'inventory': inventory.id}]}, + normal_user, + expect=201, + ) + # This is not working, we need to figure that out if we want to include tests for more jobs # with mock.patch('awx.api.serializers.settings.BULK_JOB_MAX_LAUNCH', num_jobs + 1): with django_assert_max_num_queries(num_queries):