~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/bzrdir_implementations/test_bzrdir.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-11-26 21:33:20 UTC
  • mfrom: (3015.2.15 pack.read-locks)
  • Revision ID: pqm@pqm.ubuntu.com-20071126213320-adxxra3gsie5inhw
(robertc) Many fixes to support packs on the smart server and as the
        default format. (Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
from cStringIO import StringIO
20
20
import errno
 
21
from itertools import izip
21
22
import os
22
23
from stat import S_ISDIR
23
24
import sys
80
81
        reading it again, which leads to changed timestamps. This is ok though,
81
82
        because the inventory.kndx file is not ignored, and the integrity of
82
83
        knit joins is tested by test_knit and test_versionedfile.
 
84
 
 
85
        :seealso: Additionally, assertRepositoryHasSameItems provides value
 
86
            rather than representation checking of repositories for
 
87
            equivalence.
83
88
        """
84
89
        files = []
85
90
        directories = ['.']
101
106
                                         target.get(path).read(),
102
107
                                         "text for file %r differs:\n" % path)
103
108
 
 
109
    def assertRepositoryHasSameItems(self, left_repo, right_repo):
 
110
        """require left_repo and right_repo to contain the same data."""
 
111
        # XXX: TODO: Doesn't work yet, because we need to be able to compare
 
112
        # local repositories to remote ones...  but this is an as-yet unsolved
 
113
        # aspect of format management and the Remote protocols...
 
114
        # self.assertEqual(left_repo._format.__class__,
 
115
        #     right_repo._format.__class__)
 
116
        left_repo.lock_read()
 
117
        try:
 
118
            right_repo.lock_read()
 
119
            try:
 
120
                # revs
 
121
                all_revs = left_repo.all_revision_ids()
 
122
                self.assertEqual(left_repo.all_revision_ids(),
 
123
                    right_repo.all_revision_ids())
 
124
                for rev_id in left_repo.all_revision_ids():
 
125
                    self.assertEqual(left_repo.get_revision(rev_id),
 
126
                        right_repo.get_revision(rev_id))
 
127
                # inventories
 
128
                left_inv_weave = left_repo.get_inventory_weave()
 
129
                right_inv_weave = right_repo.get_inventory_weave()
 
130
                self.assertEqual(set(left_inv_weave.versions()),
 
131
                    set(right_inv_weave.versions()))
 
132
                # XXX: currently this does not handle indirectly referenced
 
133
                # inventories (e.g. where the inventory is a delta basis for
 
134
                # one that is fully present but that the revid for that
 
135
                # inventory is not yet present.)
 
136
                self.assertEqual(set(left_inv_weave.versions()), set(all_revs))
 
137
                left_trees = left_repo.revision_trees(all_revs)
 
138
                right_trees = right_repo.revision_trees(all_revs)
 
139
                for left_tree, right_tree in izip(left_trees, right_trees):
 
140
                    self.assertEqual(left_tree.inventory, right_tree.inventory)
 
141
                # texts
 
142
                text_index = left_repo._generate_text_key_index()
 
143
                self.assertEqual(text_index,
 
144
                    right_repo._generate_text_key_index())
 
145
                for file_id, revision_id in text_index.iterkeys():
 
146
                    left_weave = left_repo.weave_store.get_weave(
 
147
                        file_id, left_repo.get_transaction())
 
148
                    right_weave = right_repo.weave_store.get_weave(
 
149
                        file_id, right_repo.get_transaction())
 
150
                    self.assertEqual(
 
151
                        left_weave.get_text(revision_id),
 
152
                        right_weave.get_text(revision_id))
 
153
                # signatures
 
154
                for rev_id in all_revs:
 
155
                    try:
 
156
                        left_text = left_repo.get_signature_text(rev_id)
 
157
                    except NoSuchRevision:
 
158
                        continue
 
159
                    right_text = right_repo.get_signature_text(rev_id)
 
160
                    self.assertEqual(left_text, right_text)
 
161
            finally:
 
162
                right_repo.unlock()
 
163
        finally:
 
164
            left_repo.unlock()
 
165
 
104
166
    def skipIfNoWorkingTree(self, a_bzrdir):
105
167
        """Raises TestSkipped if a_bzrdir doesn't have a working tree.
106
168
        
229
291
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
230
292
                                    [
231
293
                                     './.bzr/merge-hashes',
232
 
                                     './.bzr/repository/inventory.knit',
 
294
                                     './.bzr/repository',
233
295
                                     ])
