53
53
self.assertFalse(wt.is_locked())
54
54
self.assertFalse(wt.branch.is_locked())
56
def test_trivial_lock_tree_write_unlock(self):
57
"""Locking for tree write is ok when the branch is not locked."""
58
wt = self.make_branch_and_tree('.')
60
self.assertFalse(wt.is_locked())
61
self.assertFalse(wt.branch.is_locked())
64
self.assertTrue(wt.is_locked())
65
self.assertTrue(wt.branch.is_locked())
68
self.assertFalse(wt.is_locked())
69
self.assertFalse(wt.branch.is_locked())
71
def test_trivial_lock_tree_write_branch_read_locked(self):
72
"""It is ok to lock_tree_write when the branch is read locked."""
73
wt = self.make_branch_and_tree('.')
75
self.assertFalse(wt.is_locked())
76
self.assertFalse(wt.branch.is_locked())
80
except errors.ReadOnlyError:
81
# When ReadOnlyError is raised, it indicates that the
82
# workingtree shares its lock with the branch, which is what
83
# the git/hg/bzr0.6 formats do.
84
# in this case, no lock should have been taken - but the tree
85
# will have been locked because they share a lock. Unlocking
86
# just the branch should make everything match again correctly.
88
self.assertFalse(wt.is_locked())
89
self.assertFalse(wt.branch.is_locked())
92
self.assertTrue(wt.is_locked())
93
self.assertTrue(wt.branch.is_locked())
96
self.assertFalse(wt.is_locked())
97
self.assertTrue(wt.branch.is_locked())
56
100
def test_unlock_branch_failures(self):
57
101
"""If the branch unlock fails the tree must still unlock."""
58
102
# The public interface for WorkingTree requires a branch, but
145
189
branch_copy.unlock()
191
def test_failing_to_lock_tree_write_branch_does_not_lock(self):
192
"""If the branch cannot be read locked, dont lock the tree."""
193
# Many implementations treat read-locks as non-blocking, but some
194
# treat them as blocking with writes.. Accordingly we test this by
195
# opening the branch twice, and locking the branch for write in the
196
# second instance. Our lock contract requires separate instances to
197
# mutually exclude if a lock is exclusive at all: If we get no error
198
# locking, the test still passes.
199
wt = self.make_branch_and_tree('.')
200
branch_copy = branch.Branch.open('.')
201
branch_copy.lock_write()
205
except errors.LockError:
206
# any error here means the locks are exclusive in some
208
self.assertFalse(wt.is_locked())
209
self.assertFalse(wt.branch.is_locked())
212
# no error - the branch allows read locks while writes
213
# are taken, just pass.