/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/branch_implementations/test_create_clone.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-02-26 03:15:58 UTC
  • mfrom: (4050.1.3 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20090226031558-1ubr618vdn4r5f07
(robertc) Fix race condition with branch hooks during cloning when
        the new branch is stacked. (Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Tests for branch.create_clone behaviour."""
18
18
 
 
19
from bzrlib.branch import Branch
19
20
from bzrlib.tests.branch_implementations.test_branch import TestCaseWithBranch
 
21
from bzrlib import remote
20
22
 
21
23
 
22
24
class TestCreateClone(TestCaseWithBranch):
54
56
            stacked_on=trunk.base)
55
57
        self.assertEqual(revid, result.last_revision())
56
58
        self.assertEqual(trunk.base, result.get_stacked_on_url())
 
59
 
 
60
    def assertBranchHookBranchIsStacked(self, pre_change_params):
 
61
        # Just calling will either succeed or fail.
 
62
        pre_change_params.branch.get_stacked_on_url()
 
63
        self.hook_calls.append(pre_change_params)
 
64
 
 
65
    def test_create_clone_on_transport_stacked_hooks_get_stacked_branch(self):
 
66
        tree = self.make_branch_and_tree('source')
 
67
        tree.commit('a commit')
 
68
        trunk = tree.branch.create_clone_on_transport(
 
69
            self.get_transport('trunk'))
 
70
        revid = tree.commit('a second commit')
 
71
        source = tree.branch
 
72
        target_transport = self.get_transport('target')
 
73
        self.hook_calls = []
 
74
        Branch.hooks.install_named_hook("pre_change_branch_tip",
 
75
            self.assertBranchHookBranchIsStacked, None)
 
76
        result = tree.branch.create_clone_on_transport(target_transport,
 
77
            stacked_on=trunk.base)
 
78
        self.assertEqual(revid, result.last_revision())
 
79
        self.assertEqual(trunk.base, result.get_stacked_on_url())
 
80
        # Smart servers invoke hooks on both sides
 
81
        if isinstance(result, remote.RemoteBranch):
 
82
            expected_calls = 2
 
83
        else:
 
84
            expected_calls = 1
 
85
        self.assertEqual(expected_calls, len(self.hook_calls))