~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
88
91
    def test_saying_no_leaves_it_locked(self):
89
92
        ### if 'no' is answered, objects should remain locked.
90
93
        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()
 
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")
104
100
 
 
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()
105
122
 
106
123
class TestBreakLockOldBranch(ExternalBase):
107
124