~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_break_lock.py

  • Committer: John Arbash Meinel
  • Date: 2006-05-10 17:48:25 UTC
  • mfrom: (1704 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1705.
  • Revision ID: john@arbash-meinel.com-20060510174825-74dcaba644915bec
[merge] bzr.dev 1704

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
import os
20
20
 
 
21
import bzrlib
 
22
import bzrlib.errors as errors
21
23
from bzrlib.branch import Branch
22
24
from bzrlib.bzrdir import BzrDir
23
 
from bzrlib.tests import TestCaseInTempDir
24
 
 
25
 
class TestBreakLock(TestCaseInTempDir):
 
25
from bzrlib.tests.blackbox import ExternalBase
 
26
 
 
27
 
 
28
class TestBreakLock(ExternalBase):
 
29
 
 
30
    # General principal for break-lock: All the elements that might be locked
 
31
    # by a bzr operation on PATH, are candidates that break-lock may unlock.
 
32
    # so pathologically if we have a lightweight checkout A, of branch B, which
 
33
    # is bound to location C, the following things should be checked for locks
 
34
    # to break:
 
35
    # wt = WorkingTree(A)
 
36
    # wt.branch
 
37
    # wt.branch.repository
 
38
    # wt.branch.get_master_branch()
 
39
    # wt.branch.get_master_branch().repository
 
40
    # so for smoke tests all we need is a bound branch with a checkout of that
 
41
    # and we can then use different urls to test individual cases, for as much
 
42
    # granularity as needed.
 
43
 
 
44
    def setUp(self):
 
45
        super(TestBreakLock, self).setUp()
 
46
        self.build_tree(
 
47
            ['master-repo/',
 
48
             'master-repo/master-branch/',
 
49
             'repo/',
 
50
             'repo/branch/',
 
51
             'checkout/'])
 
52
        bzrlib.bzrdir.BzrDir.create('master-repo').create_repository()
 
53
        self.master_branch = bzrlib.bzrdir.BzrDir.create_branch_convenience(
 
54
            'master-repo/master-branch')
 
55
        bzrlib.bzrdir.BzrDir.create('repo').create_repository()
 
56
        local_branch = bzrlib.bzrdir.BzrDir.create_branch_convenience('repo/branch')
 
57
        local_branch.bind(self.master_branch)
 
58
        checkoutdir = bzrlib.bzrdir.BzrDir.create('checkout')
 
59
        bzrlib.branch.BranchReferenceFormat().initialize(
 
60
            checkoutdir, local_branch)
 
61
        self.wt = checkoutdir.create_workingtree()
 
62
 
26
63
    def test_break_lock_help(self):
27
 
        self.run_bzr('break-lock', '--help')
28
 
        # shouldn't fail
29
 
 
30
 
    def test_show_no_lock(self):
31
 
        wt = BzrDir.create_standalone_workingtree('.')
32
 
        # out, err = self.run_bzr('break-lock', '--show', '.', retcode=3)
33
 
        # shouldn't see any information
34
 
        # self.assertContainsRe(err, 'not locked')
 
64
        out, err = self.run_bzr('break-lock', '--help')
 
65
        # shouldn't fail and should not produce error output
 
66
        self.assertEqual('', err)
 
67
 
 
68
    def test_break_lock_everything_locked(self):
 
69
        ### if everything is locked, we should be able to unlock the lot.
 
70
        # sketch of test:
 
71
        # lock the lot:
 
72
        self.wt.lock_write()
 
73
        self.master_branch.lock_write()
 
74
        # run the break-lock
 
75
        # we need 5 yes's - wt, branch, repo, bound branch, bound repo.
 
76
        self.run_bzr('break-lock', 'checkout', stdin="y\ny\ny\ny\ny\n")
 
77
        # a new tree instance should be lockable
 
78
        wt = bzrlib.workingtree.WorkingTree.open('checkout')
 
79
        wt.lock_write()
 
80
        wt.unlock()
 
81
        # and a new instance of the master branch 
 
82
        mb = wt.branch.get_master_branch()
 
83
        mb.lock_write()
 
84
        mb.unlock()
 
85
        self.assertRaises(errors.LockBroken, self.wt.unlock)
 
86
        self.assertRaises(errors.LockBroken, self.master_branch.unlock)
 
87
 
 
88
    def test_saying_no_leaves_it_locked(self):
 
89
        ### if 'no' is answered, objects should remain locked.
 
90
        self.wt.lock_write()
 
91
        self.master_branch.lock_write()
 
92
        # run the break-lock
 
93
        # we need 5 yes's - wt, branch, repo, bound branch, bound repo.
 
94
        self.run_bzr('break-lock', 'checkout', stdin="n\nn\nn\nn\nn\n")
 
95
        # a new tree instance should not be lockable
 
96
        wt = bzrlib.workingtree.WorkingTree.open('checkout')
 
97
        self.assertRaises(errors.LockContention, wt.lock_write)
 
98
        # and a new instance of the master branch 
 
99
        mb = wt.branch.get_master_branch()
 
100
        self.assertRaises(errors.LockContention, mb.lock_write)
 
101
        # unlock our branches normally.
 
102
        self.wt.unlock()
 
103
        self.master_branch.unlock()
 
104
 
 
105
 
 
106
class TestBreakLockOldBranch(ExternalBase):
 
107
 
 
108
    def test_break_lock_format_5_bzrdir(self):
 
109
        # break lock on a format 5 bzrdir should just return
 
110
        self.make_branch_and_tree('foo', format=bzrlib.bzrdir.BzrDirFormat5())
 
111
        out, err = self.run_bzr('break-lock', 'foo')
 
112
        self.assertEqual('', out)
 
113
        self.assertEqual('', err)