cpython/Lib/test/test_free_threading/test_grp.py
Miss Islington (bot) 55eaaab8a4
[3.14] gh-116738: Make grp module thread-safe (GH-135434) (#136658)
gh-116738: Make grp module thread-safe (GH-135434)

Make grp module methods getgrgid() and getgrnam() thread-safe when the GIL is disabled and getgrgid_r()/getgrnam_r() C APIs are not available.
---------
(cherry picked from commit 9363703bd3)

Co-authored-by: Alper <alperyoney@fb.com>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2025-07-15 11:03:33 +05:30

35 lines
954 B
Python

import unittest
from test.support import import_helper, threading_helper
from test.support.threading_helper import run_concurrently
grp = import_helper.import_module("grp")
from test import test_grp
NTHREADS = 10
@threading_helper.requires_working_threading()
class TestGrp(unittest.TestCase):
def setUp(self):
self.test_grp = test_grp.GroupDatabaseTestCase()
def test_racing_test_values(self):
# test_grp.test_values() calls grp.getgrall() and checks the entries
run_concurrently(
worker_func=self.test_grp.test_values, nthreads=NTHREADS
)
def test_racing_test_values_extended(self):
# test_grp.test_values_extended() calls grp.getgrall(), grp.getgrgid(),
# grp.getgrnam() and checks the entries
run_concurrently(
worker_func=self.test_grp.test_values_extended,
nthreads=NTHREADS,
)
if __name__ == "__main__":
unittest.main()