~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/branch_implementations/test_locking.py

  • Committer: Martin Pool
  • Date: 2007-04-04 01:22:11 UTC
  • mfrom: (2393.1.1 bzr.docs)
  • mto: This revision was merged to the branch mainline in revision 2397.
  • Revision ID: mbp@sourcefrog.net-20070404012211-sq269me6bai9m6xk
merge trunk and doc fix from elliot

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Test locks across all branch implemenations"""
18
18
 
 
19
from bzrlib import errors
 
20
from bzrlib.branch import BzrBranchFormat4
 
21
from bzrlib.tests import TestSkipped
19
22
from bzrlib.tests.branch_implementations.test_branch import TestCaseWithBranch
20
23
from bzrlib.tests.lock_helpers import TestPreventLocking, LockWrapper
21
24
 
22
25
 
23
26
class TestBranchLocking(TestCaseWithBranch):
24
27
 
 
28
    def setUp(self):
 
29
        TestCaseWithBranch.setUp(self)
 
30
        self.reduceLockdirTimeout()
 
31
 
25
32
    def get_instrumented_branch(self):
26
33
        """Get a Branch object which has been instrumented"""
27
34
        # TODO: jam 20060630 It may be that not all formats have a 
220
227
                          ('rc', 'ul', True),
221
228
                         ], self.locks)
222
229
 
 
230
    def test_lock_read_then_unlock(self):
 
231
        # Calling lock_read then unlocking should work without errors.
 
232
        branch = self.make_branch('b')
 
233
        branch.lock_read()
 
234
        branch.unlock()
 
235
 
 
236
    def test_lock_write_locks_repo_too(self):
 
237
        if isinstance(self.branch_format, BzrBranchFormat4):
 
238
            # Branch format 4 is combined with the repository, so this test
 
239
            # doesn't apply.
 
240
            return
 
241
        branch = self.make_branch('b')
 
242
        branch = branch.bzrdir.open_branch()
 
243
        branch.lock_write()
 
244
        try:
 
245
            # Now the branch.repository is locked, so we can't lock it with a new
 
246
            # repository without a token.
 
247
            new_repo = branch.bzrdir.open_repository()
 
248
            self.assertRaises(errors.LockContention, new_repo.lock_write)
 
249
            # We can call lock_write on the original repository object though,
 
250
            # because it is already locked.
 
251
            branch.repository.lock_write()
 
252
            branch.repository.unlock()
 
253
        finally:
 
254
            branch.unlock()