~bzr-pqm/bzr/bzr.dev

4597.9.2 by Vincent Ladeuil
Merge bzr.dev into cleanup
1
# Copyright (C) 2006, 2007, 2009, 2010 Canonical Ltd
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
2
#
1553.5.34 by Martin Pool
Stub lock-breaking command
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
7
#
1553.5.34 by Martin Pool
Stub lock-breaking command
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
12
#
1553.5.34 by Martin Pool
Stub lock-breaking command
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1553.5.34 by Martin Pool
Stub lock-breaking command
16
17
"""Tests for lock-breaking user interface"""
18
1957.1.17 by John Arbash Meinel
Change tests that expect locking to fail to timeout sooner.
19
from bzrlib import (
5356.1.1 by Vincent Ladeuil
Cleanup test imports.
20
    branch,
21
    bzrdir,
5345.5.9 by Vincent Ladeuil
Implements 'bzr lock --config <file>'.
22
    config,
1957.1.17 by John Arbash Meinel
Change tests that expect locking to fail to timeout sooner.
23
    errors,
5345.5.9 by Vincent Ladeuil
Implements 'bzr lock --config <file>'.
24
    osutils,
5356.1.1 by Vincent Ladeuil
Cleanup test imports.
25
    tests,
1957.1.17 by John Arbash Meinel
Change tests that expect locking to fail to timeout sooner.
26
    )
6352.2.2 by Jelmer Vernooij
Use new NoVfsCalls matcher in blackbox tests.
27
from bzrlib.tests.matchers import NoVfsCalls
5416.2.1 by Martin Pool
Add 'break-lock --force'
28
from bzrlib.tests.script import (
5416.2.3 by Martin Pool
Better test for break-lock; show lock URLs as they're broken
29
    run_script,
5416.2.1 by Martin Pool
Add 'break-lock --force'
30
    )
5356.1.1 by Vincent Ladeuil
Cleanup test imports.
31
32
33
class TestBreakLock(tests.TestCaseWithTransport):
1687.1.1 by Robert Collins
Document what the break-lock commands should be like
34
35
    # General principal for break-lock: All the elements that might be locked
36
    # by a bzr operation on PATH, are candidates that break-lock may unlock.
37
    # so pathologically if we have a lightweight checkout A, of branch B, which
38
    # is bound to location C, the following things should be checked for locks
39
    # to break:
40
    # wt = WorkingTree(A)
41
    # wt.branch
42
    # wt.branch.repository
43
    # wt.branch.get_master_branch()
44
    # wt.branch.get_master_branch().repository
45
    # so for smoke tests all we need is a bound branch with a checkout of that
46
    # and we can then use different urls to test individual cases, for as much
47
    # granularity as needed.
48
49
    def setUp(self):
50
        super(TestBreakLock, self).setUp()
51
        self.build_tree(
52
            ['master-repo/',
53
             'master-repo/master-branch/',
54
             'repo/',
55
             'repo/branch/',
56
             'checkout/'])
5356.1.1 by Vincent Ladeuil
Cleanup test imports.
57
        bzrdir.BzrDir.create('master-repo').create_repository()
58
        self.master_branch = bzrdir.BzrDir.create_branch_convenience(
1687.1.1 by Robert Collins
Document what the break-lock commands should be like
59
            'master-repo/master-branch')
5356.1.1 by Vincent Ladeuil
Cleanup test imports.
60
        bzrdir.BzrDir.create('repo').create_repository()
61
        local_branch = bzrdir.BzrDir.create_branch_convenience('repo/branch')
1687.1.1 by Robert Collins
Document what the break-lock commands should be like
62
        local_branch.bind(self.master_branch)
5356.1.1 by Vincent Ladeuil
Cleanup test imports.
63
        checkoutdir = bzrdir.BzrDir.create('checkout')
64
        branch.BranchReferenceFormat().initialize(
5051.3.10 by Jelmer Vernooij
Pass colocated branch name around in more places.
65
            checkoutdir, target_branch=local_branch)
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
66
        self.wt = checkoutdir.create_workingtree()
1687.1.1 by Robert Collins
Document what the break-lock commands should be like
67
1553.5.34 by Martin Pool
Stub lock-breaking command
68
    def test_break_lock_help(self):
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
69
        out, err = self.run_bzr('break-lock --help')
1687.1.1 by Robert Collins
Document what the break-lock commands should be like
70
        # shouldn't fail and should not produce error output
71
        self.assertEqual('', err)
72
5416.2.1 by Martin Pool
Add 'break-lock --force'
73
    def test_break_lock_no_interaction(self):
74
        """With --force, the user isn't asked for confirmation"""
5416.2.3 by Martin Pool
Better test for break-lock; show lock URLs as they're broken
75
        self.master_branch.lock_write()
