]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-109974: Fix threading lock_tests race conditions (#110057)
authorVictor Stinner <vstinner@python.org>
Fri, 29 Sep 2023 00:34:27 +0000 (02:34 +0200)
committerGitHub <noreply@github.com>
Fri, 29 Sep 2023 00:34:27 +0000 (02:34 +0200)
commit4e356ad183eeb567783f4a87fd092573da1e9252
treed2742d870883b6a46fa42125c03f1c7ba1e82870
parent5fdcea744024c8a19ddb57057bf5ec2889546c98
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().
Lib/test/lock_tests.py
Misc/NEWS.d/next/Tests/2023-09-29-00-19-21.gh-issue-109974.Sh_g-r.rst [new file with mode: 0644]