]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-129401: Test repr rlock failing randomly (GH-129959) (#144405)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 2 Feb 2026 19:11:03 +0000 (20:11 +0100)
committerGitHub <noreply@github.com>
Mon, 2 Feb 2026 19:11:03 +0000 (14:11 -0500)
Fix and simplify a test of `test_repr_rlock` about multiprocessing.RLock primitive.
(cherry picked from commit a98a6bd1128663fbe58c0c73d468710245a57ad6)

Co-authored-by: Duprat <yduprat@gmail.com>
Lib/test/_test_multiprocessing.py
Misc/NEWS.d/next/Tests/2025-02-10-14-34-29.gh-issue-129401.Cq6Ruy.rst [new file with mode: 0644]

index 35a6f0830d472fd6e76d7be5142d9f3eeb8d53ba..ded7c5249e155c3d8863a2f7f659261e5604bdfe 100644 (file)
@@ -1484,14 +1484,11 @@ class _TestLock(BaseTestCase):
         for i in range(n):
             self.assertIn(f'<RLock(MainProcess|T{i+1}, {i+1})>', 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('<RLock(SomeOtherThread, nonzero)>', repr(lock))
-        time.sleep(0.2)
+        t.join()
+        self.assertEqual('<RLock(SomeOtherThread, nonzero)>', repr(rlock))
 
         pname = 'P1'
         l = multiprocessing.Manager().list()
@@ -1502,14 +1499,11 @@ class _TestLock(BaseTestCase):
         p.join()
         self.assertEqual(f'<RLock({pname}, 1)>', 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('<RLock(SomeOtherProcess, nonzero)>', repr(lock))
         p.join()
+        self.assertEqual('<RLock(SomeOtherProcess, nonzero)>', 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 (file)
index 0000000..7b87d54
--- /dev/null
@@ -0,0 +1 @@
+Fix a flaky test in ``test_repr_rlock`` that checks the representation of :class:`multiprocessing.RLock`.