~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Robert Collins
  • Date: 2007-03-08 04:06:06 UTC
  • mfrom: (2323.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 2442.
  • Revision ID: robertc@robertcollins.net-20070308040606-84gsniv56huiyjt4
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Copyright (C) 2006 Canonical Ltd
2
 
 
 
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
7
 
 
 
7
#
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
11
# GNU General Public License for more details.
12
 
 
 
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
19
import os
20
20
 
21
21
import bzrlib
22
 
import bzrlib.errors as errors
 
22
from bzrlib import (
 
23
    errors,
 
24
    lockdir,
 
25
    )
23
26
from bzrlib.branch import Branch
24
27
from bzrlib.bzrdir import BzrDir
25
28
from bzrlib.tests.blackbox import ExternalBase
67
70
 
68
71
    def test_break_lock_everything_locked(self):
69
72
        ### if everything is locked, we should be able to unlock the lot.
 
73
        # however, we dont test breaking the working tree because we 
 
74
        # cannot accurately do so right now: the dirstate lock is held 
 
75
        # by an os lock, and we need to spawn a separate process to lock it
 
76
        # thne kill -9 it.
70
77
        # sketch of test:
71
 
        # lock the lot:
72
 
        self.wt.lock_write()
 
78
        # lock most of the dir:
 
79
        self.wt.branch.lock_write()
73
80
        self.master_branch.lock_write()
74
81
        # run the break-lock
75
82
        # 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")
 
83
        self.run_bzr('break-lock', 'checkout', stdin="y\ny\ny\ny\n")
77
84
        # a new tree instance should be lockable
78
 
        wt = bzrlib.workingtree.WorkingTree.open('checkout')
79
 
        wt.lock_write()
80
 
        wt.unlock()
 
85
        branch = bzrlib.branch.Branch.open('checkout')
 
86
        branch.lock_write()
 
87
        branch.unlock()
81
88
        # and a new instance of the master branch 
82
 
        mb = wt.branch.get_master_branch()
 
89
        mb = branch.get_master_branch()
83
90
        mb.lock_write()
84
91
        mb.unlock()
85
92
        self.assertRaises(errors.LockBroken, self.wt.unlock)
86
93
        self.assertRaises(errors.LockBroken, self.master_branch.unlock)
87
94
 
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
95
 
106
96
class TestBreakLockOldBranch(ExternalBase):
107
97