Commit f7eaa0c6 authored by Berker Peksag's avatar Berker Peksag

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

Python is built without threads.
parent 748ff8bf
......@@ -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:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment