Rev 4530: Change the fcntl locks so they are only exclusive with -Dlock. in lp:///~jameinel/bzr/1.18-lock-warnings
John Arbash Meinel
john at arbash-meinel.com
Thu Jul 30 22:03:01 BST 2009
At lp:///~jameinel/bzr/1.18-lock-warnings
------------------------------------------------------------
revno: 4530
revision-id: john at arbash-meinel.com-20090730210106-7m4zs5bxl0cqgtn8
parent: john at arbash-meinel.com-20090730204645-w20f3wb8k480b5kc
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 1.18-lock-warnings
timestamp: Thu 2009-07-30 16:01:06 -0500
message:
Change the fcntl locks so they are only exclusive with -Dlock.
Update the tests to handle this fact.
-------------- next part --------------
=== modified file 'bzrlib/lock.py'
--- a/bzrlib/lock.py 2009-07-30 20:46:45 +0000
+++ b/bzrlib/lock.py 2009-07-30 21:01:06 +0000
@@ -188,7 +188,8 @@
# 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 self.filename in _fcntl_ReadLock._open_locks):
+ or ('lock' in debug.debug_flags
+ and self.filename in _fcntl_ReadLock._open_locks)):
self._clear_f()
raise errors.LockContention(self.filename)
@@ -221,7 +222,8 @@
def __init__(self, filename):
super(_fcntl_ReadLock, self).__init__()
self.filename = osutils.realpath(filename)
- if self.filename in _fcntl_WriteLock._open_locks:
+ if ('lock' in debug.debug_flags and
+ self.filename in _fcntl_WriteLock._open_locks):
raise errors.LockContention(self.filename)
_fcntl_ReadLock._open_locks.setdefault(self.filename, 0)
_fcntl_ReadLock._open_locks[self.filename] += 1
=== modified file 'bzrlib/tests/test_lock.py'
--- a/bzrlib/tests/test_lock.py 2009-07-10 20:07:24 +0000
+++ b/bzrlib/tests/test_lock.py 2009-07-30 21:01:06 +0000
@@ -19,8 +19,9 @@
from bzrlib import (
+ debug,
+ errors,
lock,
- errors,
tests,
)
@@ -73,16 +74,50 @@
def test_read_locks_block_write_locks(self):
r_lock = self.read_lock('a-lock-file')
try:
- self.assertRaises(errors.LockContention,
- self.write_lock, 'a-lock-file')
+ if lock.have_fcntl and self.write_lock is lock._fcntl_WriteLock:
+ # With -Dlock, fcntl locks are properly exclusive
+ debug.debug_flags.add('lock')
+ self.assertRaises(errors.LockContention,
+ self.write_lock, 'a-lock-file')
+ # But not without it
+ debug.debug_flags.remove('lock')
+ try:
+ w_lock = self.write_lock('a-lock-file')
+ except errors.LockContention:
+ self.fail('Unexpected success. fcntl read locks'
+ ' do not usually block write locks')
+ else:
+ w_lock.unlock()
+ self.knownFailure('fcntl read locks don\'t'
+ ' block write locks without -Dlock')
+ else:
+ self.assertRaises(errors.LockContention,
+ self.write_lock, 'a-lock-file')
finally:
r_lock.unlock()
def test_write_locks_block_read_lock(self):
w_lock = self.write_lock('a-lock-file')
try:
- self.assertRaises(errors.LockContention,
- self.read_lock, 'a-lock-file')
+ if lock.have_fcntl and self.read_lock is lock._fcntl_ReadLock:
+ # With -Dlock, fcntl locks are properly exclusive
+ debug.debug_flags.add('lock')
+ self.assertRaises(errors.LockContention,
+ self.read_lock, 'a-lock-file')
+ # But not without it
+ debug.debug_flags.remove('lock')
+ try:
+ r_lock = self.read_lock('a-lock-file')
+ except errors.LockContention:
+ self.fail('Unexpected success. fcntl write locks'
+ ' do not usually block read locks')
+ else:
+ r_lock.unlock()
+ self.knownFailure('fcntl write locks don\'t'
+ ' block read locks without -Dlock')
+ else:
+ self.assertRaises(errors.LockContention,
+ self.read_lock, 'a-lock-file')
finally:
w_lock.unlock()
More information about the bazaar-commits
mailing list