~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_branch/test_push.py

  • Committer: Danny van Heumen
  • Date: 2010-03-09 21:42:11 UTC
  • mto: (4634.139.5 2.0)
  • mto: This revision was merged to the branch mainline in revision 5160.
  • Revision ID: danny@dannyvanheumen.nl-20100309214211-iqh42x6qcikgd9p3
Reverted now-useless TODO list.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2010 Canonical Ltd
 
1
# Copyright (C) 2004, 2005, 2007 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
26
26
    check,
27
27
    debug,
28
28
    errors,
29
 
    memorytree,
30
29
    push,
31
30
    repository,
32
 
    revision,
33
31
    tests,
34
 
    transport,
35
 
    )
36
 
from bzrlib.smart import (
37
 
    client,
38
 
    server,
39
 
    repository as _mod_smart_repo,
40
 
    )
41
 
from bzrlib.tests import (
42
 
    per_branch,
43
 
    test_server,
44
 
    )
45
 
 
46
 
 
47
 
class TestPush(per_branch.TestCaseWithBranch):
 
32
    )
 
33
from bzrlib.branch import Branch
 
34
from bzrlib.bzrdir import BzrDir
 
35
from bzrlib.memorytree import MemoryTree
 
36
from bzrlib.revision import NULL_REVISION
 
37
from bzrlib.smart import client, server
 
38
from bzrlib.smart.repository import SmartServerRepositoryGetParentMap
 
39
from bzrlib.tests.per_branch.test_branch import TestCaseWithBranch
 
40
from bzrlib.transport import get_transport
 
41
from bzrlib.transport.local import LocalURLServer
 
42
 
 
43
 
 
44
class TestPush(TestCaseWithBranch):
48
45
 
49
46
    def test_push_convergence_simple(self):
50
47
        # when revisions are pushed, the left-most accessible parents must
151
148
        try:
152
149
            tree = a_branch.bzrdir.create_workingtree()
153
150
        except errors.NotLocalUrl:
154
 
            if self.vfs_transport_factory is test_server.LocalURLServer:
 
151
            if self.vfs_transport_factory is LocalURLServer:
155
152
                # the branch is colocated on disk, we cannot create a checkout.
156
153
                # hopefully callers will expect this.
157
 
                local_controldir= bzrdir.BzrDir.open(
158
 
                    self.get_vfs_only_url('repo/tree'))
 
154
                local_controldir= bzrdir.BzrDir.open(self.get_vfs_only_url('repo/tree'))
159
155
                tree = local_controldir.create_workingtree()
160
156
            else:
161
157
                tree = a_branch.create_checkout('repo/tree', lightweight=True)
227
223
        push._show_push_branch(trunk, 'rev-2', self.get_url('remote'), output)
228
224
        # Push rev-3 onto "remote".  If "remote" not stacked and is missing the
229
225
        # fulltext record for f-id @ rev-1, then this will fail.
230
 
        remote_branch = branch.Branch.open(self.get_url('remote'))
 
226
        remote_branch = Branch.open(self.get_url('remote'))
231
227
        trunk.push(remote_branch)
232
228
        check.check_dwim(remote_branch.base, False, True, True)
233
229
 
234
 
 
235
 
class TestPushHook(per_branch.TestCaseWithBranch):
 
230
    def test_no_get_parent_map_after_insert_stream(self):
 
231
        # Effort test for bug 331823
 
232
        self.setup_smart_server_with_call_log()
 
233
        # Make a local branch with four revisions.  Four revisions because:
 
234
        # one to push, one there for _walk_to_common_revisions to find, one we
 
235
        # don't want to access, one for luck :)
 
236
        if isinstance(self.branch_format, branch.BranchReferenceFormat):
 
237
            # This test could in principle apply to BranchReferenceFormat, but
 
238
            # make_branch_builder doesn't support it.
 
239
            raise tests.TestSkipped(
 
240
                "BranchBuilder can't make reference branches.")
 
241
        try:
 
242
            builder = self.make_branch_builder('local')
 
243
        except (errors.TransportNotPossible, errors.UninitializableFormat):
 
244
            raise tests.TestNotApplicable('format not directly constructable')
 
245
        builder.start_series()
 
246
        builder.build_snapshot('first', None, [
 
247
            ('add', ('', 'root-id', 'directory', ''))])
 
