cpython: 454dceb5fd56 (original) (raw)
Mercurial > cpython
changeset 78790:454dceb5fd56
Issue #15794: Relax a test case due to the deadlock detection's conservativeness. [#15794]
Antoine Pitrou solipsis@pitrou.net | |
---|---|
date | Tue, 28 Aug 2012 20:10:18 +0200 |
parents | 06497bbdf4fe |
children | 2e587b9bae35 263d09ce3e9e |
files | Lib/test/test_importlib/test_locks.py |
diffstat | 1 files changed, 18 insertions(+), 4 deletions(-)[+] [-] Lib/test/test_importlib/test_locks.py 22 |
line wrap: on
line diff
--- a/Lib/test/test_importlib/test_locks.py +++ b/Lib/test/test_importlib/test_locks.py @@ -1,4 +1,5 @@ from importlib import _bootstrap +import sys import time import unittest import weakref @@ -41,6 +42,17 @@ else: @unittest.skipUnless(threading, "threads needed for this test") class DeadlockAvoidanceTests(unittest.TestCase):
- def setUp(self):
try:[](#l1.14)
self.old_switchinterval = sys.getswitchinterval()[](#l1.15)
sys.setswitchinterval(0.000001)[](#l1.16)
except AttributeError:[](#l1.17)
self.old_switchinterval = None[](#l1.18)
- def tearDown(self):
if self.old_switchinterval is not None:[](#l1.21)
sys.setswitchinterval(self.old_switchinterval)[](#l1.22)
+ def run_deadlock_avoidance_test(self, create_deadlock): NLOCKS = 10 locks = [LockType(str(i)) for i in range(NLOCKS)] @@ -75,10 +87,12 @@ class DeadlockAvoidanceTests(unittest.Te def test_deadlock(self): results = self.run_deadlock_avoidance_test(True)
# One of the threads detected a potential deadlock on its second[](#l1.31)
# acquire() call.[](#l1.32)
self.assertEqual(results.count((True, False)), 1)[](#l1.33)
self.assertEqual(results.count((True, True)), len(results) - 1)[](#l1.34)
# At least one of the threads detected a potential deadlock on its[](#l1.35)
# second acquire() call. It may be several of them, because the[](#l1.36)
# deadlock avoidance mechanism is conservative.[](#l1.37)
nb_deadlocks = results.count((True, False))[](#l1.38)
self.assertGreaterEqual(nb_deadlocks, 1)[](#l1.39)
self.assertEqual(results.count((True, True)), len(results) - nb_deadlocks)[](#l1.40)
def test_no_deadlock(self): results = self.run_deadlock_avoidance_test(False)