From f3b243e14a5f8da352f490719ae2bdae6040e0aa Mon Sep 17 00:00:00 2001 From: ptweezy Date: Sat, 24 Oct 2026 12:32:27 -0400 Subject: [PATCH] Add a timeout to the barrier in test_isal_compress_decompress_threaded A failed job made fewer barrier waits than the other jobs, so when the jobs ran out, the other threads waited at the barrier forever and the test never finished. Create the barrier in the test function with a 10 s timeout, because a module-level barrier would stay broken and also fail the next parameter set. --- tests/test_freethreading.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/test_freethreading.py b/tests/test_freethreading.py index 75f113dc..4e3c155e 100644 --- a/tests/test_freethreading.py +++ b/tests/test_freethreading.py @@ -75,10 +75,9 @@ NUM_THREADS = 10 NUM_ITERATIONS = 20 NUM_JOBS = 50 # To simulate 50 jobs running in 10 threads -barrier = threading.Barrier(parties=NUM_THREADS) -def isal_compress_decompress(compress, decompress): +def isal_compress_decompress(compress, decompress, barrier): for _ in range(NUM_ITERATIONS): barrier.wait() x = compress(HAMLET_SCENE) @@ -101,9 +100,14 @@ def isal_compress_decompress(compress, decompress): ] ) def test_isal_compress_decompress_threaded(compress, decompress): + # A failed job makes fewer barrier waits than the others, so when the + # jobs run out, the other threads would wait at the barrier forever. + # The timeout makes them fail instead. + barrier = threading.Barrier(parties=NUM_THREADS, timeout=10) with concurrent.futures.ThreadPoolExecutor(NUM_THREADS) as executor: futures = [ - executor.submit(isal_compress_decompress, compress, decompress) + executor.submit(isal_compress_decompress, compress, decompress, + barrier) for _ in range(NUM_JOBS) ] for future in concurrent.futures.as_completed(futures):