100
100
self.assertTrue(wt.branch.is_locked())
101
101
wt.branch.unlock()
103
def _test_unlock_with_lock_method(self, methodname):
104
"""Create a tree and then test its unlocking behaviour.
106
:param methodname: The lock method to use to establish locks.
108
# when unlocking the last lock count from tree_write_lock,
109
# the tree should do a flush().
110
# we test that by changing the inventory using set_root_id
111
tree = self.make_branch_and_tree('tree')
112
# prepare for a series of changes that will modify the
114
getattr(tree, methodname)()
115
# note that we dont have a try:finally here because of two reasons:
116
# firstly there will only be errors reported if the test fails, and
117
# when it fails thats ok as long as the test suite cleanup still works,
118
# which it will as the lock objects are released (thats where the
119
# warning comes from. Secondly, it is hard in this test to be
120
# sure that we've got the right interactions between try:finally
121
# and the lock/unlocks we are doing.
122
getattr(tree, methodname)()
123
# this should really do something within the public api
124
# e.g. mkdir('foo') but all the mutating methods at the
125
# moment trigger inventory writes and thus will not
126
# let us trigger a read-when-dirty situation.
127
old_root = tree.get_root_id()
128
tree.set_root_id('new-root')
129
# to detect that the inventory is written by unlock, we
130
# first check that it was not written yet.
131
reference_tree = tree.bzrdir.open_workingtree()
132
self.assertEqual(old_root, reference_tree.get_root_id())
133
# now unlock the second held lock, which should do nothing.
135
reference_tree = tree.bzrdir.open_workingtree()
136
self.assertEqual(old_root, reference_tree.get_root_id())
137
# unlocking the first lock we took will now flush.
139
# and check it was written using another reference tree
140
reference_tree = tree.bzrdir.open_workingtree()
141
self.assertEqual('new-root', reference_tree.get_root_id())
143
def test_unlock_from_tree_write_lock_flushes(self):
144
self._test_unlock_with_lock_method("lock_tree_write")
146
def test_unlock_from_write_lock_flushes(self):
147
self._test_unlock_with_lock_method("lock_write")
103
149
def test_unlock_branch_failures(self):
104
150
"""If the branch unlock fails the tree must still unlock."""
105
151
# The public interface for WorkingTree requires a branch, but