Merge lp:~vila/bzr/failing-lock-tests into lp:~bzr/bzr/trunk-old

Proposed by Vincent Ladeuil
Status: Merged
Merged at revision: not available
Proposed branch: lp:~vila/bzr/failing-lock-tests
Merge into: lp:~bzr/bzr/trunk-old
Diff against target: 526 lines
To merge this branch: bzr merge lp:~vila/bzr/failing-lock-tests
Reviewer Review Type Date Requested Status
Robert Collins (community) Approve
Review via email: mp+6418@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Vincent Ladeuil (vila) wrote :

This fixed all the remaining failures (~30) encountered when running:

 bzr selftest -Dlock --no-plugins

We may want to wait a bit before switching to unconditional failure (-Dlock transform the warning into a failure for now), so that plugin authors have a bit more time to address their own failures (1.15rc1 is a bit too close to switch IMHO).

Revision history for this message
Robert Collins (lifeless) wrote :

 review approve

I think you should invert the sense of the test, so that
selftest -> lock mismatch is fatal
selftest -Dlock -> lock mismatch warns.

That will give plugin authors immediate feedback even if they use build
scripts or whatever.

We can loosen it up again for 1.15 if plugin authors are having
trouble.

-Rob

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'NEWS'
--- NEWS 2009-05-12 03:47:18 +0000
+++ NEWS 2009-05-12 08:35:12 +0000
@@ -167,6 +167,12 @@
167167
168* Updated the bundled ``ConfigObj`` library to 4.6.0 (Matt Nordhoff)168* Updated the bundled ``ConfigObj`` library to 4.6.0 (Matt Nordhoff)
169169
170Testing
171*******
172
173* ``bzr selftest`` will now fail if lock/unlock are not correctly balanced in
174 tests. Using ``-Dlock`` will turn the related failures into warnings.
175 (Vincent Ladeuil, Robert Collins)
170176
171bzr 1.14177bzr 1.14
172###########178###########
173179
=== modified file 'bzrlib/tests/__init__.py'
--- bzrlib/tests/__init__.py 2009-05-11 06:44:30 +0000
+++ bzrlib/tests/__init__.py 2009-05-12 08:35:12 +0000
@@ -884,7 +884,7 @@
884 def _track_locks(self):884 def _track_locks(self):
885 """Track lock activity during tests."""885 """Track lock activity during tests."""
886 self._lock_actions = []886 self._lock_actions = []
887 self._lock_check_thorough = 'lock' in debug.debug_flags887 self._lock_check_thorough = 'lock' not in debug.debug_flags
888 self.addCleanup(self._check_locks)888 self.addCleanup(self._check_locks)
889 _mod_lock.Lock.hooks.install_named_hook('lock_acquired',889 _mod_lock.Lock.hooks.install_named_hook('lock_acquired',
890 self._lock_acquired, None)890 self._lock_acquired, None)
891891
=== modified file 'bzrlib/tests/branch_implementations/test_locking.py'
--- bzrlib/tests/branch_implementations/test_locking.py 2009-04-15 05:39:38 +0000
+++ bzrlib/tests/branch_implementations/test_locking.py 2009-05-12 08:35:12 +0000
@@ -432,6 +432,10 @@
432 branch.unlock()432 branch.unlock()
433 # We should be unable to relock the repo.433 # We should be unable to relock the repo.
434 self.assertRaises(errors.LockContention, branch.lock_write)434 self.assertRaises(errors.LockContention, branch.lock_write)
435 # Cleanup
436 branch.lock_write(token)
437 branch.dont_leave_lock_in_place()
438 branch.unlock()
435439
436 def test_dont_leave_lock_in_place(self):440 def test_dont_leave_lock_in_place(self):
437 branch = self.make_branch('b')441 branch = self.make_branch('b')
438442
=== modified file 'bzrlib/tests/per_repository/test_repository.py'
--- bzrlib/tests/per_repository/test_repository.py 2009-04-09 20:23:07 +0000
+++ bzrlib/tests/per_repository/test_repository.py 2009-05-12 08:35:12 +0000
@@ -1046,6 +1046,10 @@
1046 repo.unlock()1046 repo.unlock()
1047 # We should be unable to relock the repo.1047 # We should be unable to relock the repo.
1048 self.assertRaises(errors.LockContention, repo.lock_write)1048 self.assertRaises(errors.LockContention, repo.lock_write)
1049 # Cleanup
1050 repo.lock_write(token)
1051 repo.dont_leave_lock_in_place()
1052 repo.unlock()
10491053
1050 def test_dont_leave_lock_in_place(self):1054 def test_dont_leave_lock_in_place(self):
1051 repo = self.make_repository('r')1055 repo = self.make_repository('r')
10521056
=== modified file 'bzrlib/tests/per_repository/test_write_group.py'
--- bzrlib/tests/per_repository/test_write_group.py 2009-05-12 01:36:08 +0000
+++ bzrlib/tests/per_repository/test_write_group.py 2009-05-12 08:35:12 +0000
@@ -112,13 +112,13 @@
112 self.addCleanup(repo.unlock)112 self.addCleanup(repo.unlock)
113 repo.start_write_group()113 repo.start_write_group()
114 # Damage the repository on the filesystem114 # Damage the repository on the filesystem
115 self.get_transport('').rename('repo', 'foo')115 t = self.get_transport('')
116 t.rename('repo', 'foo')
117 self.addCleanup(t.rename, 'foo', 'repo')
116 # abort_write_group will not raise an error, because either an118 # abort_write_group will not raise an error, because either an
117 # exception was not generated, or the exception was caught and119 # exception was not generated, or the exception was caught and
118 # suppressed. See also test_pack_repository's test of the same name.120 # suppressed. See also test_pack_repository's test of the same name.
119 self.assertEqual(None, repo.abort_write_group(suppress_errors=True))121 self.assertEqual(None, repo.abort_write_group(suppress_errors=True))
120 if token is not None:
121 repo.leave_lock_in_place()
122122
123class TestGetMissingParentInventories(TestCaseWithRepository):123class TestGetMissingParentInventories(TestCaseWithRepository):
124124
125125
=== modified file 'bzrlib/tests/test_lockable_files.py'
--- bzrlib/tests/test_lockable_files.py 2009-04-04 02:50:01 +0000
+++ bzrlib/tests/test_lockable_files.py 2009-05-12 08:35:12 +0000
@@ -56,72 +56,68 @@
56 deprecated_in((1, 5, 0)),56 deprecated_in((1, 5, 0)),
57 self.lockable.get_utf8, 'foo')57 self.lockable.get_utf8, 'foo')
58 self.lockable.lock_write()58 self.lockable.lock_write()
59 try:59 self.addCleanup(self.lockable.unlock)
60 unicode_string = u'bar\u1234'60 unicode_string = u'bar\u1234'
61 self.assertEqual(4, len(unicode_string))61 self.assertEqual(4, len(unicode_string))
62 byte_string = unicode_string.encode('utf-8')62 byte_string = unicode_string.encode('utf-8')
63 self.assertEqual(6, len(byte_string))63 self.assertEqual(6, len(byte_string))
64 self.assertRaises(UnicodeEncodeError,64 self.assertRaises(UnicodeEncodeError,
65 self.applyDeprecated,65 self.applyDeprecated,
66 deprecated_in((1, 6, 0)),66 deprecated_in((1, 6, 0)),
67 self.lockable.put, 'foo',67 self.lockable.put, 'foo',
68 StringIO(unicode_string))68 StringIO(unicode_string))
69 self.applyDeprecated(69 self.applyDeprecated(
70 deprecated_in((1, 6, 0)),70 deprecated_in((1, 6, 0)),
71 self.lockable.put,71 self.lockable.put,
72 'foo', StringIO(byte_string))72 'foo', StringIO(byte_string))
73 byte_stream = self.applyDeprecated(73 byte_stream = self.applyDeprecated(
74 deprecated_in((1, 5, 0)),74 deprecated_in((1, 5, 0)),
75 self.lockable.get,75 self.lockable.get,
76 'foo')76 'foo')
77 self.assertEqual(byte_string, byte_stream.read())77 self.assertEqual(byte_string, byte_stream.read())
78 unicode_stream = self.applyDeprecated(78 unicode_stream = self.applyDeprecated(
79 deprecated_in((1, 5, 0)),79 deprecated_in((1, 5, 0)),
80 self.lockable.get_utf8,80 self.lockable.get_utf8,
81 'foo')81 'foo')
82 self.assertEqual(unicode_string,82 self.assertEqual(unicode_string,
83 unicode_stream.read())83 unicode_stream.read())
84 self.assertRaises(BzrBadParameterNotString,84 self.assertRaises(BzrBadParameterNotString,
85 self.applyDeprecated,85 self.applyDeprecated,
86 deprecated_in((1, 6, 0)),86 deprecated_in((1, 6, 0)),
87 self.lockable.put_utf8,87 self.lockable.put_utf8,
88 'bar',88 'bar',
89 StringIO(unicode_string))89 StringIO(unicode_string))
90 self.applyDeprecated(90 self.applyDeprecated(
91 deprecated_in((1, 6, 0)),91 deprecated_in((1, 6, 0)),
92 self.lockable.put_utf8,92 self.lockable.put_utf8,
93 'bar',93 'bar',
94 unicode_string)94 unicode_string)
95 unicode_stream = self.applyDeprecated(95 unicode_stream = self.applyDeprecated(
96 deprecated_in((1, 5, 0)),96 deprecated_in((1, 5, 0)),
97 self.lockable.get_utf8,97 self.lockable.get_utf8,
98 'bar')98 'bar')
99 self.assertEqual(unicode_string,99 self.assertEqual(unicode_string,
100 unicode_stream.read())100 unicode_stream.read())
101 byte_stream = self.applyDeprecated(101 byte_stream = self.applyDeprecated(
102 deprecated_in((1, 5, 0)),102 deprecated_in((1, 5, 0)),
103 self.lockable.get,103 self.lockable.get,
104 'bar')104 'bar')
105 self.assertEqual(byte_string, byte_stream.read())105 self.assertEqual(byte_string, byte_stream.read())
106 self.applyDeprecated(106 self.applyDeprecated(
107 deprecated_in((1, 6, 0)),107 deprecated_in((1, 6, 0)),
108 self.lockable.put_bytes,108 self.lockable.put_bytes,
109 'raw', 'raw\xffbytes')109 'raw', 'raw\xffbytes')
110 byte_stream = self.applyDeprecated(110 byte_stream = self.applyDeprecated(
111 deprecated_in((1, 5, 0)),111 deprecated_in((1, 5, 0)),
112 self.lockable.get,112 self.lockable.get,
113 'raw')113 'raw')
114 self.assertEqual('raw\xffbytes', byte_stream.read())114 self.assertEqual('raw\xffbytes', byte_stream.read())
115 finally:
116 self.lockable.unlock()
117115
118 def test_locks(self):116 def test_locks(self):
119 self.lockable.lock_read()117 self.lockable.lock_read()
120 try:118 self.addCleanup(self.lockable.unlock)
121 self.assertRaises(ReadOnlyError, self.lockable.put, 'foo',119 self.assertRaises(ReadOnlyError, self.lockable.put, 'foo',
122 StringIO('bar\u1234'))120 StringIO('bar\u1234'))
123 finally:
124 self.lockable.unlock()
125121
126 def test_transactions(self):122 def test_transactions(self):
127 self.assertIs(self.lockable.get_transaction().__class__,123 self.assertIs(self.lockable.get_transaction().__class__,
@@ -176,92 +172,80 @@
176172
177 def test_lock_write_returns_None_refuses_token(self):173 def test_lock_write_returns_None_refuses_token(self):
178 token = self.lockable.lock_write()174 token = self.lockable.lock_write()
179 try:175 self.addCleanup(self.lockable.unlock)
180 if token is not None:176 if token is not None:
181 # This test does not apply, because this lockable supports177 # This test does not apply, because this lockable supports
182 # tokens.178 # tokens.
183 raise TestNotApplicable("%r uses tokens" % (self.lockable,))179 raise TestNotApplicable("%r uses tokens" % (self.lockable,))
184 self.assertRaises(errors.TokenLockingNotSupported,180 self.assertRaises(errors.TokenLockingNotSupported,
185 self.lockable.lock_write, token='token')181 self.lockable.lock_write, token='token')
186 finally:
187 self.lockable.unlock()
188182
189 def test_lock_write_returns_token_when_given_token(self):183 def test_lock_write_returns_token_when_given_token(self):
190 token = self.lockable.lock_write()184 token = self.lockable.lock_write()
191 try:185 self.addCleanup(self.lockable.unlock)
192 if token is None:186 if token is None:
193 # This test does not apply, because this lockable refuses187 # This test does not apply, because this lockable refuses
194 # tokens.188 # tokens.
195 return189 return
196 new_lockable = self.get_lockable()190 new_lockable = self.get_lockable()
197 token_from_new_lockable = new_lockable.lock_write(token=token)191 token_from_new_lockable = new_lockable.lock_write(token=token)
198 try:192 self.addCleanup(new_lockable.unlock)
199 self.assertEqual(token, token_from_new_lockable)193 self.assertEqual(token, token_from_new_lockable)
200 finally:
201 new_lockable.unlock()
202 finally:
203 self.lockable.unlock()
204194
205 def test_lock_write_raises_on_token_mismatch(self):195 def test_lock_write_raises_on_token_mismatch(self):
206 token = self.lockable.lock_write()196 token = self.lockable.lock_write()
207 try:197 self.addCleanup(self.lockable.unlock)
208 if token is None:198 if token is None:
209 # This test does not apply, because this lockable refuses199 # This test does not apply, because this lockable refuses
210 # tokens.200 # tokens.
211 return201 return
212 different_token = token + 'xxx'202 different_token = token + 'xxx'
213 # Re-using the same lockable instance with a different token will203 # Re-using the same lockable instance with a different token will
214 # raise TokenMismatch.204 # raise TokenMismatch.
215 self.assertRaises(errors.TokenMismatch,205 self.assertRaises(errors.TokenMismatch,
216 self.lockable.lock_write, token=different_token)206 self.lockable.lock_write, token=different_token)
217 # A separate instance for the same lockable will also raise207 # A separate instance for the same lockable will also raise
218 # TokenMismatch.208 # TokenMismatch.
219 # This detects the case where a caller claims to have a lock (via209 # This detects the case where a caller claims to have a lock (via
220 # the token) for an external resource, but doesn't (the token is210 # the token) for an external resource, but doesn't (the token is
221 # different). Clients need a separate lock object to make sure the211 # different). Clients need a separate lock object to make sure the
222 # external resource is probed, whereas the existing lock object212 # external resource is probed, whereas the existing lock object
223 # might cache.213 # might cache.
224 new_lockable = self.get_lockable()214 new_lockable = self.get_lockable()
225 self.assertRaises(errors.TokenMismatch,215 self.assertRaises(errors.TokenMismatch,
226 new_lockable.lock_write, token=different_token)216 new_lockable.lock_write, token=different_token)
227 finally:
228 self.lockable.unlock()
229217
230 def test_lock_write_with_matching_token(self):218 def test_lock_write_with_matching_token(self):
231 # If the token matches, so no exception is raised by lock_write.219 # If the token matches, so no exception is raised by lock_write.
232 token = self.lockable.lock_write()220 token = self.lockable.lock_write()
233 try:221 self.addCleanup(self.lockable.unlock)
234 if token is None:222 if token is None:
235 # This test does not apply, because this lockable refuses223 # This test does not apply, because this lockable refuses
236 # tokens.224 # tokens.
237 return225 return
238 # The same instance will accept a second lock_write if the specified226 # The same instance will accept a second lock_write if the specified
239 # token matches.227 # token matches.
240 self.lockable.lock_write(token=token)228 self.lockable.lock_write(token=token)
241 self.lockable.unlock()229 self.lockable.unlock()
242 # Calling lock_write on a new instance for the same lockable will230 # Calling lock_write on a new instance for the same lockable will
243 # also succeed.231 # also succeed.
244 new_lockable = self.get_lockable()232 new_lockable = self.get_lockable()
245 new_lockable.lock_write(token=token)233 new_lockable.lock_write(token=token)
246 new_lockable.unlock()234 new_lockable.unlock()
247 finally:
248 self.lockable.unlock()
249235
250 def test_unlock_after_lock_write_with_token(self):236 def test_unlock_after_lock_write_with_token(self):
251 # If lock_write did not physically acquire the lock (because it was237 # If lock_write did not physically acquire the lock (because it was
252 # passed a token), then unlock should not physically release it.238 # passed a token), then unlock should not physically release it.
253 token = self.lockable.lock_write()239 token = self.lockable.lock_write()
254 try:240 self.addCleanup(self.lockable.unlock)
255 if token is None:241 if token is None:
256 # This test does not apply, because this lockable refuses242 # This test does not apply, because this lockable refuses
257 # tokens.243 # tokens.
258 return244 return
259 new_lockable = self.get_lockable()245 new_lockable = self.get_lockable()
260 new_lockable.lock_write(token=token)246 new_lockable.lock_write(token=token)
261 new_lockable.unlock()247 new_lockable.unlock()
262 self.assertTrue(self.lockable.get_physical_lock_status())248 self.assertTrue(self.lockable.get_physical_lock_status())
263 finally:
264 self.lockable.unlock()
265249
266 def test_lock_write_with_token_fails_when_unlocked(self):250 def test_lock_write_with_token_fails_when_unlocked(self):
267 # Lock and unlock to get a superficially valid token. This mimics a251 # Lock and unlock to get a superficially valid token. This mimics a
@@ -332,6 +316,11 @@
332 # But should be relockable with a token.316 # But should be relockable with a token.
333 self.lockable.lock_write(token=token)317 self.lockable.lock_write(token=token)
334 self.lockable.unlock()318 self.lockable.unlock()
319 # Cleanup: we should still be able to get the lock, but we restore the
320 # behavior to clearing the lock when unlocking.
321 self.lockable.lock_write(token=token)
322 self.lockable.dont_leave_in_place()
323 self.lockable.unlock()
335324
336 def test_dont_leave_in_place(self):325 def test_dont_leave_in_place(self):
337 token = self.lockable.lock_write()326 token = self.lockable.lock_write()
338327
=== modified file 'bzrlib/tests/test_selftest.py'
--- bzrlib/tests/test_selftest.py 2009-04-30 06:16:30 +0000
+++ bzrlib/tests/test_selftest.py 2009-05-12 08:35:12 +0000
@@ -622,9 +622,6 @@
622 self.assertRaises(AssertionError, self._check_safety_net)622 self.assertRaises(AssertionError, self._check_safety_net)
623623
624 def test_dangling_locks_cause_failures(self):624 def test_dangling_locks_cause_failures(self):
625 # This is currently only enabled during debug runs, so turn debugging
626 # on.
627 debug.debug_flags.add('lock')
628 class TestDanglingLock(TestCaseWithMemoryTransport):625 class TestDanglingLock(TestCaseWithMemoryTransport):
629 def test_function(self):626 def test_function(self):
630 t = self.get_transport('.')627 t = self.get_transport('.')
631628
=== modified file 'bzrlib/tests/test_smart.py'
--- bzrlib/tests/test_smart.py 2009-04-28 03:55:56 +0000
+++ bzrlib/tests/test_smart.py 2009-05-12 08:35:12 +0000
@@ -586,6 +586,8 @@
586 '')586 '')
587 self.assertEqual(SuccessfulSmartServerResponse(()), result)587 self.assertEqual(SuccessfulSmartServerResponse(()), result)
588 self.assertEqual('bar', config.get_option('foo'))588 self.assertEqual('bar', config.get_option('foo'))
589 # Cleanup
590 branch.unlock()
589591
590 def test_value_name_section(self):592 def test_value_name_section(self):
591 branch = self.make_branch('.')593 branch = self.make_branch('.')
@@ -597,6 +599,8 @@
597 'gam')599 'gam')
598 self.assertEqual(SuccessfulSmartServerResponse(()), result)600 self.assertEqual(SuccessfulSmartServerResponse(()), result)
599 self.assertEqual('bar', config.get_option('foo', 'gam'))601 self.assertEqual('bar', config.get_option('foo', 'gam'))
602 # Cleanup
603 branch.unlock()
600604
601605
602class SetLastRevisionTestBase(TestLockedBranch):606class SetLastRevisionTestBase(TestLockedBranch):
@@ -915,17 +919,24 @@
915 # with a new branch object.919 # with a new branch object.
916 new_branch = repository.bzrdir.open_branch()920 new_branch = repository.bzrdir.open_branch()
917 self.assertRaises(errors.LockContention, new_branch.lock_write)921 self.assertRaises(errors.LockContention, new_branch.lock_write)
922 # Cleanup
923 request = smart.branch.SmartServerBranchRequestUnlock(backing)
924 response = request.execute('', branch_nonce, repository_nonce)
918925
919 def test_lock_write_on_locked_branch(self):926 def test_lock_write_on_locked_branch(self):
920 backing = self.get_transport()927 backing = self.get_transport()
921 request = smart.branch.SmartServerBranchRequestLockWrite(backing)928 request = smart.branch.SmartServerBranchRequestLockWrite(backing)
922 branch = self.make_branch('.')929 branch = self.make_branch('.')
923 branch.lock_write()930 branch_token = branch.lock_write()
924 branch.leave_lock_in_place()931 branch.leave_lock_in_place()
925 branch.unlock()932 branch.unlock()
926 response = request.execute('')933 response = request.execute('')
927 self.assertEqual(934 self.assertEqual(
928 SmartServerResponse(('LockContention',)), response)935 SmartServerResponse(('LockContention',)), response)
936 # Cleanup
937 branch.lock_write(branch_token)
938 branch.dont_leave_lock_in_place()
939 branch.unlock()
929940
930 def test_lock_write_with_tokens_on_locked_branch(self):941 def test_lock_write_with_tokens_on_locked_branch(self):
931 backing = self.get_transport()942 backing = self.get_transport()
@@ -941,6 +952,13 @@
941 branch_token, repo_token)952 branch_token, repo_token)
942 self.assertEqual(953 self.assertEqual(
943 SmartServerResponse(('ok', branch_token, repo_token)), response)954 SmartServerResponse(('ok', branch_token, repo_token)), response)
955 # Cleanup
956 branch.repository.lock_write(repo_token)
957 branch.repository.dont_leave_lock_in_place()
958 branch.repository.unlock()
959 branch.lock_write(branch_token)
960 branch.dont_leave_lock_in_place()
961 branch.unlock()
944962
945 def test_lock_write_with_mismatched_tokens_on_locked_branch(self):963 def test_lock_write_with_mismatched_tokens_on_locked_branch(self):
946 backing = self.get_transport()964 backing = self.get_transport()
@@ -956,17 +974,29 @@
956 branch_token+'xxx', repo_token)974 branch_token+'xxx', repo_token)
957 self.assertEqual(975 self.assertEqual(
958 SmartServerResponse(('TokenMismatch',)), response)976 SmartServerResponse(('TokenMismatch',)), response)
977 # Cleanup
978 branch.repository.lock_write(repo_token)
979 branch.repository.dont_leave_lock_in_place()
980 branch.repository.unlock()
981 branch.lock_write(branch_token)
982 branch.dont_leave_lock_in_place()
983 branch.unlock()
959984
960 def test_lock_write_on_locked_repo(self):985 def test_lock_write_on_locked_repo(self):
961 backing = self.get_transport()986 backing = self.get_transport()
962 request = smart.branch.SmartServerBranchRequestLockWrite(backing)987 request = smart.branch.SmartServerBranchRequestLockWrite(backing)
963 branch = self.make_branch('.', format='knit')988 branch = self.make_branch('.', format='knit')
964 branch.repository.lock_write()989 repo = branch.repository
965 branch.repository.leave_lock_in_place()990 repo_token = repo.lock_write()
966 branch.repository.unlock()991 repo.leave_lock_in_place()
992 repo.unlock()
967 response = request.execute('')993 response = request.execute('')
968 self.assertEqual(994 self.assertEqual(
969 SmartServerResponse(('LockContention',)), response)995 SmartServerResponse(('LockContention',)), response)
996 # Cleanup
997 repo.lock_write(repo_token)
998 repo.dont_leave_lock_in_place()
999 repo.unlock()
9701000
971 def test_lock_write_on_readonly_transport(self):1001 def test_lock_write_on_readonly_transport(self):
972 backing = self.get_readonly_transport()1002 backing = self.get_readonly_transport()
@@ -1031,6 +1061,10 @@
1031 '', 'branch token', repo_token)1061 '', 'branch token', repo_token)
1032 self.assertEqual(1062 self.assertEqual(
1033 SmartServerResponse(('TokenMismatch',)), response)1063 SmartServerResponse(('TokenMismatch',)), response)
1064 # Cleanup
1065 branch.repository.lock_write(repo_token)
1066 branch.repository.dont_leave_lock_in_place()
1067 branch.repository.unlock()
10341068
10351069
1036class TestSmartServerRepositoryRequest(tests.TestCaseWithMemoryTransport):1070class TestSmartServerRepositoryRequest(tests.TestCaseWithMemoryTransport):
@@ -1282,17 +1316,24 @@
1282 # object.1316 # object.
1283 new_repo = repository.bzrdir.open_repository()1317 new_repo = repository.bzrdir.open_repository()
1284 self.assertRaises(errors.LockContention, new_repo.lock_write)1318 self.assertRaises(errors.LockContention, new_repo.lock_write)
1319 # Cleanup
1320 request = smart.repository.SmartServerRepositoryUnlock(backing)
1321 response = request.execute('', nonce)
12851322
1286 def test_lock_write_on_locked_repo(self):1323 def test_lock_write_on_locked_repo(self):
1287 backing = self.get_transport()1324 backing = self.get_transport()
1288 request = smart.repository.SmartServerRepositoryLockWrite(backing)1325 request = smart.repository.SmartServerRepositoryLockWrite(backing)
1289 repository = self.make_repository('.', format='knit')1326 repository = self.make_repository('.', format='knit')
1290 repository.lock_write()1327 repo_token = repository.lock_write()
1291 repository.leave_lock_in_place()1328 repository.leave_lock_in_place()
1292 repository.unlock()1329 repository.unlock()
1293 response = request.execute('')1330 response = request.execute('')
1294 self.assertEqual(1331 self.assertEqual(
1295 SmartServerResponse(('LockContention',)), response)1332 SmartServerResponse(('LockContention',)), response)
1333 # Cleanup
1334 repository.lock_write(repo_token)
1335 repository.dont_leave_lock_in_place()
1336 repository.unlock()
12961337
1297 def test_lock_write_on_readonly_transport(self):1338 def test_lock_write_on_readonly_transport(self):
1298 backing = self.get_readonly_transport()1339 backing = self.get_readonly_transport()