~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Vincent Ladeuil
  • Date: 2012-01-18 14:09:19 UTC
  • mto: This revision was merged to the branch mainline in revision 6468.
  • Revision ID: v.ladeuil+lp@free.fr-20120118140919-rlvdrhpc0nq1lbwi
Change set/remove to require a lock for the branch config files.

This means that tests (or any plugin for that matter) do not requires an
explicit lock on the branch anymore to change a single option. This also
means the optimisation becomes "opt-in" and as such won't be as
spectacular as it may be and/or harder to get right (nothing fails
anymore).

This reduces the diff by ~300 lines.

Code/tests that were updating more than one config option is still taking
a lock to at least avoid some IOs and demonstrate the benefits through
the decreased number of hpss calls.

The duplication between BranchStack and BranchOnlyStack will be removed
once the same sharing is in place for local config files, at which point
the Stack class itself may be able to host the changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
from bzrlib import (
21
21
    bzrdir,
22
22
    )
23
 
from bzrlib.tests.blackbox import (
24
 
    ExternalBase,
 
23
from bzrlib.tests import (
 
24
    TestCaseWithTransport,
25
25
    )
26
 
 
27
 
 
28
 
class TestRemoveBranch(ExternalBase):
29
 
 
30
 
    def example_branch(self, path='.'):
31
 
        tree = self.make_branch_and_tree(path)
 
26
from bzrlib.tests.matchers import ContainsNoVfsCalls
 
27
 
 
28
 
 
29
class TestRemoveBranch(TestCaseWithTransport):
 
30
 
 
31
    def example_branch(self, path='.', format=None):
 
32
        tree = self.make_branch_and_tree(path, format=format)
32
33
        self.build_tree_contents([(path + '/hello', 'foo')])
33
34
        tree.add('hello')
34
35
        tree.commit(message='setup')
35
36
        self.build_tree_contents([(path + '/goodbye', 'baz')])
36
37
        tree.add('goodbye')
37
38
        tree.commit(message='setup')
 
39
        return tree
38
40
 
39
41
    def test_remove_local(self):
40
42
        # Remove a local branch.
42
44
        self.run_bzr('rmbranch a')
43
45
        dir = bzrdir.BzrDir.open('a')
44
46
        self.assertFalse(dir.has_branch())
45
 
        self.failUnlessExists('a/hello')
46
 
        self.failUnlessExists('a/goodbye')
 
47
        self.assertPathExists('a/hello')
 
48
        self.assertPathExists('a/goodbye')
47
49
 
48
50
    def test_no_branch(self):
49
51
        # No branch in the current directory. 
57
59
        self.run_bzr('rmbranch', working_dir='a')
58
60
        dir = bzrdir.BzrDir.open('a')
59
61
        self.assertFalse(dir.has_branch())
 
62
 
 
63
    def test_remove_colo(self):
 
64
        # Remove a colocated branch.
 
65
        tree = self.example_branch('a', format='development-colo')
 
66
        tree.bzrdir.create_branch(name="otherbranch")
 
67
        self.assertTrue(tree.bzrdir.has_branch('otherbranch'))
 
68
        self.run_bzr('rmbranch %s,branch=otherbranch' % tree.bzrdir.user_url)
 
69
        dir = bzrdir.BzrDir.open('a')
 
70
        self.assertFalse(dir.has_branch('otherbranch'))
 
71
        self.assertTrue(dir.has_branch())
 
72
 
 
73
 
 
74
class TestSmartServerRemoveBranch(TestCaseWithTransport):
 
75
 
 
76
    def test_simple_remove_branch(self):
 
77
        self.setup_smart_server_with_call_log()
 
78
        self.make_branch('branch')
 
79
        self.reset_smart_call_log()
 
80
        out, err = self.run_bzr(['rmbranch', self.get_url('branch')])
 
81
        # This figure represent the amount of work to perform this use case. It
 
82
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
83
        # being too low. If rpc_count increases, more network roundtrips have
 
84
        # become necessary for this use case. Please do not adjust this number
 
85
        # upwards without agreement from bzr's network support maintainers.
 
86
        self.assertLength(5, self.hpss_calls)
 
87
        self.assertLength(1, self.hpss_connections)
 
88
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)