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: ...@@ -52,8 +52,8 @@ 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):
try: try:
...@@ -76,14 +76,17 @@ class DeadlockAvoidanceTests: ...@@ -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)
...@@ -113,13 +116,22 @@ class DeadlockAvoidanceTests: ...@@ -113,13 +116,22 @@ class DeadlockAvoidanceTests:
self.assertEqual(results.count((True, True)), len(results)) 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()} for kind, splitinit in init.items()}
(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:
......
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