248
        builder.build_snapshot('second', ['first'], [])
 
249
        builder.build_snapshot('third', ['second'], [])
 
250
        builder.build_snapshot('fourth', ['third'], [])
 
251
        builder.finish_series()
 
252
        local = builder.get_branch()
 
253
        local = branch.Branch.open(self.get_vfs_only_url('local'))
 
254
        # Initial push of three revisions
 
255
        remote_bzrdir = local.bzrdir.sprout(
 
256
            self.get_url('remote'), revision_id='third')
 
257
        remote = remote_bzrdir.open_branch()
 
258
        # Push fourth revision
 
259
        self.reset_smart_call_log()
 
260
        self.disableOptimisticGetParentMap()
 
261
        self.assertFalse(local.is_locked())
 
262
        local.push(remote)
 
263
        hpss_call_names = [item.call.method for item in self.hpss_calls]
 
264
        self.assertTrue('Repository.insert_stream_1.19' in hpss_call_names)
 
265
        insert_stream_idx = hpss_call_names.index(
 
266
            'Repository.insert_stream_1.19')
 
267
        calls_after_insert_stream = hpss_call_names[insert_stream_idx:]
 
268
        # After inserting the stream the client has no reason to query the
 
269
        # remote graph any further.
 
270
        self.assertEqual(
 
271
            ['Repository.insert_stream_1.19', 'Repository.insert_stream_1.19',
 
272
             'get', 'Branch.set_last_revision_info', 'Branch.unlock'],
 
273
            calls_after_insert_stream)
 
274
 
 
275
    def disableOptimisticGetParentMap(self):
 
276
        # Tweak some class variables to stop remote get_parent_map calls asking
 
277
        # for or receiving more data than the caller asked for.
 
278
        old_flag = SmartServerRepositoryGetParentMap.no_extra_results
 
279
        inter_class = repository.InterRepository
 
280
        old_batch_size = inter_class._walk_to_common_revisions_batch_size
 
281
        inter_class._walk_to_common_revisions_batch_size = 1
 
282
        SmartServerRepositoryGetParentMap.no_extra_results = True
 
283
        def reset_values():
 
284
            SmartServerRepositoryGetParentMap.no_extra_results = old_flag
 
285
            inter_class._walk_to_common_revisions_batch_size = old_batch_size
 
286
        self.addCleanup(reset_values)
 
287
 
 
288
 
 
289
class TestPushHook(TestCaseWithBranch):
236
290
 
237
291
    def setUp(self):
238
292
        self.hook_calls = []
239
 
        super(TestPushHook, self).setUp()
 
293
        TestCaseWithBranch.setUp(self)
240
294
 
241
295
    def capture_post_push_hook(self, result):
