Skip to content

Commit f6602f4

Browse files
committed
Add a test for sharing a dictionary across threads
1 parent 1b68e1e commit f6602f4

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Lib/test/test_zstd.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2506,6 +2506,28 @@ def run_method(method, input_data, output_data):
25062506
self.assertEqual(expected, actual)
25072507

25082508

2509+
@threading_helper.reap_threads
2510+
@threading_helper.requires_working_threading()
2511+
def test_compress_shared_dict(self):
2512+
num_threads = 8
2513+
2514+
def run_method(b):
2515+
level = threading.get_ident() % 2
2516+
# sync threads to increase chance of contention on
2517+
# capsule storing dictionary levels
2518+
b.wait()
2519+
ZstdCompressor(level=level, zstd_dict=TRAINED_DICT.as_digested_dict)
2520+
threads = []
2521+
2522+
b = threading.Barrier(num_threads)
2523+
for i in range(num_threads):
2524+
thread = threading.Thread(target=run_method, args=(b,))
2525+
2526+
threads.append(thread)
2527+
2528+
with threading_helper.start_threads(threads):
2529+
pass
2530+
25092531

25102532
if __name__ == "__main__":
25112533
unittest.main()

0 commit comments

Comments
 (0)