76
        run_script(self, """
5416.2.1 by Martin Pool
Add 'break-lock --force'
77
        $ bzr break-lock --force master-repo/master-branch
5416.2.3 by Martin Pool
Better test for break-lock; show lock URLs as they're broken
78
        Broke lock ...master-branch/.bzr/...
5416.2.1 by Martin Pool
Add 'break-lock --force'
79
        """)
80
        # lock should now be dead
5416.2.3 by Martin Pool
Better test for break-lock; show lock URLs as they're broken
81
        self.assertRaises(errors.LockBroken, self.master_branch.unlock)
5416.2.1 by Martin Pool
Add 'break-lock --force'
82
1687.1.1 by Robert Collins
Document what the break-lock commands should be like
83
    def test_break_lock_everything_locked(self):
84
        ### if everything is locked, we should be able to unlock the lot.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
85
        # however, we dont test breaking the working tree because we
86
        # cannot accurately do so right now: the dirstate lock is held
2255.2.143 by Robert Collins
Update break-lock blackbox test to not break with dirstate as the default tree format. Unfortunately this slightly reduces test coverage of the UI.
87
        # by an os lock, and we need to spawn a separate process to lock it
5345.5.2 by Vincent Ladeuil
Fix typo.
88
        # then kill -9 it.
1687.1.1 by Robert Collins
Document what the break-lock commands should be like
89
        # sketch of test:
2255.2.143 by Robert Collins
Update break-lock blackbox test to not break with dirstate as the default tree format. Unfortunately this slightly reduces test coverage of the UI.
90
        # lock most of the dir:
91
        self.wt.branch.lock_write()
1687.1.1 by Robert Collins
Document what the break-lock commands should be like
92
        self.master_branch.lock_write()
93
        # run the break-lock
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
94
        # we need 5 yes's - wt, branch, repo, bound branch, bound repo.
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
95
        self.run_bzr('break-lock checkout', stdin="y\ny\ny\ny\n")
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
96
        # a new tree instance should be lockable
5356.1.1 by Vincent Ladeuil
Cleanup test imports.
97
        br = branch.Branch.open('checkout')
98
        br.lock_write()
99
        br.unlock()
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
100
        # and a new instance of the master branch
5356.1.1 by Vincent Ladeuil
Cleanup test imports.
101
        mb = br.get_master_branch()
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
102
        mb.lock_write()
103
        mb.unlock()
104
        self.assertRaises(errors.LockBroken, self.wt.unlock)
105
        self.assertRaises(errors.LockBroken, self.master_branch.unlock)
1687.1.16 by Robert Collins
Ensure that answering no to break lock leaves the locks in place. This is currently simple - ask for everything always.
106
1687.1.17 by Robert Collins
Test break lock on old format branches.
107
5345.5.9 by Vincent Ladeuil
Implements 'bzr lock --config <file>'.
108
class TestConfigBreakLock(tests.TestCaseWithTransport):
109
110
    def setUp(self):
111
        super(TestConfigBreakLock, self).setUp()
112
        self.config_file_name = './my.conf'
113
        self.build_tree_contents([(self.config_file_name,
114
                                   '[DEFAULT]\none=1\n')])
115
        self.config = config.LockableConfig(file_name=self.config_file_name)
116
        self.config.lock_write()
117
118
    def test_create_pending_lock(self):
119
        self.addCleanup(self.config.unlock)
120
        self.assertTrue(self.config._lock.is_held)
121
122
    def test_break_lock(self):
123
        self.run_bzr('break-lock --config %s'
124
                     % osutils.dirname(self.config_file_name),
125
                     stdin="y\n")
126
        self.assertRaises(errors.LockBroken, self.config.unlock)
127
6283.1.2 by Jelmer Vernooij
Add hpss call count for break-lock.
128
129
class TestSmartServerBreakLock(tests.TestCaseWithTransport):
130
131
    def test_simple_branch_break_lock(self):
132
        self.setup_smart_server_with_call_log()
133
        t = self.make_branch_and_tree('branch')
134
        t.branch.lock_write()
135
        self.reset_smart_call_log()
136
        out, err = self.run_bzr(['break-lock', '--force', self.get_url('branch')])
137
        # This figure represent the amount of work to perform this use case. It
138
        # is entirely ok to reduce this number if a test fails due to rpc_count
139
        # being too low. If rpc_count increases, more network roundtrips have
140
        # become necessary for this use case. Please do not adjust this number
141
        # upwards without agreement from bzr's network support maintainers.
6352.2.2 by Jelmer Vernooij
Use new NoVfsCalls matcher in blackbox tests.
142
        self.assertThat(self.hpss_calls, NoVfsCalls)
6280.4.8 by Jelmer Vernooij
Merge bzr.dev, fix hpss call count for 'bzr break-lock'.
143
        self.assertLength(5, self.hpss_calls)