/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_push.py

  • Committer: Andrew Bennetts
  • Date: 2009-02-24 06:02:51 UTC
  • mto: This revision was merged to the branch mainline in revision 4043.
  • Revision ID: andrew.bennetts@canonical.com-20090224060251-25g4k13lh1sekza6
Fix unnecessary get_parent_map calls after insert_stream during push.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
    debug,
27
27
    errors,
28
28
    push,
 
29
    repository,
29
30
    tests,
30
31
    )
31
32
from bzrlib.branch import Branch
33
34
from bzrlib.memorytree import MemoryTree
34
35
from bzrlib.revision import NULL_REVISION
35
36
from bzrlib.smart import client, server
 
37
from bzrlib.smart.repository import SmartServerRepositoryGetParentMap
36
38
from bzrlib.tests.branch_implementations.test_branch import TestCaseWithBranch
37
39
from bzrlib.transport import get_transport
38
40
from bzrlib.transport.local import LocalURLServer
224
226
        trunk.push(remote_branch)
225
227
        remote_branch.check()
226
228
 
 
229
    def test_no_get_parent_map_after_insert_stream(self):
 
230
        # Effort test for bug 331823
 
231
        self.setup_smart_server_with_call_log()
 
232
        # Make a local branch with four revisions.  Four revisions because:
 
233
        # one to push, one there for _walk_to_common_revisions to find, one we
 
234
        # don't want to access, one for luck :)
 
235
        try:
 
236
            builder = self.make_branch_builder('local')
 
237
        except (errors.TransportNotPossible, errors.UninitializableFormat):
 
238
            raise tests.TestNotApplicable('format not directly constructable')
 
239
        builder.start_series()
 
240
        builder.build_snapshot('first', None, [
 
241
            ('add', ('', 'root-id', 'directory', ''))])
 
242
        builder.build_snapshot('second', ['first'], [])
 
243
        builder.build_snapshot('third', ['second'], [])
 
244
        builder.build_snapshot('fourth', ['third'], [])
 
245
        builder.finish_series()
 
246
        local = builder.get_branch()
 
247
        local = branch.Branch.open(self.get_vfs_only_url('local'))
 
248
        # Initial push of three revisions
 
249
        remote_bzrdir = local.bzrdir.sprout(
 
250
            self.get_url('remote'), revision_id='third')
 
251
        remote = remote_bzrdir.open_branch()
 
252
        # Push fourth revision
 
253
        self.reset_smart_call_log()
 
254
        self.disableOptimisticGetParentMap()
 
255
        self.assertFalse(local.is_locked())
 
256
        local.push(remote)
 
257
        hpss_call_names = [item[0].method for item in self.hpss_calls]
 
258
        self.assertTrue('Repository.insert_stream' in hpss_call_names)
 
259
        insert_stream_idx = hpss_call_names.index('Repository.insert_stream')
 
260
        calls_after_insert_stream = hpss_call_names[insert_stream_idx:]
 
261
        # After inserting the stream the client has no reason to query the
 
262
        # remote graph any further.
 
263
        self.assertEqual(
 
264
            ['Repository.insert_stream', 'Repository.insert_stream', 'get',
 
265
             'delete', 'Branch.set_last_revision_info', 'Branch.unlock'],
 
266
            calls_after_insert_stream)
 
267
 
 
268
    def disableOptimisticGetParentMap(self):
 
269
        # Tweak some class variables to stop remote get_parent_map calls asking
 
270
        # for or receiving more data than the caller asked for.
 
271
        old_flag = SmartServerRepositoryGetParentMap.no_extra_results
 
272
        inter_classes = [repository.InterOtherToRemote,
 
273
            repository.InterPackToRemotePack]
 
274
        old_batch_sizes = []
 
275
        for inter_class in inter_classes:
 
276
            old_batch_sizes.append(
 
277
                inter_class._walk_to_common_revisions_batch_size)
 
278
            inter_class._walk_to_common_revisions_batch_size = 1
 
279
        SmartServerRepositoryGetParentMap.no_extra_results = True
 
280
        def reset_values():
 
281
            SmartServerRepositoryGetParentMap.no_extra_results = old_flag
 
282
            for inter_class, size in zip(inter_classes, old_batch_sizes):
 
283
                inter_class._walk_to_common_revisions_batch_size = size
 
284
        self.addCleanup(reset_values)
 
285
 
227
286
 
228
287
class TestPushHook(TestCaseWithBranch):
229
288