From 66a512c96c15d94f8ec17918bc3c2b94df31e786 Mon Sep 17 00:00:00 2001 From: Trenton H <797416+stumpylog@users.noreply.github.com> Date: Sun, 11 Jan 2026 12:45:06 -0800 Subject: [PATCH] Ensures tags created in the thread are cleaned up --- .../tests/test_management_consumer.py | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/documents/tests/test_management_consumer.py b/src/documents/tests/test_management_consumer.py index 13ba4635e..8a6b8d390 100644 --- a/src/documents/tests/test_management_consumer.py +++ b/src/documents/tests/test_management_consumer.py @@ -703,16 +703,26 @@ def start_consumer( sleep(0.5) # Give thread time to start return thread - yield _start + try: + yield _start + finally: + # Cleanup all threads that were started + for thread in threads: + thread.stop() - # Cleanup all threads that were started - for thread in threads: - thread.stop() + failed_threads = [] + for thread in threads: + thread.join(timeout=5.0) + if thread.is_alive(): + failed_threads.append(thread) - for thread in threads: - thread.join(timeout=5.0) - if thread.is_alive(): - pytest.fail("Consumer thread did not stop within timeout") + # Clean up any Tags created by threads (they bypass test transaction isolation) + Tag.objects.all().delete() + + if failed_threads: + pytest.fail( + f"{len(failed_threads)} consumer thread(s) did not stop within timeout", + ) @pytest.mark.django_db