]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-129401: Test repr rlock failing randomly (#129959)
authorDuprat <yduprat@gmail.com>
Sat, 1 Mar 2025 20:28:14 +0000 (21:28 +0100)
committerGitHub <noreply@github.com>
Sat, 1 Mar 2025 20:28:14 +0000 (15:28 -0500)
Fix and simplify a test of `test_repr_rlock` about multiprocessing.RLock primitive.

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 5dd89bd5af7daa0a68f3466ffc1a26ca06d05c80..cafbc757904f641947cac371871ac13250abc3ef 100644 (file)
@@ -1521,14 +1521,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()
@@ -1539,14 +1536,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`.