Issue #21755: Skip {Frozen,Source}_DeadlockAvoidanceTests tests when

Python is built without threads.
This commit is contained in:
Berker Peksag 2014-07-03 06:25:10 +03:00
parent 748ff8bfd1
commit f7eaa0c63c

View file

@ -52,7 +52,7 @@ else:
pass pass
@unittest.skipUnless(threading, "threads needed for this test") if threading is not None:
class DeadlockAvoidanceTests: class DeadlockAvoidanceTests:
def setUp(self): def setUp(self):
@ -76,14 +76,17 @@ class DeadlockAvoidanceTests:
NTHREADS = NLOCKS - 1 NTHREADS = NLOCKS - 1
barrier = threading.Barrier(NTHREADS) barrier = threading.Barrier(NTHREADS)
results = [] results = []
def _acquire(lock): 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: try:
lock.acquire() lock.acquire()
except self.DeadlockError: except self.DeadlockError:
return False return False
else: else:
return True return True
def f(): def f():
a, b = pairs.pop() a, b = pairs.pop()
ra = _acquire(a) ra = _acquire(a)
@ -119,7 +122,16 @@ DEADLOCK_ERRORS = {kind: splitinit._bootstrap._DeadlockError
(Frozen_DeadlockAvoidanceTests, (Frozen_DeadlockAvoidanceTests,
Source_DeadlockAvoidanceTests Source_DeadlockAvoidanceTests
) = test_util.test_both(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: class LifetimeTests: