~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Martin Pool
  • Date: 2010-04-01 04:41:18 UTC
  • mto: This revision was merged to the branch mainline in revision 5128.
  • Revision ID: mbp@sourcefrog.net-20100401044118-shyctqc02ob08ngz
ignore .testrepository

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
import bzrlib
22
22
from bzrlib import (
23
 
    branch,
24
 
    bzrdir,
25
 
    config,
26
23
    errors,
27
24
    lockdir,
28
 
    osutils,
29
 
    tests,
30
25
    )
31
 
 
32
 
 
33
 
class TestBreakLock(tests.TestCaseWithTransport):
 
26
from bzrlib.branch import Branch
 
27
from bzrlib.bzrdir import BzrDir
 
28
from bzrlib.tests.blackbox import ExternalBase
 
29
 
 
30
 
 
31
class TestBreakLock(ExternalBase):
34
32
 
35
33
    # General principal for break-lock: All the elements that might be locked
36
34
    # by a bzr operation on PATH, are candidates that break-lock may unlock.
54
52
             'repo/',
55
53
             'repo/branch/',
56
54
             'checkout/'])
57
 
        bzrdir.BzrDir.create('master-repo').create_repository()
58
 
        self.master_branch = bzrdir.BzrDir.create_branch_convenience(
 
55
        bzrlib.bzrdir.BzrDir.create('master-repo').create_repository()
 
56
        self.master_branch = bzrlib.bzrdir.BzrDir.create_branch_convenience(
59
57
            'master-repo/master-branch')
60
 
        bzrdir.BzrDir.create('repo').create_repository()
61
 
        local_branch = bzrdir.BzrDir.create_branch_convenience('repo/branch')
 
58
        bzrlib.bzrdir.BzrDir.create('repo').create_repository()
 
59
        local_branch = bzrlib.bzrdir.BzrDir.create_branch_convenience('repo/branch')
62
60
        local_branch.bind(self.master_branch)
63
 
        checkoutdir = bzrdir.BzrDir.create('checkout')
64
 
        branch.BranchReferenceFormat().initialize(
 
61
        checkoutdir = bzrlib.bzrdir.BzrDir.create('checkout')
 
62
        bzrlib.branch.BranchReferenceFormat().initialize(
65
63
            checkoutdir, target_branch=local_branch)
66
64
        self.wt = checkoutdir.create_workingtree()
67
65
 
75
73
        # however, we dont test breaking the working tree because we
76
74
        # cannot accurately do so right now: the dirstate lock is held
77
75
        # by an os lock, and we need to spawn a separate process to lock it
78
 
        # then kill -9 it.
 
76
        # thne kill -9 it.
79
77
        # sketch of test:
80
78
        # lock most of the dir:
81
79
        self.wt.branch.lock_write()
84
82
        # we need 5 yes's - wt, branch, repo, bound branch, bound repo.
85
83
        self.run_bzr('break-lock checkout', stdin="y\ny\ny\ny\n")
86
84
        # a new tree instance should be lockable
87
 
        br = branch.Branch.open('checkout')
88
 
        br.lock_write()
89
 
        br.unlock()
 
85
        branch = bzrlib.branch.Branch.open('checkout')
 
86
        branch.lock_write()
 
87
        branch.unlock()
90
88
        # and a new instance of the master branch
91
 
        mb = br.get_master_branch()
 
89
        mb = branch.get_master_branch()
92
90
        mb.lock_write()
93
91
        mb.unlock()
94
92
        self.assertRaises(errors.LockBroken, self.wt.unlock)
95
93
        self.assertRaises(errors.LockBroken, self.master_branch.unlock)
96
94
 
97
95
 
98
 
class TestBreakLockOldBranch(tests.TestCaseWithTransport):
 
96
class TestBreakLockOldBranch(ExternalBase):
99
97
 
100
98
    def test_break_lock_format_5_bzrdir(self):
101
99
        # break lock on a format 5 bzrdir should just return
102
 
        self.make_branch_and_tree('foo', format=bzrdir.BzrDirFormat5())
 
100
        self.make_branch_and_tree('foo', format=bzrlib.bzrdir.BzrDirFormat5())
103
101
        out, err = self.run_bzr('break-lock foo')
104
102
        self.assertEqual('', out)
105
103
        self.assertEqual('', err)
106
 
 
107
 
class TestConfigBreakLock(tests.TestCaseWithTransport):
108
 
 
109
 
    def setUp(self):
110
 
        super(TestConfigBreakLock, self).setUp()
111
 
        self.config_file_name = './my.conf'
112
 
        self.build_tree_contents([(self.config_file_name,
113
 
                                   '[DEFAULT]\none=1\n')])
114
 
        self.config = config.LockableConfig(file_name=self.config_file_name)
115
 
        self.config.lock_write()
116
 
 
117
 
    def test_create_pending_lock(self):
118
 
        self.addCleanup(self.config.unlock)
119
 
        self.assertTrue(self.config._lock.is_held)
120
 
 
121
 
    def test_break_lock(self):
122
 
        self.run_bzr('break-lock --config %s'
123
 
                     % osutils.dirname(self.config_file_name),
124
 
                     stdin="y\n")
125
 
        self.assertRaises(errors.LockBroken, self.config.unlock)
126