234
 
 
 
296
        self.assertRepositoryHasSameItems(tree.branch.repository, repo)
235
297
 
236
298
    def test_clone_bzrdir_repository_under_shared(self):
237
299
        tree = self.make_branch_and_tree('commit_tree')
324
386
        target = dir.clone(self.get_url('target/child'), force_new_repo=True)
325
387
        self.assertNotEqual(dir.transport.base, target.transport.base)
326
388
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
327
 
                                    ['./.bzr/repository/inventory.knit',
 
389
                                    ['./.bzr/repository',
328
390
                                     ])
 
391
        self.assertRepositoryHasSameItems(tree.branch.repository, repo)
329
392
 
330
393
    def test_clone_bzrdir_repository_revision(self):
331
394
        # test for revision limiting, [smoke test, not corner case checks].
361
424
                                     './.bzr/basis-inventory-cache',
362
425
                                     './.bzr/checkout/stat-cache',
363
426
                                     './.bzr/merge-hashes',
364
 
                                     './.bzr/repository/inventory.knit',
 
427
                                     './.bzr/repository',
365
428
                                     './.bzr/stat-cache',
366
429
                                    ])
 
430
        self.assertRepositoryHasSameItems(
 
431
            tree.branch.repository, target.open_repository())
367
432
 
368
433
    def test_clone_bzrdir_branch_and_repo_into_shared_repo(self):
369
434
        # by default cloning into a shared repo uses the shared repo.
401
466
        dir = source.bzrdir
402
467
        target = dir.clone(self.get_url('target/child'), force_new_repo=True)
403
468
        self.assertNotEqual(dir.transport.base, target.transport.base)
404
 
        target.open_repository()
 
469
        repo = target.open_repository()
405
470
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
406
 
                                    ['./.bzr/repository/inventory.knit',
 
471
                                    ['./.bzr/repository',
407
472
                                     ])
 
473
        self.assertRepositoryHasSameItems(tree.branch.repository, repo)
408
474
 
409
475
    def test_clone_bzrdir_branch_reference(self):
410
476
        # cloning should preserve the reference status of the branch in a bzrdir
418
484
            return
419
485
        target = dir.clone(self.get_url('target'))
420
486
        self.assertNotEqual(dir.transport.base, target.transport.base)
421
 
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
422
 
                                    ['./.bzr/repository/inventory.knit',
423
 
                                     ])
 
487
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport)
424
488
 
425
489
    def test_clone_bzrdir_branch_revision(self):
426
490
        # test for revision limiting, [smoke test, not corner case checks].
454
518
                                     './.bzr/checkout/stat-cache',
455
519
                                     './.bzr/checkout/merge-hashes',
456
520
                                     './.bzr/merge-hashes',
457
 
                                     './.bzr/repository/inventory.knit',
 
521
                                     './.bzr/repository',
458
522
                                     ])
459
 
 
 
523
        self.assertRepositoryHasSameItems(tree.branch.repository,
 
524
            target.open_repository())
460
525
        target.open_workingtree().revert()
461
526
 
462
527
    def test_revert_inventory(self):
473
538
                                     './.bzr/checkout/stat-cache',
474
539
                                     './.bzr/checkout/merge-hashes',
475
540
                                     './.bzr/merge-hashes',
476
 
                                     './.bzr/repository/inventory.knit',
 
541
                                     './.bzr/repository',
477
542
                                     ])
 
543
        self.assertRepositoryHasSameItems(tree.branch.repository,
 
544
            target.open_repository())
478
545
 
479
546
        target.open_workingtree().revert()
480
547
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
483
550
                                     './.bzr/checkout/stat-cache',
484
551
                                     './.bzr/checkout/merge-hashes',
485
552
                                     './.bzr/merge-hashes',
486
 
                                     './.bzr/repository/inventory.knit',
 
553
                                     './.bzr/repository',
487
554
                                     ])
 
555
        self.assertRepositoryHasSameItems(tree.branch.repository,
 
556
            target.open_repository())
488
557
 
489
558
    def test_clone_bzrdir_tree_branch_reference(self):
