~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Andrew Bennetts
  • Date: 2007-02-28 07:08:25 UTC
  • mfrom: (2018.13.1 hpss)
  • mto: (2018.5.80 hpss)
  • mto: This revision was merged to the branch mainline in revision 2435.
  • Revision ID: andrew.bennetts@canonical.com-20070228070825-q2dvkjb0a11ouhtx
Update to current hpss branch?  Fix lots of test failures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""Test locks across all branch implemenations"""
18
18
 
19
19
from bzrlib import errors
 
20
from bzrlib.branch import BzrBranchFormat4
 
21
from bzrlib.remote import RemoteBranchFormat
 
22
from bzrlib.tests import TestSkipped
20
23
from bzrlib.tests.branch_implementations.test_branch import TestCaseWithBranch
21
24
from bzrlib.tests.lock_helpers import TestPreventLocking, LockWrapper
22
25
 
33
36
        # 'control_files' member. So we should fail gracefully if
34
37
        # not there. But assuming it has them lets us test the exact 
35
38
        # lock/unlock order.
 
39
        if isinstance(self.branch_format, RemoteBranchFormat):
 
40
            raise TestSkipped(
 
41
                "RemoteBranches don't have 'control_files'.")
36
42
        self.locks = []
37
43
        b = LockWrapper(self.locks, self.get_branch(), 'b')
38
44
        b.repository = LockWrapper(self.locks, b.repository, 'r')
416
422
        branch.lock_write()
417
423
        branch.unlock()
418
424
 
 
425
    def test_lock_read_then_unlock(self):
 
426
        # Calling lock_read then unlocking should work without errors.
 
427
        branch = self.make_branch('b')
 
428
        branch.lock_read()
 
429
        branch.unlock()
 
430
 
 
431
    def test_lock_write_locks_repo_too(self):
 
432
        if isinstance(self.branch_format, BzrBranchFormat4):
 
433
            # Branch format 4 is combined with the repository, so this test
 
434
            # doesn't apply.
 
435
            return
 
436
        branch = self.make_branch('b')
 
437
        branch = branch.bzrdir.open_branch()
 
438
        branch.lock_write()
 
439
        try:
 
440
            # Now the branch.repository is locked, so we can't lock it with a new
 
441
            # repository without a token.
 
442
            new_repo = branch.bzrdir.open_repository()
 
443
            self.assertRaises(errors.LockContention, new_repo.lock_write)
 
444
            # We can call lock_write on the original repository object though,
 
445
            # because it is already locked.
 
446
            branch.repository.lock_write()
 
447
            branch.repository.unlock()
 
448
        finally:
 
449
            branch.unlock()
 
450
 
 
451
    #def test_lock_read_locks_repo_too(self):
 
452
    #    branch = self.make_branch('b')
 
453
 
 
454
 
419
455