242
296
        """Capture post push hook calls to self.hook_calls.
260
314
    def test_post_push_empty_history(self):
261
315
        target = self.make_branch('target')
262
316
        source = self.make_branch('source')
263
 
        branch.Branch.hooks.install_named_hook(
264
 
            'post_push', self.capture_post_push_hook, None)
 
317
        Branch.hooks.install_named_hook('post_push',
 
318
                                        self.capture_post_push_hook, None)
265
319
        source.push(target)
266
320
        # with nothing there we should still get a notification, and
267
321
        # have both branches locked at the notification time.
268
322
        self.assertEqual([
269
 
            ('post_push', source, None, target.base, 0, revision.NULL_REVISION,
270
 
             0, revision.NULL_REVISION, True, None, True)
 
323
            ('post_push', source, None, target.base, 0, NULL_REVISION,
 
324
             0, NULL_REVISION, True, None, True)
271
325
            ],
272
326
            self.hook_calls)
273
327
 
286
340
            # remotebranches can't be bound.  Let's instead make a new local
287
341
            # branch of the default type, which does allow binding.
288
342
            # See https://bugs.launchpad.net/bzr/+bug/112020
289
 
            local = bzrdir.BzrDir.create_branch_convenience('local2')
 
343
            local = BzrDir.create_branch_convenience('local2')
290
344
            local.bind(target)
291
345
        source = self.make_branch('source')
292
 
        branch.Branch.hooks.install_named_hook(
293
 
            'post_push', self.capture_post_push_hook, None)
 
346
        Branch.hooks.install_named_hook('post_push',
 
347
                                        self.capture_post_push_hook, None)
294
348
        source.push(local)
295
349
        # with nothing there we should still get a notification, and
296
350
        # have both branches locked at the notification time.
297
351
        self.assertEqual([
298
 
            ('post_push', source, local.base, target.base, 0,
299
 
             revision.NULL_REVISION, 0, revision.NULL_REVISION,
300
 
             True, True, True)
 
352
            ('post_push', source, local.base, target.base, 0, NULL_REVISION,
 
353
             0, NULL_REVISION, True, True, True)
301
354
            ],
302
355
            self.hook_calls)
303
356
 
308
361
        rev1 = target.commit('rev 1')
309
362
        target.unlock()
310
363
        sourcedir = target.bzrdir.clone(self.get_url('source'))
311
 
        source = memorytree.MemoryTree.create_on_branch(sourcedir.open_branch())
 
364
        source = MemoryTree.create_on_branch(sourcedir.open_branch())
312
365
        rev2 = source.commit('rev 2')
313
 
        branch.Branch.hooks.install_named_hook(
314
 
            'post_push', self.capture_post_push_hook, None)
 
366
        Branch.hooks.install_named_hook('post_push',
 
367
                                        self.capture_post_push_hook, None)
315
368
        source.branch.push(target.branch)
316
369
        # with nothing there we should still get a notification, and
317
370
        # have both branches locked at the notification time.
322
375
            self.hook_calls)
323
376
 
324
377
 
325
 
class EmptyPushSmartEffortTests(per_branch.TestCaseWithBranch):
 
378
class EmptyPushSmartEffortTests(TestCaseWithBranch):
326
379
    """Tests that a push of 0 revisions should make a limited number of smart
327
380
    protocol RPCs.
328
381
    """
329
382
 
330
383
    def setUp(self):
331
384
        # Skip some scenarios that don't apply to these tests.
332
 
        if (self.transport_server is not None
333
 
            and issubclass(self.transport_server,
334
 
                           test_server.SmartTCPServer_for_testing)):
 
385
        if (self.transport_server is not None and
 
386
            issubclass(self.transport_server, server.SmartTCPServer)):
335
387
            raise tests.TestNotApplicable(
336
388
                'Does not apply when remote backing branch is also '
337
389
                'a smart branch')
341
393
        super(EmptyPushSmartEffortTests, self).setUp()
342
394
        # Create a smart server that publishes whatever the backing VFS server
343
395
        # does.
344
 
        self.smart_server = test_server.SmartTCPServer_for_testing()
345
 
        self.start_server(self.smart_server, self.get_server())
 
396
        self.smart_server = server.SmartTCPServer_for_testing()
 
397
        self.smart_server.setUp(self.get_server())
 
398
        self.addCleanup(self.smart_server.tearDown)
346
399
        # Make two empty branches, 'empty' and 'target'.
347
400
        self.empty_branch = self.make_branch('empty')
348
401
        self.make_branch('target')
357
410
    def test_empty_branch_api(self):
358
411
        """The branch_obj.push API should make a limited number of HPSS calls.
359
412
        """
360
 
        t = transport.get_transport(self.smart_server.get_url()).clone('target')
361
 
        target = branch.Branch.open_from_transport(t)
 
413
        transport = get_transport(self.smart_server.get_url()).clone('target')
 
414
        target = Branch.open_from_transport(transport)
362
415
        self.empty_branch.push(target)
363
416
        self.assertEqual(
364
 
            ['BzrDir.open_2.1',
365
 
             'BzrDir.open_branchV3',
 
417
            ['BzrDir.open',
 
418
             'BzrDir.open_branchV2',
366
419
             'BzrDir.find_repositoryV3',
367
420
             'Branch.get_stacked_on_url',
368
421
             'Branch.lock_write',
385
438
        self.assertTrue(len(self.hpss_calls) <= 9, self.hpss_calls)
386
439
 
387
440
 
388
 
class TestLossyPush(per_branch.TestCaseWithBranch):
 
441
class TestLossyPush(TestCaseWithBranch):
389
442
 
390
443
    def setUp(self):
391
444
        self.hook_calls = []
392
 
        super(TestLossyPush, self).setUp()
 
445
        TestCaseWithBranch.setUp(self)
393
446
 
394
447
    def test_lossy_push_raises_same_vcs(self):
395
448
        target = self.make_branch('target')