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
|
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:
|
||||||
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:
|
||||||
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:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue