mirror of
https://github.com/ansible/awx.git
synced 2026-10-29 22:03:20 -02:30
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.
This commit is contained in:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user