1553.5.34
by Martin Pool
Stub lock-breaking command |
1 |
# Copyright (C) 2006 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
|
|
15 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
16 |
||
17 |
"""Tests for lock-breaking user interface"""
|
|
18 |
||
19 |
import os |
|
20 |
||
1687.1.12
by Robert Collins
Hook in the full break-lock ui. |
21 |
import bzrlib |
1957.1.17
by John Arbash Meinel
Change tests that expect locking to fail to timeout sooner. |
22 |
from bzrlib import ( |
23 |
errors, |
|
24 |
lockdir, |
|
25 |
)
|
|
1553.5.34
by Martin Pool
Stub lock-breaking command |
26 |
from bzrlib.branch import Branch |
1553.5.35
by Martin Pool
Start break-lock --show |
27 |
from bzrlib.bzrdir import BzrDir |
1687.1.1
by Robert Collins
Document what the break-lock commands should be like |
28 |
from bzrlib.tests.blackbox import ExternalBase |
29 |
||
30 |
||
31 |
class TestBreakLock(ExternalBase): |
|
32 |
||
33 |
# General principal for break-lock: All the elements that might be locked
|
|
34 |
# by a bzr operation on PATH, are candidates that break-lock may unlock.
|
|
35 |
# so pathologically if we have a lightweight checkout A, of branch B, which
|
|
36 |
# is bound to location C, the following things should be checked for locks
|
|
37 |
# to break:
|
|
38 |
# wt = WorkingTree(A)
|
|
39 |
# wt.branch
|
|
40 |
# wt.branch.repository
|
|
41 |
# wt.branch.get_master_branch()
|
|
42 |
# wt.branch.get_master_branch().repository
|
|
43 |
# so for smoke tests all we need is a bound branch with a checkout of that
|
|
44 |
# and we can then use different urls to test individual cases, for as much
|
|
45 |
# granularity as needed.
|
|
46 |
||
47 |
def setUp(self): |
|
48 |
super(TestBreakLock, self).setUp() |
|
49 |
self.build_tree( |
|
50 |
['master-repo/', |
|
51 |
'master-repo/master-branch/', |
|
52 |
'repo/', |
|
53 |
'repo/branch/', |
|
54 |
'checkout/']) |
|
55 |
bzrlib.bzrdir.BzrDir.create('master-repo').create_repository() |
|
1687.1.12
by Robert Collins
Hook in the full break-lock ui. |
56 |
self.master_branch = bzrlib.bzrdir.BzrDir.create_branch_convenience( |
1687.1.1
by Robert Collins
Document what the break-lock commands should be like |
57 |
'master-repo/master-branch') |
58 |
bzrlib.bzrdir.BzrDir.create('repo').create_repository() |
|
1687.1.12
by Robert Collins
Hook in the full break-lock ui. |
59 |
local_branch = bzrlib.bzrdir.BzrDir.create_branch_convenience('repo/branch') |
1687.1.1
by Robert Collins
Document what the break-lock commands should be like |
60 |
local_branch.bind(self.master_branch) |
61 |
checkoutdir = bzrlib.bzrdir.BzrDir.create('checkout') |
|
62 |
bzrlib.branch.BranchReferenceFormat().initialize( |
|
63 |
checkoutdir, local_branch) |
|
1687.1.12
by Robert Collins
Hook in the full break-lock ui. |
64 |
self.wt = checkoutdir.create_workingtree() |
1687.1.1
by Robert Collins
Document what the break-lock commands should be like |
65 |
|
1553.5.34
by Martin Pool
Stub lock-breaking command |
66 |
def test_break_lock_help(self): |
1687.1.1
by Robert Collins
Document what the break-lock commands should be like |
67 |
out, err = self.run_bzr('break-lock', '--help') |
68 |
# shouldn't fail and should not produce error output
|
|
69 |
self.assertEqual('', err) |
|
70 |
||
71 |
def test_break_lock_everything_locked(self): |
|
72 |
### if everything is locked, we should be able to unlock the lot.
|
|
73 |
# sketch of test:
|
|
74 |
# lock the lot:
|
|
75 |
self.wt.lock_write() |
|
76 |
self.master_branch.lock_write() |
|
77 |
# run the break-lock
|
|
1687.1.12
by Robert Collins
Hook in the full break-lock ui. |
78 |
# we need 5 yes's - wt, branch, repo, bound branch, bound repo.
|
79 |
self.run_bzr('break-lock', 'checkout', stdin="y\ny\ny\ny\ny\n") |
|
80 |
# a new tree instance should be lockable
|
|
81 |
wt = bzrlib.workingtree.WorkingTree.open('checkout') |
|
82 |
wt.lock_write() |
|
83 |
wt.unlock() |
|
84 |
# and a new instance of the master branch
|
|
85 |
mb = wt.branch.get_master_branch() |
|
86 |
mb.lock_write() |
|
87 |
mb.unlock() |
|
88 |
self.assertRaises(errors.LockBroken, self.wt.unlock) |
|
89 |
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. |
90 |
|
91 |
def test_saying_no_leaves_it_locked(self): |
|
92 |
### if 'no' is answered, objects should remain locked.
|
|
93 |
self.wt.lock_write() |
|
1957.1.17
by John Arbash Meinel
Change tests that expect locking to fail to timeout sooner. |
94 |
try: |
95 |
self.master_branch.lock_write() |
|
96 |
try: |
|
97 |
# run the break-lock
|
|
98 |
# we need 5 yes's - wt, branch, repo, bound branch, bound repo.
|
|
99 |
self.run_bzr('break-lock', 'checkout', stdin="n\nn\nn\nn\nn\n") |
|
1687.1.17
by Robert Collins
Test break lock on old format branches. |
100 |
|
1957.1.17
by John Arbash Meinel
Change tests that expect locking to fail to timeout sooner. |
101 |
# The default timeout to wait for LockContention is 5 minutes.
|
102 |
# we need to override this temporarily.
|
|
103 |
# TODO: jam 20060927 When we have per repository/branch/tree
|
|
104 |
# timeouts set the value of the repository,
|
|
105 |
# rather than setting the global default.
|
|
106 |
orig_default = lockdir._DEFAULT_TIMEOUT_SECONDS |
|
107 |
try: |
|
108 |
lockdir._DEFAULT_TIMEOUT_SECONDS = 1 |
|
109 |
# a new tree instance should not be lockable
|
|
110 |
wt = bzrlib.workingtree.WorkingTree.open('checkout') |
|
111 |
self.assertRaises(errors.LockContention, wt.lock_write) |
|
112 |
# and a new instance of the master branch
|
|
113 |
mb = wt.branch.get_master_branch() |
|
114 |
self.assertRaises(errors.LockContention, mb.lock_write) |
|
115 |
finally: |
|
116 |
lockdir._DEFAULT_TIMEOUT_SECONDS = orig_default |
|
117 |
# unlock our branches normally.
|
|
118 |
finally: |
|
119 |
self.master_branch.unlock() |
|
120 |
finally: |
|
121 |
self.wt.unlock() |
|
1687.1.17
by Robert Collins
Test break lock on old format branches. |
122 |
|
123 |
class TestBreakLockOldBranch(ExternalBase): |
|
124 |
||
125 |
def test_break_lock_format_5_bzrdir(self): |
|
126 |
# break lock on a format 5 bzrdir should just return
|
|
127 |
self.make_branch_and_tree('foo', format=bzrlib.bzrdir.BzrDirFormat5()) |
|
128 |
out, err = self.run_bzr('break-lock', 'foo') |
|
129 |
self.assertEqual('', out) |
|
130 |
self.assertEqual('', err) |