/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5050.70.1 by Martin Pool
Add failing test for bug 715000
1
# Copyright (C) 2011 Canonical Ltd
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
17
18
"""Tests for graph operations on stacked repositories."""
19
20
6015.24.5 by John Arbash Meinel
Bug #388269.
21
from bzrlib import (
22
    remote,
6015.24.6 by John Arbash Meinel
A test that exposes exactly what we wanted.
23
    repository,
6015.24.5 by John Arbash Meinel
Bug #388269.
24
    tests,
25
    )
5050.70.1 by Martin Pool
Add failing test for bug 715000
26
from bzrlib.tests.per_repository import TestCaseWithRepository
27
28
29
class TestGraph(TestCaseWithRepository):
30
31
    def test_get_known_graph_ancestry_stacked(self):
32
        """get_known_graph_ancestry works correctly on stacking.
33
34
        See <https://bugs.launchpad.net/bugs/715000>.
35
        """
36
        branch_a, branch_b, branch_c, revid_1 = self.make_double_stacked_branches()
5652.2.3 by Martin Pool
More assertions about the fix for bug 715000
37
        for br in [branch_a, branch_b, branch_c]:
5050.70.1 by Martin Pool
Add failing test for bug 715000
38
            self.assertEquals(
39
                [revid_1],
40
                br.repository.get_known_graph_ancestry([revid_1]).topo_sort())
41
42
    def make_double_stacked_branches(self):
43
        wt_a = self.make_branch_and_tree('a')
44
        branch_a = wt_a.branch
45
        branch_b = self.make_branch('b')
46
        branch_b.set_stacked_on_url('../a')
47
        branch_c = self.make_branch('c')
48
        branch_c.set_stacked_on_url('../b')
49
        revid_1 = wt_a.commit('first commit')
50
        return branch_a, branch_b, branch_c, revid_1
6015.24.5 by John Arbash Meinel
Bug #388269.
51
52
    def make_stacked_branch_with_long_history(self):
53
        builder = self.make_branch_builder('source')
54
        builder.start_series()
55
        builder.build_snapshot('A', None, [
56
            ('add', ('', 'directory', 'root-id', None))])
57
        builder.build_snapshot('B', ['A'], [])
58
        builder.build_snapshot('C', ['B'], [])
59
        builder.build_snapshot('D', ['C'], [])
60
        builder.build_snapshot('E', ['D'], [])
61
        builder.build_snapshot('F', ['E'], [])
62
        source_b = builder.get_branch()
63
        master_b = self.make_branch('master')
64
        master_b.pull(source_b, stop_revision='E')
65
        stacked_b = self.make_branch('stacked')
66
        stacked_b.set_stacked_on_url('../master')
67
        stacked_b.pull(source_b, stop_revision='F')
68
        builder.finish_series()
69
        return master_b, stacked_b
70
6015.24.8 by John Arbash Meinel
Some cleanups suggested by Vincent.
71
    def assertParentMapCalls(self, expected):
72
        """Check that self.hpss_calls has the expected get_parent_map calls."""
73
        get_parent_map_calls = []
74
        for c in self.hpss_calls:
75
            # Right now, the only RPCs that get called are get_parent_map. If
76
            # this changes in the future, we can change this to:
77
            # if c.call.method != 'Repository.get_parent_map':
78
            #    continue
79
            self.assertEqual('Repository.get_parent_map', c.call.method)
80
            args = c.call.args
81
            location = args[0]
82
            self.assertEqual('include-missing:', args[1])
83
            revisions = sorted(args[2:])
84
            get_parent_map_calls.append((location, revisions))
85
        self.assertEqual(expected, get_parent_map_calls)
86
6015.24.5 by John Arbash Meinel
Bug #388269.
87
    def test_doesnt_call_get_parent_map_on_all_fallback_revs(self):
88
        if not isinstance(self.repository_format,
89
                          remote.RemoteRepositoryFormat):
90
            raise tests.TestNotApplicable('only for RemoteRepository')
91
        # bug #388269
92
        master_b, stacked_b = self.make_stacked_branch_with_long_history()
93
        self.addCleanup(stacked_b.lock_read().unlock)
94
        self.make_repository('target_repo', shared=True)
95
        target_b = self.make_branch('target_repo/branch')
6015.24.6 by John Arbash Meinel
A test that exposes exactly what we wanted.
96
        self.addCleanup(target_b.lock_write().unlock)
97
        self.setup_smart_server_with_call_log()
98
        res = target_b.repository.search_missing_revision_ids(
99
                stacked_b.repository, revision_ids=['F'],
100
                find_ghosts=False)
6015.24.8 by John Arbash Meinel
Some cleanups suggested by Vincent.
101
        self.assertParentMapCalls([
6015.24.6 by John Arbash Meinel
A test that exposes exactly what we wanted.
102
            # One call to stacked to start, which returns F=>E, and that E
103
            # itself is missing, so when we step, we won't look for it.
104
            ('extra/stacked/', ['F']),
105
            # One fallback call to extra/master, which will return the rest of
106
            # the history.
107
            ('extra/master/', ['E']),
108
            # And then one get_parent_map call to the target, to see if it
109
            # already has any of these revisions.
110
            ('extra/target_repo/branch/', ['A', 'B', 'C', 'D', 'E', 'F']),
6015.24.8 by John Arbash Meinel
Some cleanups suggested by Vincent.
111
            ])
6015.24.6 by John Arbash Meinel
A test that exposes exactly what we wanted.
112
        # Before bug #388269 was fixed, there would be a bunch of extra calls
113
        # to 'extra/stacked', ['D'] then ['C'], then ['B'], then ['A'].
114
        # One-at-a-time for the rest of the ancestry.