/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1
# Copyright (C) 2011, 2016 Canonical Ltd
5050.70.1 by Martin Pool
Add failing test for bug 715000
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
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
21
from breezy import (
6015.24.5 by John Arbash Meinel
Bug #388269.
22
    tests,
6182.1.4 by Jelmer Vernooij
Determine proper relative paths in reference tests.
23
    urlutils,
6015.24.5 by John Arbash Meinel
Bug #388269.
24
    )
6670.4.14 by Jelmer Vernooij
Move remote to breezy.bzr.
25
from breezy.bzr import (
26
    remote,
27
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
28
from breezy.tests.per_repository import TestCaseWithRepository
5050.70.1 by Martin Pool
Add failing test for bug 715000
29
30
31
class TestGraph(TestCaseWithRepository):
32
33
    def test_get_known_graph_ancestry_stacked(self):
34
        """get_known_graph_ancestry works correctly on stacking.
35
36
        See <https://bugs.launchpad.net/bugs/715000>.
37
        """
38
        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
39
        for br in [branch_a, branch_b, branch_c]:
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
40
            self.assertEqual(
5050.70.1 by Martin Pool
Add failing test for bug 715000
41
                [revid_1],
42
                br.repository.get_known_graph_ancestry([revid_1]).topo_sort())
43
44
    def make_double_stacked_branches(self):
45
        wt_a = self.make_branch_and_tree('a')
46
        branch_a = wt_a.branch
47
        branch_b = self.make_branch('b')
6182.1.4 by Jelmer Vernooij
Determine proper relative paths in reference tests.
48
        branch_b.set_stacked_on_url(
49
            urlutils.relative_url(branch_b.base, branch_a.base))
5050.70.1 by Martin Pool
Add failing test for bug 715000
50
        branch_c = self.make_branch('c')
6182.1.4 by Jelmer Vernooij
Determine proper relative paths in reference tests.
51
        branch_c.set_stacked_on_url(
52
            urlutils.relative_url(branch_c.base, branch_b.base))
5050.70.1 by Martin Pool
Add failing test for bug 715000
53
        revid_1 = wt_a.commit('first commit')
54
        return branch_a, branch_b, branch_c, revid_1
6015.24.5 by John Arbash Meinel
Bug #388269.
55
56
    def make_stacked_branch_with_long_history(self):
57
        builder = self.make_branch_builder('source')
58
        builder.start_series()
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
59
        builder.build_snapshot(None, [
7045.4.34 by Jelmer Vernooij
Fix some more tests.
60
            ('add', ('', b'root-id', 'directory', None))],
6973.5.2 by Jelmer Vernooij
Add more bees.
61
            revision_id=b'A')
6973.6.2 by Jelmer Vernooij
Fix more tests.
62
        builder.build_snapshot([b'A'], [], revision_id=b'B')
63
        builder.build_snapshot([b'B'], [], revision_id=b'C')
64
        builder.build_snapshot([b'C'], [], revision_id=b'D')
65
        builder.build_snapshot([b'D'], [], revision_id=b'E')
66
        builder.build_snapshot([b'E'], [], revision_id=b'F')
6015.24.5 by John Arbash Meinel
Bug #388269.
67
        source_b = builder.get_branch()
68
        master_b = self.make_branch('master')
6973.6.2 by Jelmer Vernooij
Fix more tests.
69
        master_b.pull(source_b, stop_revision=b'E')
6015.24.5 by John Arbash Meinel
Bug #388269.
70
        stacked_b = self.make_branch('stacked')
71
        stacked_b.set_stacked_on_url('../master')
6973.6.2 by Jelmer Vernooij
Fix more tests.
72
        stacked_b.pull(source_b, stop_revision=b'F')
6015.24.5 by John Arbash Meinel
Bug #388269.
73
        builder.finish_series()
74
        return master_b, stacked_b
75
6015.24.8 by John Arbash Meinel
Some cleanups suggested by Vincent.
76
    def assertParentMapCalls(self, expected):
77
        """Check that self.hpss_calls has the expected get_parent_map calls."""
78
        get_parent_map_calls = []
79
        for c in self.hpss_calls:
80
            # Right now, the only RPCs that get called are get_parent_map. If
81
            # this changes in the future, we can change this to:
82
            # if c.call.method != 'Repository.get_parent_map':
83
            #    continue
7067.13.1 by Jelmer Vernooij
Some more fixes for Python 3.
84
            self.assertEqual(b'Repository.get_parent_map', c.call.method)
6015.24.8 by John Arbash Meinel
Some cleanups suggested by Vincent.
85
            args = c.call.args
86
            location = args[0]
7067.13.1 by Jelmer Vernooij
Some more fixes for Python 3.
87
            self.assertEqual(b'include-missing:', args[1])
6015.24.8 by John Arbash Meinel
Some cleanups suggested by Vincent.
88
            revisions = sorted(args[2:])
89
            get_parent_map_calls.append((location, revisions))
90
        self.assertEqual(expected, get_parent_map_calls)
91
6015.24.5 by John Arbash Meinel
Bug #388269.
92
    def test_doesnt_call_get_parent_map_on_all_fallback_revs(self):
93
        if not isinstance(self.repository_format,
94
                          remote.RemoteRepositoryFormat):
95
            raise tests.TestNotApplicable('only for RemoteRepository')
96
        # bug #388269
97
        master_b, stacked_b = self.make_stacked_branch_with_long_history()
98
        self.addCleanup(stacked_b.lock_read().unlock)
99
        self.make_repository('target_repo', shared=True)
100
        target_b = self.make_branch('target_repo/branch')
6015.24.6 by John Arbash Meinel
A test that exposes exactly what we wanted.
101
        self.addCleanup(target_b.lock_write().unlock)
102
        self.setup_smart_server_with_call_log()
103
        res = target_b.repository.search_missing_revision_ids(
7143.15.2 by Jelmer Vernooij
Run autopep8.
104
            stacked_b.repository, revision_ids=[b'F'],
105
            find_ghosts=False)
6015.24.8 by John Arbash Meinel
Some cleanups suggested by Vincent.
106
        self.assertParentMapCalls([
6015.24.6 by John Arbash Meinel
A test that exposes exactly what we wanted.
107
            # One call to stacked to start, which returns F=>E, and that E
108
            # itself is missing, so when we step, we won't look for it.
7067.13.1 by Jelmer Vernooij
Some more fixes for Python 3.
109
            (b'extra/stacked/', [b'F']),
6015.24.6 by John Arbash Meinel
A test that exposes exactly what we wanted.
110
            # One fallback call to extra/master, which will return the rest of
111
            # the history.
7067.13.1 by Jelmer Vernooij
Some more fixes for Python 3.
112
            (b'extra/master/', [b'E']),
6015.24.6 by John Arbash Meinel
A test that exposes exactly what we wanted.
113
            # And then one get_parent_map call to the target, to see if it
114
            # already has any of these revisions.
7143.15.2 by Jelmer Vernooij
Run autopep8.
115
            (b'extra/target_repo/branch/',
116
             [b'A', b'B', b'C', b'D', b'E', b'F']),
6015.24.8 by John Arbash Meinel
Some cleanups suggested by Vincent.
117
            ])
6015.24.6 by John Arbash Meinel
A test that exposes exactly what we wanted.
118
        # Before bug #388269 was fixed, there would be a bunch of extra calls
119
        # to 'extra/stacked', ['D'] then ['C'], then ['B'], then ['A'].
120
        # One-at-a-time for the rest of the ancestry.