From 4b8e10c8d49e9acdca67f27cb3e36b0c027f3385 Mon Sep 17 00:00:00 2001 From: Tim Burke Date: Fri, 13 Sep 2024 22:09:42 +0000 Subject: [PATCH] Add a multi-threaded test This passes currently, but only because of the GIL. Testing on py313t with PYTHON_GIL=0 and liberasurecode 1.6.2, it segfaults. Related-Change: https://review.opendev.org/c/openstack/liberasurecode/+/929325 Change-Id: I46ec7d3ee28700c5ebb7b563dafc6a0fb3c9a10f --- test/test_pyeclib_api.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/test_pyeclib_api.py b/test/test_pyeclib_api.py index a2e3ab5..f16d669 100644 --- a/test/test_pyeclib_api.py +++ b/test/test_pyeclib_api.py @@ -22,11 +22,16 @@ # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import os +try: + import queue +except ImportError: # py2 + import Queue as queue import random import resource import string import sys import tempfile +import threading import unittest from itertools import combinations @@ -177,6 +182,26 @@ class TestPyECLibDriver(unittest.TestCase): pass self.assertEqual(available_ec_types, VALID_EC_TYPES) + def test_create_in_threads(self): + def create_backend(kwargs, q): + q.put(ECDriver(**kwargs)) + + for backend in VALID_EC_TYPES: + q = queue.Queue() + threads = [ + threading.Thread( + target=create_backend, + args=({'k': 10, 'm': 5, 'ec_type': backend}, q)) + for _ in range(5)] + for t in threads: + t.start() + for t in threads: + t.join() + results = [] + while not q.empty(): + results.append(q.get()) + self.assertEqual(len(results), 5) + def test_valid_algo(self): print("") for _type in ALL_EC_TYPES: