From 01fae57de2e1d7226ef1aa3c73955a5da0e7c4e7 Mon Sep 17 00:00:00 2001 From: Alan Rominger Date: Tue, 11 Mar 2025 14:46:39 -0400 Subject: [PATCH] Fix indirect host counting task test race condition (#15871) --- .../live/tests/test_indirect_host_counting.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/awx/main/tests/live/tests/test_indirect_host_counting.py b/awx/main/tests/live/tests/test_indirect_host_counting.py index ce202f02ae..2843eaeba5 100644 --- a/awx/main/tests/live/tests/test_indirect_host_counting.py +++ b/awx/main/tests/live/tests/test_indirect_host_counting.py @@ -50,13 +50,14 @@ def test_indirect_host_counting(live_tmp_folder, run_job_from_playbook): job.refresh_from_db() if job.event_queries_processed is False: save_indirect_host_entries.delay(job.id, wait_for_events=False) - # This will poll for the background task to finish - for _ in range(10): - if IndirectManagedNodeAudit.objects.filter(job=job).exists(): - break - time.sleep(0.2) - else: - raise RuntimeError(f'No IndirectManagedNodeAudit records ever populated for job_id={job.id}') + + # event_queries_processed only assures the task has started, it might take a minor amount of time to finish + for _ in range(10): + if IndirectManagedNodeAudit.objects.filter(job=job).exists(): + break + time.sleep(0.2) + else: + raise RuntimeError(f'No IndirectManagedNodeAudit records ever populated for job_id={job.id}') assert IndirectManagedNodeAudit.objects.filter(job=job).count() == 1 host_audit = IndirectManagedNodeAudit.objects.filter(job=job).first()