mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
Issue #21755: Skip {Frozen,Source}_DeadlockAvoidanceTests tests when
Python is built without threads.
This commit is contained in:
parent
748ff8bfd1
commit
f7eaa0c63c
1 changed files with 72 additions and 60 deletions
|
@ -52,8 +52,8 @@ else:
|
|||
pass
|
||||
|
||||
|
||||
@unittest.skipUnless(threading, "threads needed for this test")
|
||||
class DeadlockAvoidanceTests:
|
||||
if threading is not None:
|
||||
class DeadlockAvoidanceTests:
|
||||
|
||||
def setUp(self):
|
||||
try:
|
||||
|
@ -76,14 +76,17 @@ class DeadlockAvoidanceTests:
|
|||
NTHREADS = NLOCKS - 1
|
||||
barrier = threading.Barrier(NTHREADS)
|
||||
results = []
|
||||
|
||||
def _acquire(lock):
|
||||
"""Try to acquire the lock. Return True on success, False on deadlock."""
|
||||
"""Try to acquire the lock. Return True on success,
|
||||
False on deadlock."""
|
||||
try:
|
||||
lock.acquire()
|
||||
except self.DeadlockError:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
def f():
|
||||
a, b = pairs.pop()
|
||||
ra = _acquire(a)
|
||||
|
@ -113,13 +116,22 @@ class DeadlockAvoidanceTests:
|
|||
self.assertEqual(results.count((True, True)), len(results))
|
||||
|
||||
|
||||
DEADLOCK_ERRORS = {kind: splitinit._bootstrap._DeadlockError
|
||||
DEADLOCK_ERRORS = {kind: splitinit._bootstrap._DeadlockError
|
||||
for kind, splitinit in init.items()}
|
||||
|
||||
(Frozen_DeadlockAvoidanceTests,
|
||||
(Frozen_DeadlockAvoidanceTests,
|
||||
Source_DeadlockAvoidanceTests
|
||||
) = test_util.test_both(DeadlockAvoidanceTests,
|
||||
LockType=LOCK_TYPES, DeadlockError=DEADLOCK_ERRORS)
|
||||
LockType=LOCK_TYPES,
|
||||
DeadlockError=DEADLOCK_ERRORS)
|
||||
else:
|
||||
DEADLOCK_ERRORS = {}
|
||||
|
||||
class Frozen_DeadlockAvoidanceTests(unittest.TestCase):
|
||||
pass
|
||||
|
||||
class Source_DeadlockAvoidanceTests(unittest.TestCase):
|
||||
pass
|
||||
|
||||
|
||||
class LifetimeTests:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue