Rev 4299: Hopefully fix locking tests to match the new code (and still be good statements of intent). in http://people.ubuntu.com/~robertc/baz2.0/pending/push.roundtrips
Robert Collins
robertc at robertcollins.net
Wed Apr 15 06:39:41 BST 2009
At http://people.ubuntu.com/~robertc/baz2.0/pending/push.roundtrips
------------------------------------------------------------
revno: 4299
revision-id: robertc at robertcollins.net-20090415053938-9w379adk8993sq1q
parent: robertc at robertcollins.net-20090415044506-30fnvsa3ukai60xb
committer: Robert Collins <robertc at robertcollins.net>
branch nick: push.roundtrips
timestamp: Wed 2009-04-15 15:39:38 +1000
message:
Hopefully fix locking tests to match the new code (and still be good statements of intent).
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py 2009-04-15 04:45:06 +0000
+++ b/bzrlib/branch.py 2009-04-15 05:39:38 +0000
@@ -1931,7 +1931,7 @@
def lock_write(self, token=None):
repo_control = getattr(self.repository, 'control_files', None)
- if self.control_files is repo_control or not self.is_locked():
+ if self.control_files == repo_control or not self.is_locked():
self.repository.lock_write()
took_lock = True
else:
@@ -1945,7 +1945,7 @@
def lock_read(self):
repo_control = getattr(self.repository, 'control_files', None)
- if self.control_files is repo_control or not self.is_locked():
+ if self.control_files == repo_control or not self.is_locked():
self.repository.lock_read()
took_lock = True
else:
@@ -1958,14 +1958,16 @@
raise
def unlock(self):
- self.control_files.unlock()
- repo_control = getattr(self.repository, 'control_files', None)
- if (self.control_files is repo_control or
- not self.control_files.is_locked()):
- self.repository.unlock()
- if not self.control_files.is_locked():
- # we just released the lock
- self._clear_cached_state()
+ try:
+ self.control_files.unlock()
+ finally:
+ repo_control = getattr(self.repository, 'control_files', None)
+ if (self.control_files == repo_control or
+ not self.control_files.is_locked()):
+ self.repository.unlock()
+ if not self.control_files.is_locked():
+ # we just released the lock
+ self._clear_cached_state()
def peek_lock_mode(self):
if self.control_files._lock_count == 0:
=== modified file 'bzrlib/tests/branch_implementations/test_locking.py'
--- a/bzrlib/tests/branch_implementations/test_locking.py 2009-03-23 14:59:43 +0000
+++ b/bzrlib/tests/branch_implementations/test_locking.py 2009-04-15 05:39:38 +0000
@@ -171,7 +171,9 @@
b.repository._other.unlock()
def test_04_lock_fail_unlock_control(self):
- # Make sure repository.unlock() is called, if we fail to unlock self
+ # Make sure repository.unlock() is not called, if we fail to unlock
+ # self leaving ourselves still locked, so that attempts to recover
+ # don't encounter an unlocked repository.
b = self.get_instrumented_branch()
b.control_files.disable_unlock()
@@ -183,10 +185,7 @@
self.assertTrue(b.repository.is_locked())
self.assertRaises(TestPreventLocking, b.unlock)
self.assertTrue(b.is_locked())
- if self.combined_control:
- self.assertTrue(b.repository.is_locked())
- else:
- self.assertFalse(b.repository.is_locked())
+ self.assertTrue(b.repository.is_locked())
# We unlock the repository even if
# we fail to unlock the control files
@@ -206,7 +205,6 @@
('bc', 'lw', True),
('b', 'ul', True),
('bc', 'ul', False),
- ('r', 'ul', True),
], self.locks)
finally:
=== modified file 'bzrlib/tests/lock_helpers.py'
--- a/bzrlib/tests/lock_helpers.py 2009-03-23 14:59:43 +0000
+++ b/bzrlib/tests/lock_helpers.py 2009-04-15 05:39:38 +0000
@@ -44,6 +44,12 @@
self.__dict__['_allow_read'] = True
self.__dict__['_allow_unlock'] = True
+ def __eq__(self, other):
+ # Branch objects look for controlfiles == repo.controlfiles.
+ if type(other) == LockWrapper:
+ return self._other == other._other
+ return False
+
def __getattr__(self, attr):
return getattr(self._other, attr)
More information about the bazaar-commits
mailing list