~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-07 08:02:58 UTC
  • mfrom: (2255.2.239 dirstate)
  • mto: This revision was merged to the branch mainline in revision 2322.
  • Revision ID: robertc@robertcollins.net-20070307080258-fi172acyjga89fz5
(robertc) Merge dirstate and subtrees. (Robert Collins, Martin Pool, Aaaron Bentley, John A Meinel, James Westby)

Show diffs side-by-side

added added

removed removed

Lines of Context:
70
70
 
71
71
    def test_break_lock_everything_locked(self):
72
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.
73
77
        # sketch of test:
74
 
        # lock the lot:
75
 
        self.wt.lock_write()
 
78
        # lock most of the dir:
 
79
        self.wt.branch.lock_write()
76
80
        self.master_branch.lock_write()
77
81
        # run the break-lock
78
82
        # 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")
 
83
        self.run_bzr('break-lock', 'checkout', stdin="y\ny\ny\ny\n")
80
84
        # a new tree instance should be lockable
81
 
        wt = bzrlib.workingtree.WorkingTree.open('checkout')
82
 
        wt.lock_write()
83
 
        wt.unlock()
 
85
        branch = bzrlib.branch.Branch.open('checkout')
 
86
        branch.lock_write()
 
87
        branch.unlock()
84
88
        # and a new instance of the master branch 
85
 
        mb = wt.branch.get_master_branch()
 
89
        mb = branch.get_master_branch()
86
90
        mb.lock_write()
87
91
        mb.unlock()
88
92
        self.assertRaises(errors.LockBroken, self.wt.unlock)
89
93
        self.assertRaises(errors.LockBroken, self.master_branch.unlock)
90
94
 
91
 
    def test_saying_no_leaves_it_locked(self):
92
 
        ### if 'no' is answered, objects should remain locked.
93
 
        self.wt.lock_write()
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")
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()
122
95
 
123
96
class TestBreakLockOldBranch(ExternalBase):
124
97