Rev 4532: Change the flags around a bit. in lp:///~jameinel/bzr/1.18-lock-warnings
John Arbash Meinel
john at arbash-meinel.com
Fri Jul 31 16:51:31 BST 2009
At lp:///~jameinel/bzr/1.18-lock-warnings
------------------------------------------------------------
revno: 4532
revision-id: john at arbash-meinel.com-20090731154925-fquqoz209bh9aabr
parent: john at arbash-meinel.com-20090730220309-d64thqta9cln1i3y
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 1.18-lock-warnings
timestamp: Fri 2009-07-31 10:49:25 -0500
message:
Change the flags around a bit.
Now it is selftest -Edisable_lock_checks rather than -Dlock
it is also now -Dstrict-locks to enable the new debugging,
and I'll work on getting the test suite to always set that value,
with -Edisable_lock_checks reverting that value.
-------------- next part --------------
=== modified file 'bzrlib/lock.py'
--- a/bzrlib/lock.py 2009-07-30 21:01:06 +0000
+++ b/bzrlib/lock.py 2009-07-31 15:49:25 +0000
@@ -187,11 +187,16 @@
super(_fcntl_WriteLock, self).__init__()
# Check we can grab a lock before we actually open the file.
self.filename = osutils.realpath(filename)
- if (self.filename in _fcntl_WriteLock._open_locks
- or ('lock' in debug.debug_flags
- and self.filename in _fcntl_ReadLock._open_locks)):
+ if self.filename in _fcntl_WriteLock._open_locks:
self._clear_f()
raise errors.LockContention(self.filename)
+ if self.filename in _fcntl_ReadLock._open_locks:
+ if 'strict-locks' in debug.debug_flags:
+ self._clear_f()
+ raise errors.LockContention(self.filename)
+ else:
+ trace.mutter('Write lock taken w/ an open read lock on: %s'
+ % (self.filename,))
self._open(self.filename, 'rb+')
# reserve a slot for this lock - even if the lockf call fails,
@@ -222,9 +227,12 @@
def __init__(self, filename):
super(_fcntl_ReadLock, self).__init__()
self.filename = osutils.realpath(filename)
- if ('lock' in debug.debug_flags and
- self.filename in _fcntl_WriteLock._open_locks):
- raise errors.LockContention(self.filename)
+ if self.filename in _fcntl_WriteLock._open_locks:
+ if 'strict-locks' in debug.debug_flags:
+ raise errors.LockContention(self.filename)
+ else:
+ trace.mutter('Read lock taken w/ an open write lock on: %s'
+ % (self.filename,))
_fcntl_ReadLock._open_locks.setdefault(self.filename, 0)
_fcntl_ReadLock._open_locks[self.filename] += 1
self._open(filename, 'rb')
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py 2009-07-30 22:03:09 +0000
+++ b/bzrlib/tests/__init__.py 2009-07-31 15:49:25 +0000
@@ -830,8 +830,8 @@
self._preserved_debug_flags = set(debug.debug_flags)
if 'allow_debug' not in selftest_debug_flags:
debug.debug_flags.clear()
- if 'lock' in selftest_debug_flags:
- debug.debug_flags.add('lock')
+ # if 'disable_lock_checks' not in selftest_debug_flags:
+ # debug.debug_flags.add('strict-locks')
self.addCleanup(self._restore_debug_flags)
def _clear_hooks(self):
@@ -859,8 +859,9 @@
def _check_locks(self):
"""Check that all lock take/release actions have been paired."""
- # once we have fixed all the current lock problems, we can change the
- # following code to always check for mismatched locks
+ # We always check for mismatched locks. If a mismatch is found, we
+ # fail unless -Edisable_lock_checks is supplied to selftest, in which
+ # case we just print a warning.
# unhook:
acquired_locks = [lock for action, lock in self._lock_actions
if action == 'acquired']
@@ -876,11 +877,20 @@
message = ('Different number of acquired and '
'released or broken locks. (%s, %s + %s)' %
(acquired_locks, released_locks, broken_locks))
+ if not self._lock_check_thorough:
+ # Rather than fail, just warn
+ print "Broken test %s: %s" % (self, message)
+ return
self.fail(message)
def _track_locks(self):
"""Track lock activity during tests."""
self._lock_actions = []
+ if 'disable_lock_checks' in selftest_debug_flags:
+ self._lock_check_thorough = False
+ else:
+ self._lock_check_thorough = True
+
self.addCleanup(self._check_locks)
_mod_lock.Lock.hooks.install_named_hook('lock_acquired',
self._lock_acquired, None)
@@ -3114,6 +3124,13 @@
# Controlled by "bzr selftest -E=..." option
+# Currently supported:
+# -Eallow_debug Will no longer clear debug.debug_flags() so it
+# preserves any flags supplied at the command line.
+# -Edisable_lock_checks Turns errors in mismatched locks into simple prints
+# rather than failing tests. And no longer raise
+# LockContention when fctnl locks are not being used
+# with proper exclusion rules.
selftest_debug_flags = set()
=== modified file 'bzrlib/tests/test_lock.py'
--- a/bzrlib/tests/test_lock.py 2009-07-30 21:01:06 +0000
+++ b/bzrlib/tests/test_lock.py 2009-07-31 15:49:25 +0000
@@ -76,11 +76,11 @@
try:
if lock.have_fcntl and self.write_lock is lock._fcntl_WriteLock:
# With -Dlock, fcntl locks are properly exclusive
- debug.debug_flags.add('lock')
+ debug.debug_flags.add('strict-locks')
self.assertRaises(errors.LockContention,
self.write_lock, 'a-lock-file')
# But not without it
- debug.debug_flags.remove('lock')
+ debug.debug_flags.remove('strict-locks')
try:
w_lock = self.write_lock('a-lock-file')
except errors.LockContention:
@@ -101,11 +101,11 @@
try:
if lock.have_fcntl and self.read_lock is lock._fcntl_ReadLock:
# With -Dlock, fcntl locks are properly exclusive
- debug.debug_flags.add('lock')
+ debug.debug_flags.add('strict-locks')
self.assertRaises(errors.LockContention,
self.read_lock, 'a-lock-file')
# But not without it
- debug.debug_flags.remove('lock')
+ debug.debug_flags.remove('strict-locks')
try:
r_lock = self.read_lock('a-lock-file')
except errors.LockContention:
More information about the bazaar-commits
mailing list