490
559
        # a tree with a branch reference (aka a checkout) 
923
992
                                     './.bzr/checkout/inventory',
924
993
                                     './.bzr/inventory',
925
994
                                     './.bzr/parent',
926
 
                                     './.bzr/repository/inventory.knit',
 
995
                                     './.bzr/repository',
927
996
                                     './.bzr/stat-cache',
928
997
                                     ])
 
998
        self.assertRepositoryHasSameItems(
 
999
            tree.branch.repository, target.open_repository())
929
1000
 
930
1001
    def test_sprout_bzrdir_tree_branch_reference(self):
931
1002
        # sprouting should create a repository if needed and a sprouted branch.
1427
1498
        # break lock with just a repo should unlock the repo.
1428
1499
        repo = self.make_repository('.')
1429
1500
        repo.lock_write()
 
1501
        lock_repo = repo.bzrdir.open_repository()
 
1502
        if not lock_repo.get_physical_lock_status():
 
1503
            # This bzrdir's default repository does not physically lock things
 
1504
            # and thus this interaction cannot be tested at the interface
 
1505
            # level.
 
1506
            repo.unlock()
 
1507
            return
1430
1508
        # only one yes needed here: it should only be unlocking
1431
1509
        # the repo
1432
1510
        bzrlib.ui.ui_factory.stdin = StringIO("y\n")
1436
1514
            # this bzrdir does not implement break_lock - so we cant test it.
1437
1515
            repo.unlock()
1438
1516
            return
1439
 
        lock_repo = repo.bzrdir.open_repository()
1440
1517
        lock_repo.lock_write()
1441
1518
        lock_repo.unlock()
1442
1519
        self.assertRaises(errors.LockBroken, repo.unlock)
1462
1539
            # dir is inappropriately accessed, 3 will be needed, and
1463
1540
            # we'll see that because the stream will be fully consumed
1464
1541
            bzrlib.ui.ui_factory.stdin = StringIO("y\ny\ny\n")
 
1542
            # determine if the repository will have been locked;
 
1543
            this_repo_locked = \
 
1544
                thisdir.open_repository().get_physical_lock_status()
1465
1545
            master.bzrdir.break_lock()
1466
 
            # only two ys should have been read
1467
 
            self.assertEqual("y\n", bzrlib.ui.ui_factory.stdin.read())
 
1546
            if this_repo_locked:
 
1547
                # only two ys should have been read
 
1548
                self.assertEqual("y\n", bzrlib.ui.ui_factory.stdin.read())
 
1549
            else:
 
1550
                # only one y should have been read
 
1551
                self.assertEqual("y\ny\n", bzrlib.ui.ui_factory.stdin.read())
1468
1552
            # we should be able to lock a newly opened branch now
1469
1553
            branch = master.bzrdir.open_branch()
1470
1554
            branch.lock_write()
1471
1555
            branch.unlock()
1472
 
            # we should not be able to lock the repository in thisdir as its still
1473
 
            # held by the explicit lock we took, and the break lock should not have
1474
 
            # touched it.
1475
 
            repo = thisdir.open_repository()
1476
 
            orig_default = lockdir._DEFAULT_TIMEOUT_SECONDS
1477
 
            try:
1478
 
                lockdir._DEFAULT_TIMEOUT_SECONDS = 1
1479
 
                self.assertRaises(errors.LockContention, repo.lock_write)
1480
 
            finally:
1481
 
                lockdir._DEFAULT_TIMEOUT_SECONDS = orig_default
 
1556
            if this_repo_locked:
 
1557
                # we should not be able to lock the repository in thisdir as
 
1558
                # its still held by the explicit lock we took, and the break
 
1559
                # lock should not have touched it.
 
1560
                repo = thisdir.open_repository()
 
1561
                orig_default = lockdir._DEFAULT_TIMEOUT_SECONDS
 
1562
                try:
 
1563
                    lockdir._DEFAULT_TIMEOUT_SECONDS = 1
 
1564
                    self.assertRaises(errors.LockContention, repo.lock_write)
 
1565
                finally:
 
1566
                    lockdir._DEFAULT_TIMEOUT_SECONDS = orig_default
1482
1567
        finally:
1483
1568
            unused_repo.unlock()
1484
1569
        self.assertRaises(errors.LockBroken, master.unlock)