From a98a6bd1128663fbe58c0c73d468710245a57ad6 Mon Sep 17 00:00:00 2001 From: Duprat Date: Sat, 1 Mar 2025 21:28:14 +0100 Subject: gh-129401: Test repr rlock failing randomly (#129959) Fix and simplify a test of `test_repr_rlock` about multiprocessing.RLock primitive. --- Lib/test/_test_multiprocessing.py | 20 +++++++------------- .../2025-02-10-14-34-29.gh-issue-129401.Cq6Ruy.rst | 1 + 2 files changed, 8 insertions(+), 13 deletions(-) create mode 100644 Misc/NEWS.d/next/Tests/2025-02-10-14-34-29.gh-issue-129401.Cq6Ruy.rst diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py index 5dd89bd..cafbc75 100644 --- a/Lib/test/_test_multiprocessing.py +++ b/Lib/test/_test_multiprocessing.py @@ -1521,14 +1521,11 @@ class _TestLock(BaseTestCase): for i in range(n): self.assertIn(f'', l) - - t = threading.Thread(target=self._acquire_release, - args=(lock, 0.2), - name=f'T1') + rlock = self.RLock() + t = threading.Thread(target=rlock.acquire) t.start() - time.sleep(0.1) - self.assertEqual('', repr(lock)) - time.sleep(0.2) + t.join() + self.assertEqual('', repr(rlock)) pname = 'P1' l = multiprocessing.Manager().list() @@ -1539,14 +1536,11 @@ class _TestLock(BaseTestCase): p.join() self.assertEqual(f'', l[0]) - event = self.Event() - lock = self.RLock() - p = self.Process(target=self._acquire_event, - args=(lock, event)) + rlock = self.RLock() + p = self.Process(target=self._acquire, args=(rlock,)) p.start() - event.wait() - self.assertEqual('', repr(lock)) p.join() + self.assertEqual('', repr(rlock)) def test_rlock(self): lock = self.RLock() diff --git a/Misc/NEWS.d/next/Tests/2025-02-10-14-34-29.gh-issue-129401.Cq6Ruy.rst b/Misc/NEWS.d/next/Tests/2025-02-10-14-34-29.gh-issue-129401.Cq6Ruy.rst new file mode 100644 index 0000000..7b87d54 --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2025-02-10-14-34-29.gh-issue-129401.Cq6Ruy.rst @@ -0,0 +1 @@ +Fix a flaky test in ``test_repr_rlock`` that checks the representation of :class:`multiprocessing.RLock`. -- cgit v0.12