Skip to content

Commit

Permalink
pythongh-109974: Fix threading lock_tests race conditions (python#110057
Browse files Browse the repository at this point in the history
)

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().
  • Loading branch information
vstinner authored and Glyphack committed Jan 27, 2024
1 parent b873e22 commit 9768e65
Show file tree
Hide file tree
Showing 2 changed files with 226 additions and 124 deletions.
Loading

0 comments on commit 9768e65

Please sign in to comment.