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

Merge with stacked-fixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
from bzrlib.branch import Branch
29
29
from bzrlib.bzrdir import BzrDir
30
30
from bzrlib.repofmt import knitrepo
31
 
from bzrlib.symbol_versioning import (
32
 
    zero_ninetyone,
33
 
    )
34
31
from bzrlib.tests import TestCaseWithTransport
35
32
from bzrlib.tests.http_utils import TestCaseWithWebserver
36
33
from bzrlib.tests.test_revision import make_branches
285
282
        # unfortunately this log entry is branch format specific. We could 
286
283
        # factor out the 'what files does this format use' to a method on the 
287
284
        # repository, which would let us to this generically. RBC 20060419
 
285
        # RBC 20080408: Or perhaps we can assert that no files are fully read
 
286
        # twice?
288
287
        self.assertEqual(1, self._count_log_matches('/ce/id.kndx', http_logs))
289
288
        self.assertEqual(1, self._count_log_matches('/ce/id.knit', http_logs))
290
 
        self.assertEqual(1, self._count_log_matches('inventory.kndx', http_logs))
 
289
        # XXX: This *should* be '1', but more intrusive fetch changes are
 
290
        # needed to drop this back to 1.
 
291
        self.assertEqual(2, self._count_log_matches('inventory.kndx', http_logs))
291
292
        # this r-h check test will prevent regressions, but it currently already 
292
293
        # passes, before the patch to cache-rh is applied :[
293
294
        self.assertTrue(1 >= self._count_log_matches('revision-history',
296
297
                                                     http_logs))
297
298
        # FIXME naughty poking in there.
298
299
        self.get_readonly_server().logs = []
299
 
        # check there is nothing more to fetch
300
 
        source = Branch.open(self.get_readonly_url("source/"))
 
300
        # check there is nothing more to fetch.  We take care to re-use the
 
301
        # existing transport so that the request logs we're about to examine
 
302
        # aren't cluttered with redundant probes for a smart server.
 
303
        # XXX: Perhaps this further parameterisation: test http with smart
 
304
        # server, and test http without smart server?
 
305
        source = Branch.open(
 
306
            self.get_readonly_url("source/"),
 
307
            possible_transports=[source.bzrdir.root_transport])
301
308
        self.assertEqual(target.fetch(source), (0, []))
302
309
        # should make just two requests
303
310
        http_logs = self.get_readonly_server().logs
305
312
        self.log('\n'.join(http_logs))
306
313
        self.assertEqual(1, self._count_log_matches('branch-format', http_logs))
307
314
        self.assertEqual(1, self._count_log_matches('branch/format', http_logs))
308
 
        self.assertEqual(1, self._count_log_matches('repository/format', http_logs))
 
315
        self.assertEqual(1, self._count_log_matches('repository/format',
 
316
            http_logs))
309
317
        self.assertTrue(1 >= self._count_log_matches('revision-history',
310
318
                                                     http_logs))
311
319
        self.assertTrue(1 >= self._count_log_matches('last-revision',
312
320
                                                     http_logs))
313
321
        self.assertEqual(4, len(http_logs))
 
322
 
 
323
 
 
324
class Test1To2Fetch(TestCaseWithTransport):
 
325
    """Tests for Model1To2 failure modes"""
 
326
 
 
327
    def make_tree_and_repo(self):
 
328
        self.tree = self.make_branch_and_tree('tree', format='pack-0.92')
 
329
        self.repo = self.make_repository('rich-repo', format='rich-root-pack')
 
330
        self.repo.lock_write()
 
331
        self.addCleanup(self.repo.unlock)
 
332
 
 
333
    def do_fetch_order_test(self, first, second):
 
334
        """Test that fetch works no matter what the set order of revision is.
 
335
 
 
336
        This test depends on the order of items in a set, which is
 
337
        implementation-dependant, so we test A, B and then B, A.
 
338
        """
 
339
        self.make_tree_and_repo()
 
340
        self.tree.commit('Commit 1', rev_id=first)
 
341
        self.tree.commit('Commit 2', rev_id=second)
 
342
        self.repo.fetch(self.tree.branch.repository, second)
 
343
 
 
344
    def test_fetch_order_AB(self):
 
345
        """See do_fetch_order_test"""
 
346
        self.do_fetch_order_test('A', 'B')
 
347
 
 
348
    def test_fetch_order_BA(self):
 
349
        """See do_fetch_order_test"""
 
350
        self.do_fetch_order_test('B', 'A')
 
351
 
 
352
    def get_parents(self, file_id, revision_id):
 
353
        transaction = self.repo.get_transaction()
 
354
        vf = self.repo.weave_store.get_weave(file_id, transaction)
 
355
        return vf.get_parents_with_ghosts(revision_id)
 
356
 
 
357
    def test_fetch_ghosts(self):
 
358
        self.make_tree_and_repo()
 
359
        self.tree.commit('first commit', rev_id='left-parent')
 
360
        self.tree.add_parent_tree_id('ghost-parent')
 
361
        fork = self.tree.bzrdir.sprout('fork', 'null:').open_workingtree()
 
362
        fork.commit('not a ghost', rev_id='not-ghost-parent')
 
363
        self.tree.branch.repository.fetch(fork.branch.repository,
 
364
                                     'not-ghost-parent')
 
365
        self.tree.add_parent_tree_id('not-ghost-parent')
 
366
        self.tree.commit('second commit', rev_id='second-id')
 
367
        self.repo.fetch(self.tree.branch.repository, 'second-id')
 
368
        root_id = self.tree.get_root_id()
 
369
        self.assertEqual(['left-parent', 'ghost-parent', 'not-ghost-parent'],
 
370
                         self.get_parents(root_id, 'second-id'))
 
371
 
 
372
    def make_two_commits(self, change_root, fetch_twice):
 
373
        self.make_tree_and_repo()
 
374
        self.tree.commit('first commit', rev_id='first-id')
 
375
        if change_root:
 
376
            self.tree.set_root_id('unique-id')
 
377
        self.tree.commit('second commit', rev_id='second-id')
 
378
        if fetch_twice:
 
379
            self.repo.fetch(self.tree.branch.repository, 'first-id')
 
380
        self.repo.fetch(self.tree.branch.repository, 'second-id')
 
381
 
 
382
    def test_fetch_changed_root(self):
 
383
        self.make_two_commits(change_root=True, fetch_twice=False)
 
384
        self.assertEqual([], self.get_parents('unique-id', 'second-id'))
 
385
 
 
386
    def test_two_fetch_changed_root(self):
 
387
        self.make_two_commits(change_root=True, fetch_twice=True)
 
388
        self.assertEqual([], self.get_parents('unique-id', 'second-id'))
 
389
 
 
390
    def test_two_fetches(self):
 
391
        self.make_two_commits(change_root=False, fetch_twice=True)
 
392
        self.assertEqual(['first-id'],
 
393
                         self.get_parents('TREE_ROOT', 'second-id'))