summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_importlib/test_locks.py
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2023-10-04 11:26:45 (GMT)
committerGitHub <noreply@github.com>2023-10-04 11:26:45 (GMT)
commit1d032ea3d67e9725b63322f896d9aa727fd75521 (patch)
treebd4f3f8b7b43d337a60d14a79d5464f7aa1ad1d1 /Lib/test/test_importlib/test_locks.py
parentf53871e1e8bad0d7a8e58dd2cd4588331480d881 (diff)
downloadcpython-1d032ea3d67e9725b63322f896d9aa727fd75521.zip
cpython-1d032ea3d67e9725b63322f896d9aa727fd75521.tar.gz
cpython-1d032ea3d67e9725b63322f896d9aa727fd75521.tar.bz2
[3.12] gh-109974: Fix threading lock_tests race conditions (#110057) (#110346)
* gh-109974: Fix threading lock_tests race conditions (#110057) Fix race conditions in test_threading lock tests. Wait until a condition is met rather than using time.sleep() with a hardcoded number of seconds. * Replace sleeping loops with support.sleeping_retry() which raises an exception on timeout. * Add wait_threads_blocked(nthread) which computes a sleep depending on the number of threads. Remove _wait() function. * test_set_and_clear(): use a way longer Event.wait() timeout. * BarrierTests.test_repr(): wait until the 2 threads are waiting for the barrier. Use a way longer timeout for Barrier.wait() timeout. * test_thread_leak() no longer needs to count len(threading.enumerate()): Bunch uses threading_helper.wait_threads_exit() internally which does it in wait_for_finished(). * Add BaseLockTests.wait_phase() which implements a timeout. test_reacquire() and test_recursion_count() use wait_phase(). (cherry picked from commit 4e356ad183eeb567783f4a87fd092573da1e9252) * gh-109974: Fix more threading lock_tests race conditions (#110089) * Add context manager on Bunch class. * Bunch now catchs exceptions on executed functions and re-raise them at __exit__() as an ExceptionGroup. * Rewrite BarrierProxy.test_default_timeout(). Use a single thread. Only check that barrier.wait() blocks for at least default timeout seconds. * test_with(): inline _with() function. (cherry picked from commit 743e3572ee940a6cf88fd518e5f4a447905ba5eb)
Diffstat (limited to 'Lib/test/test_importlib/test_locks.py')
-rw-r--r--Lib/test/test_importlib/test_locks.py3
1 files changed, 2 insertions, 1 deletions
diff --git a/Lib/test/test_importlib/test_locks.py b/Lib/test/test_importlib/test_locks.py
index 7091c36..befac5d 100644
--- a/Lib/test/test_importlib/test_locks.py
+++ b/Lib/test/test_importlib/test_locks.py
@@ -93,7 +93,8 @@ class DeadlockAvoidanceTests:
b.release()
if ra:
a.release()
- lock_tests.Bunch(f, NTHREADS).wait_for_finished()
+ with lock_tests.Bunch(f, NTHREADS):
+ pass
self.assertEqual(len(results), NTHREADS)
return results