From 81a1bd7e8b4192fd319ad10c9e8d02f16b4e80dc Mon Sep 17 00:00:00 2001 From: Rogdham Date: Tue, 8 Jul 2025 19:38:03 +0200 Subject: [PATCH 1/2] Fix race condition in test_zstd --- Lib/test/test_zstd.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_zstd.py b/Lib/test/test_zstd.py index 90b2adc9665480..413f4847a9d62e 100644 --- a/Lib/test/test_zstd.py +++ b/Lib/test/test_zstd.py @@ -2673,8 +2673,12 @@ def test_compress_locking(self): input = b'a'* (16*_1K) num_threads = 8 + # gh-136394: the first output of comp.compress includes the frame header + # so it is different than the others + # this is why it is added outside of the threading part + comp = ZstdCompressor() - parts = [] + parts = [comp.compress(input, ZstdCompressor.FLUSH_BLOCK)] for _ in range(num_threads): res = comp.compress(input, ZstdCompressor.FLUSH_BLOCK) if res: @@ -2683,7 +2687,7 @@ def test_compress_locking(self): expected = b''.join(parts) + rest1 comp = ZstdCompressor() - output = [] + output = [comp.compress(input, ZstdCompressor.FLUSH_BLOCK)] def run_method(method, input_data, output_data): res = method(input_data, ZstdCompressor.FLUSH_BLOCK) if res: From cc34f8ee57da859e0032d014b9ec437983cf0470 Mon Sep 17 00:00:00 2001 From: Rogdham Date: Wed, 9 Jul 2025 21:06:40 +0200 Subject: [PATCH 2/2] Reword comment based on Emma suggestion --- Lib/test/test_zstd.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_zstd.py b/Lib/test/test_zstd.py index 413f4847a9d62e..6358cc78739cd9 100644 --- a/Lib/test/test_zstd.py +++ b/Lib/test/test_zstd.py @@ -2673,9 +2673,9 @@ def test_compress_locking(self): input = b'a'* (16*_1K) num_threads = 8 - # gh-136394: the first output of comp.compress includes the frame header - # so it is different than the others - # this is why it is added outside of the threading part + # gh-136394: the first output of .compress() includes the frame header + # we run the first .compress() call outside of the threaded portion + # to make the test order-independent comp = ZstdCompressor() parts = [comp.compress(input, ZstdCompressor.FLUSH_BLOCK)]