mirror of
https://github.com/python/cpython.git
synced 2026-04-01 17:41:27 +00:00
svn+ssh://pythondev@svn.python.org/python/trunk ........ r63208 | georg.brandl | 2008-05-13 15:04:54 -0400 (Tue, 13 May 2008) | 2 lines #2831: add start argument to enumerate(). Patch by Scott Dial and me. ........ r63209 | marc-andre.lemburg | 2008-05-13 15:10:45 -0400 (Tue, 13 May 2008) | 3 lines Remove leftovers from reverted setuptools checkin (they were added in r45525). ........ r63211 | georg.brandl | 2008-05-13 17:32:03 -0400 (Tue, 13 May 2008) | 2 lines Fix a refleak in the _warnings module. ........ r63212 | andrew.kuchling | 2008-05-13 20:46:41 -0400 (Tue, 13 May 2008) | 1 line List all the removes and renamed modules ........ r63214 | brett.cannon | 2008-05-13 21:09:40 -0400 (Tue, 13 May 2008) | 2 lines Rewrap some lines in test_py3kwarn. ........ r63219 | georg.brandl | 2008-05-14 02:34:15 -0400 (Wed, 14 May 2008) | 2 lines Add NEWS entry for #2831. ........ r63220 | neal.norwitz | 2008-05-14 02:47:56 -0400 (Wed, 14 May 2008) | 3 lines Fix "refleak" by restoring the tearDown method removed by accident (AFAICT) in r62788. ........ r63221 | georg.brandl | 2008-05-14 03:18:22 -0400 (Wed, 14 May 2008) | 2 lines Fix another "refleak" by clearing the filters after test. ........ r63222 | neal.norwitz | 2008-05-14 03:21:42 -0400 (Wed, 14 May 2008) | 5 lines Install the json package and tests as well as the lib2to3 tests so the tests work when run from an install directory. They are currently skipped on the daily runs (not from the buildbots) for checking refleaks, etc. ........ r63256 | andrew.kuchling | 2008-05-14 21:10:24 -0400 (Wed, 14 May 2008) | 1 line Note some removals and a rename ........ r63311 | brett.cannon | 2008-05-15 00:36:53 -0400 (Thu, 15 May 2008) | 2 lines Add a snippet for the deprecation directive for docs. ........ r63313 | gregory.p.smith | 2008-05-15 00:56:18 -0400 (Thu, 15 May 2008) | 5 lines disable the crashing test. I will also file a bug. This crash does not appear to be a new bug, its just that the test coverage went up recently exposing it. (I verified that by testing this test code on an older Modules/_bsddb.c) ........ r63320 | georg.brandl | 2008-05-15 11:08:32 -0400 (Thu, 15 May 2008) | 2 lines #2863: add gen.__name__ and add this name to generator repr(). ........ r63324 | andrew.kuchling | 2008-05-15 16:07:39 -0400 (Thu, 15 May 2008) | 1 line Import class from distutils.cmd, not .core, to avoid circular import ........ r63327 | alexandre.vassalotti | 2008-05-15 16:31:42 -0400 (Thu, 15 May 2008) | 2 lines Fixed typo in a doctest of test_genexps. ........ r63332 | benjamin.peterson | 2008-05-15 18:34:33 -0400 (Thu, 15 May 2008) | 2 lines add Mac modules to the list of deprecated ones ........ r63333 | benjamin.peterson | 2008-05-15 18:41:16 -0400 (Thu, 15 May 2008) | 2 lines fix typos in whatsnew ........ r63348 | benjamin.peterson | 2008-05-15 22:24:49 -0400 (Thu, 15 May 2008) | 2 lines make test_platform a bit more assertive (We'll see what the buildbots say.) ........
183 lines
5.7 KiB
Python
183 lines
5.7 KiB
Python
"""
|
|
TestCases for testing the locking sub-system.
|
|
"""
|
|
|
|
import sys
|
|
import tempfile
|
|
import time
|
|
|
|
try:
|
|
from threading import Thread, currentThread
|
|
have_threads = 1
|
|
except ImportError:
|
|
have_threads = 0
|
|
|
|
|
|
import unittest
|
|
from bsddb.test.test_all import verbose
|
|
|
|
try:
|
|
# For Pythons w/distutils pybsddb
|
|
from bsddb3 import db
|
|
except ImportError:
|
|
# For Python 2.3
|
|
from bsddb import db
|
|
|
|
try:
|
|
from bsddb3 import test_support
|
|
except ImportError:
|
|
from test import test_support
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
class LockingTestCase(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
self.homeDir = tempfile.mkdtemp('.test_lock')
|
|
self.env = db.DBEnv()
|
|
self.env.open(self.homeDir, db.DB_THREAD | db.DB_INIT_MPOOL |
|
|
db.DB_INIT_LOCK | db.DB_CREATE)
|
|
|
|
|
|
def tearDown(self):
|
|
self.env.close()
|
|
test_support.rmtree(self.homeDir)
|
|
|
|
|
|
def test01_simple(self):
|
|
if verbose:
|
|
print('\n', '-=' * 30)
|
|
print("Running %s.test01_simple..." % self.__class__.__name__)
|
|
|
|
anID = self.env.lock_id()
|
|
if verbose:
|
|
print("locker ID: %s" % anID)
|
|
lock = self.env.lock_get(anID, b"some locked thing", db.DB_LOCK_WRITE)
|
|
if verbose:
|
|
print("Aquired lock: %s" % lock)
|
|
time.sleep(1)
|
|
self.env.lock_put(lock)
|
|
if verbose:
|
|
print("Released lock: %s" % lock)
|
|
if db.version() >= (4,0):
|
|
self.env.lock_id_free(anID)
|
|
|
|
|
|
def test02_threaded(self):
|
|
if verbose:
|
|
print('\n', '-=' * 30)
|
|
print("Running %s.test02_threaded..." % self.__class__.__name__)
|
|
|
|
threads = []
|
|
threads.append(Thread(target = self.theThread,
|
|
args=(5, db.DB_LOCK_WRITE)))
|
|
threads.append(Thread(target = self.theThread,
|
|
args=(1, db.DB_LOCK_READ)))
|
|
threads.append(Thread(target = self.theThread,
|
|
args=(1, db.DB_LOCK_READ)))
|
|
threads.append(Thread(target = self.theThread,
|
|
args=(1, db.DB_LOCK_WRITE)))
|
|
threads.append(Thread(target = self.theThread,
|
|
args=(1, db.DB_LOCK_READ)))
|
|
threads.append(Thread(target = self.theThread,
|
|
args=(1, db.DB_LOCK_READ)))
|
|
threads.append(Thread(target = self.theThread,
|
|
args=(1, db.DB_LOCK_WRITE)))
|
|
threads.append(Thread(target = self.theThread,
|
|
args=(1, db.DB_LOCK_WRITE)))
|
|
threads.append(Thread(target = self.theThread,
|
|
args=(1, db.DB_LOCK_WRITE)))
|
|
|
|
for t in threads:
|
|
t.start()
|
|
for t in threads:
|
|
t.join()
|
|
|
|
def _DISABLED_test03_lock_timeout(self):
|
|
# Disabled as this test crashes the python interpreter built in
|
|
# debug mode with:
|
|
# Fatal Python error: UNREF invalid object
|
|
# the error occurs as marked below.
|
|
self.env.set_timeout(0, db.DB_SET_LOCK_TIMEOUT)
|
|
self.env.set_timeout(0, db.DB_SET_TXN_TIMEOUT)
|
|
self.env.set_timeout(123456, db.DB_SET_LOCK_TIMEOUT)
|
|
self.env.set_timeout(7890123, db.DB_SET_TXN_TIMEOUT)
|
|
|
|
def deadlock_detection() :
|
|
while not deadlock_detection.end :
|
|
deadlock_detection.count = \
|
|
self.env.lock_detect(db.DB_LOCK_EXPIRE)
|
|
if deadlock_detection.count :
|
|
while not deadlock_detection.end :
|
|
pass
|
|
break
|
|
time.sleep(0.01)
|
|
|
|
deadlock_detection.end=False
|
|
deadlock_detection.count=0
|
|
t=Thread(target=deadlock_detection)
|
|
t.setDaemon(True)
|
|
t.start()
|
|
self.env.set_timeout(100000, db.DB_SET_LOCK_TIMEOUT)
|
|
anID = self.env.lock_id()
|
|
anID2 = self.env.lock_id()
|
|
self.assertNotEqual(anID, anID2)
|
|
lock = self.env.lock_get(anID, "shared lock", db.DB_LOCK_WRITE)
|
|
start_time=time.time()
|
|
# FIXME: I see the UNREF crash as the interpreter trys to exit
|
|
# from this call to lock_get.
|
|
self.assertRaises(db.DBLockNotGrantedError,
|
|
self.env.lock_get,anID2, "shared lock", db.DB_LOCK_READ)
|
|
end_time=time.time()
|
|
deadlock_detection.end=True
|
|
self.assertTrue((end_time-start_time) >= 0.1)
|
|
self.env.lock_put(lock)
|
|
t.join()
|
|
|
|
if db.version() >= (4,0):
|
|
self.env.lock_id_free(anID)
|
|
self.env.lock_id_free(anID2)
|
|
|
|
if db.version() >= (4,6):
|
|
self.assertTrue(deadlock_detection.count>0)
|
|
|
|
def theThread(self, lockType):
|
|
name = currentThread().getName()
|
|
if lockType == db.DB_LOCK_WRITE:
|
|
lt = "write"
|
|
else:
|
|
lt = "read"
|
|
|
|
anID = self.env.lock_id()
|
|
if verbose:
|
|
print("%s: locker ID: %s" % (name, anID))
|
|
|
|
lock = self.env.lock_get(anID, b"some locked thing", lockType)
|
|
if verbose:
|
|
print("%s: Aquired %s lock: %s" % (name, lt, lock))
|
|
|
|
time.sleep(sleepTime)
|
|
|
|
self.env.lock_put(lock)
|
|
if verbose:
|
|
print("%s: Released %s lock: %s" % (name, lt, lock))
|
|
if db.version() >= (4,0):
|
|
self.env.lock_id_free(anID)
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
def test_suite():
|
|
suite = unittest.TestSuite()
|
|
|
|
if have_threads:
|
|
suite.addTest(unittest.makeSuite(LockingTestCase))
|
|
else:
|
|
suite.addTest(unittest.makeSuite(LockingTestCase, 'test01'))
|
|
|
|
return suite
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main(defaultTest='test_suite')
|