~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_repository.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-09-01 08:02:42 UTC
  • mfrom: (5390.3.3 faster-revert-593560)
  • Revision ID: pqm@pqm.ubuntu.com-20100901080242-esg62ody4frwmy66
(spiv) Avoid repeatedly calling self.target.all_file_ids() in
 InterTree.iter_changes. (Andrew Bennetts)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007, 2008, 2009 Canonical Ltd
 
1
# Copyright (C) 2006-2010 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
23
23
"""
24
24
 
25
25
from stat import S_ISDIR
26
 
from StringIO import StringIO
 
26
import sys
27
27
 
28
28
import bzrlib
29
 
from bzrlib.errors import (NotBranchError,
30
 
                           NoSuchFile,
 
29
from bzrlib.errors import (NoSuchFile,
31
30
                           UnknownFormatError,
32
31
                           UnsupportedFormatError,
33
32
                           )
34
33
from bzrlib import (
 
34
    btree_index,
35
35
    graph,
36
36
    tests,
37
37
    )
38
 
from bzrlib.branchbuilder import BranchBuilder
39
38
from bzrlib.btree_index import BTreeBuilder, BTreeGraphIndex
40
 
from bzrlib.index import GraphIndex, InMemoryGraphIndex
 
39
from bzrlib.index import GraphIndex
41
40
from bzrlib.repository import RepositoryFormat
42
 
from bzrlib.smart import server
43
41
from bzrlib.tests import (
44
42
    TestCase,
45
43
    TestCaseWithTransport,
46
 
    TestSkipped,
47
 
    test_knit,
48
44
    )
49
45
from bzrlib.transport import (
50
 
    fakenfs,
51
46
    get_transport,
52
47
    )
53
 
from bzrlib.transport.memory import MemoryServer
54
48
from bzrlib import (
55
 
    bencode,
56
49
    bzrdir,
57
50
    errors,
58
51
    inventory,
59
52
    osutils,
60
 
    progress,
61
53
    repository,
62
54
    revision as _mod_revision,
63
 
    symbol_versioning,
64
55
    upgrade,
 
56
    versionedfile,
65
57
    workingtree,
66
58
    )
67
59
from bzrlib.repofmt import (
252
244
        tree = control.create_workingtree()
253
245
        tree.add(['foo'], ['Foo:Bar'], ['file'])
254
246
        tree.put_file_bytes_non_atomic('Foo:Bar', 'content\n')
255
 
        tree.commit('first post', rev_id='first')
 
247
        try:
 
248
            tree.commit('first post', rev_id='first')
 
249
        except errors.IllegalPath:
 
250
            if sys.platform != 'win32':
 
251
                raise
 
252
            self.knownFailure('Foo:Bar cannot be used as a file-id on windows'
 
253
                              ' in repo format 7')
 
254
            return
256
255
        self.assertEqualDiff(
257
256
            '# bzr weave file v5\n'
258
257
            'i\n'
456
455
        repo = self.make_repository('.',
457
456
                format=bzrdir.format_registry.get('knit')())
458
457
        inv_xml = '<inventory format="5">\n</inventory>\n'
459
 
        inv = repo.deserialise_inventory('test-rev-id', inv_xml)
 
458
        inv = repo._deserialise_inventory('test-rev-id', inv_xml)
460
459
        self.assertEqual('test-rev-id', inv.root.revision)
461
460
 
462
461
    def test_deserialise_uses_global_revision_id(self):
468
467
        # Arguably, the deserialise_inventory should detect a mismatch, and
469
468
        # raise an error, rather than silently using one revision_id over the
470
469
        # other.
471
 
        self.assertRaises(AssertionError, repo.deserialise_inventory,
 
470
        self.assertRaises(AssertionError, repo._deserialise_inventory,
472
471
            'test-rev-id', inv_xml)
473
 
        inv = repo.deserialise_inventory('other-rev-id', inv_xml)
 
472
        inv = repo._deserialise_inventory('other-rev-id', inv_xml)
474
473
        self.assertEqual('other-rev-id', inv.root.revision)
475
474
 
476
475
    def test_supports_external_lookups(self):
486
485
    _serializer = None
487
486
 
488
487
    def supports_rich_root(self):
 
488
        if self._format is not None:
 
489
            return self._format.rich_root_data
489
490
        return False
490
491
 
491
492
    def get_graph(self):
542
543
        # pair that it returns true on for the is_compatible static method
543
544
        # check
544
545
        dummy_a = DummyRepository()
 
546
        dummy_a._format = RepositoryFormat()
545
547
        dummy_b = DummyRepository()
 
548
        dummy_b._format = RepositoryFormat()
546
549
        repo = self.make_repository('.')
547
550
        # hack dummies to look like repo somewhat.
548
551
        dummy_a._serializer = repo._serializer
 
552
        dummy_a._format.supports_tree_reference = repo._format.supports_tree_reference
 
553
        dummy_a._format.rich_root_data = repo._format.rich_root_data
549
554
        dummy_b._serializer = repo._serializer
 
555
        dummy_b._format.supports_tree_reference = repo._format.supports_tree_reference
 
556
        dummy_b._format.rich_root_data = repo._format.rich_root_data
550
557
        repository.InterRepository.register_optimiser(InterDummy)
551
558
        try:
552
559
            # we should get the default for something InterDummy returns False
673
680
        self.assertFalse(repo._format.supports_external_lookups)
674
681
 
675
682
 
676
 
class Test2a(TestCaseWithTransport):
 
683
class Test2a(tests.TestCaseWithMemoryTransport):
 
684
 
 
685
    def test_chk_bytes_uses_custom_btree_parser(self):
 
686
        mt = self.make_branch_and_memory_tree('test', format='2a')
 
687
        mt.lock_write()
 
688
        self.addCleanup(mt.unlock)
 
689
        mt.add([''], ['root-id'])
 
690
        mt.commit('first')
 
691
        index = mt.branch.repository.chk_bytes._index._graph_index._indices[0]
 
692
        self.assertEqual(btree_index._gcchk_factory, index._leaf_factory)
 
693
        # It should also work if we re-open the repo
 
694
        repo = mt.branch.repository.bzrdir.open_repository()
 
695
        repo.lock_read()
 
696
        self.addCleanup(repo.unlock)
 
697
        index = repo.chk_bytes._index._graph_index._indices[0]
 
698
        self.assertEqual(btree_index._gcchk_factory, index._leaf_factory)
 
699
 
 
700
    def test_fetch_combines_groups(self):
 
701
        builder = self.make_branch_builder('source', format='2a')
 
702
        builder.start_series()
 
703
        builder.build_snapshot('1', None, [
 
704
            ('add', ('', 'root-id', 'directory', '')),
 
705
            ('add', ('file', 'file-id', 'file', 'content\n'))])
 
706
        builder.build_snapshot('2', ['1'], [
 
707
            ('modify', ('file-id', 'content-2\n'))])
 
708
        builder.finish_series()
 
709
        source = builder.get_branch()
 
710
        target = self.make_repository('target', format='2a')
 
711
        target.fetch(source.repository)
 
712
        target.lock_read()
 
713
        self.addCleanup(target.unlock)
 
714
        details = target.texts._index.get_build_details(
 
715
            [('file-id', '1',), ('file-id', '2',)])
 
716
        file_1_details = details[('file-id', '1')]
 
717
        file_2_details = details[('file-id', '2')]
 
718
        # The index, and what to read off disk, should be the same for both
 
719
        # versions of the file.
 
720
        self.assertEqual(file_1_details[0][:3], file_2_details[0][:3])
 
721
 
 
722
    def test_fetch_combines_groups(self):
 
723
        builder = self.make_branch_builder('source', format='2a')
 
724
        builder.start_series()
 
725
        builder.build_snapshot('1', None, [
 
726
            ('add', ('', 'root-id', 'directory', '')),
 
727
            ('add', ('file', 'file-id', 'file', 'content\n'))])
 
728
        builder.build_snapshot('2', ['1'], [
 
729
            ('modify', ('file-id', 'content-2\n'))])
 
730
        builder.finish_series()
 
731
        source = builder.get_branch()
 
732
        target = self.make_repository('target', format='2a')
 
733
        target.fetch(source.repository)
 
734
        target.lock_read()
 
735
        self.addCleanup(target.unlock)
 
736
        details = target.texts._index.get_build_details(
 
737
            [('file-id', '1',), ('file-id', '2',)])
 
738
        file_1_details = details[('file-id', '1')]
 
739
        file_2_details = details[('file-id', '2')]
 
740
        # The index, and what to read off disk, should be the same for both
 
741
        # versions of the file.
 
742
        self.assertEqual(file_1_details[0][:3], file_2_details[0][:3])
 
743
 
 
744
    def test_fetch_combines_groups(self):
 
745
        builder = self.make_branch_builder('source', format='2a')
 
746
        builder.start_series()
 
747
        builder.build_snapshot('1', None, [
 
748
            ('add', ('', 'root-id', 'directory', '')),
 
749
            ('add', ('file', 'file-id', 'file', 'content\n'))])
 
750
        builder.build_snapshot('2', ['1'], [
 
751
            ('modify', ('file-id', 'content-2\n'))])
 
752
        builder.finish_series()
 
753
        source = builder.get_branch()
 
754
        target = self.make_repository('target', format='2a')
 
755
        target.fetch(source.repository)
 
756
        target.lock_read()
 
757
        self.addCleanup(target.unlock)
 
758
        details = target.texts._index.get_build_details(
 
759
            [('file-id', '1',), ('file-id', '2',)])
 
760
        file_1_details = details[('file-id', '1')]
 
761
        file_2_details = details[('file-id', '2')]
 
762
        # The index, and what to read off disk, should be the same for both
 
763
        # versions of the file.
 
764
        self.assertEqual(file_1_details[0][:3], file_2_details[0][:3])
677
765
 
678
766
    def test_format_pack_compresses_True(self):
679
767
        repo = self.make_repository('repo', format='2a')
680
768
        self.assertTrue(repo._format.pack_compresses)
681
769
 
682
770
    def test_inventories_use_chk_map_with_parent_base_dict(self):
683
 
        tree = self.make_branch_and_tree('repo', format="2a")
 
771
        tree = self.make_branch_and_memory_tree('repo', format="2a")
 
772
        tree.lock_write()
 
773
        tree.add([''], ['TREE_ROOT'])
684
774
        revid = tree.commit("foo")
 
775
        tree.unlock()
685
776
        tree.lock_read()
686
777
        self.addCleanup(tree.unlock)
687
778
        inv = tree.branch.repository.get_inventory(revid)
696
787
        # at 20 unchanged commits, chk pages are packed that are split into
697
788
        # two groups such that the new pack being made doesn't have all its
698
789
        # pages in the source packs (though they are in the repository).
699
 
        tree = self.make_branch_and_tree('tree', format='2a')
 
790
        # Use a memory backed repository, we don't need to hit disk for this
 
791
        tree = self.make_branch_and_memory_tree('tree', format='2a')
 
792
        tree.lock_write()
 
793
        self.addCleanup(tree.unlock)
 
794
        tree.add([''], ['TREE_ROOT'])
700
795
        for pos in range(20):
701
796
            tree.commit(str(pos))
702
797
 
703
798
    def test_pack_with_hint(self):
704
 
        tree = self.make_branch_and_tree('tree', format='2a')
 
799
        tree = self.make_branch_and_memory_tree('tree', format='2a')
 
800
        tree.lock_write()
 
801
        self.addCleanup(tree.unlock)
 
802
        tree.add([''], ['TREE_ROOT'])
705
803
        # 1 commit to leave untouched
706
804
        tree.commit('1')
707
805
        to_keep = tree.branch.repository._pack_collection.names()
946
1044
            inv = inventory.Inventory(revision_id='rev1a')
947
1045
            inv.root.revision = 'rev1a'
948
1046
            self.add_file(repo, inv, 'file1', 'rev1a', [])
 
1047
            repo.texts.add_lines((inv.root.file_id, 'rev1a'), [], [])
949
1048
            repo.add_inventory('rev1a', inv, [])
950
1049
            revision = _mod_revision.Revision('rev1a',
951
1050
                committer='jrandom@example.com', timestamp=0,
986
1085
    def add_revision(self, repo, revision_id, inv, parent_ids):
987
1086
        inv.revision_id = revision_id
988
1087
        inv.root.revision = revision_id
 
1088
        repo.texts.add_lines((inv.root.file_id, revision_id), [], [])
989
1089
        repo.add_inventory(revision_id, inv, parent_ids)
990
1090
        revision = _mod_revision.Revision(revision_id,
991
1091
            committer='jrandom@example.com', timestamp=0, inventory_sha1='',
1008
1108
        """
1009
1109
        broken_repo = self.make_broken_repository()
1010
1110
        empty_repo = self.make_repository('empty-repo')
1011
 
        # See bug https://bugs.launchpad.net/bzr/+bug/389141 for information
1012
 
        # about why this was turned into expectFailure
1013
 
        self.expectFailure('new Stream fetch fills in missing compression'
1014
 
           ' parents (bug #389141)',
1015
 
           self.assertRaises, (errors.RevisionNotPresent, errors.BzrCheckError),
1016
 
                              empty_repo.fetch, broken_repo)
1017
 
        self.assertRaises((errors.RevisionNotPresent, errors.BzrCheckError),
1018
 
                          empty_repo.fetch, broken_repo)
 
1111
        try:
 
1112
            empty_repo.fetch(broken_repo)
 
1113
        except (errors.RevisionNotPresent, errors.BzrCheckError):
 
1114
            # Test successful: compression parent not being copied leads to
 
1115
            # error.
 
1116
            return
 
1117
        empty_repo.lock_read()
 
1118
        self.addCleanup(empty_repo.unlock)
 
1119
        text = empty_repo.texts.get_record_stream(
 
1120
            [('file2-id', 'rev3')], 'topological', True).next()
 
1121
        self.assertEqual('line\n', text.get_bytes_as('fulltext'))
1019
1122
 
1020
1123
 
1021
1124
class TestRepositoryPackCollection(TestCaseWithTransport):
1030
1133
 
1031
1134
    def make_packs_and_alt_repo(self, write_lock=False):
1032
1135
        """Create a pack repo with 3 packs, and access it via a second repo."""
1033
 
        tree = self.make_branch_and_tree('.')
 
1136
        tree = self.make_branch_and_tree('.', format=self.get_format())
1034
1137
        tree.lock_write()
1035
1138
        self.addCleanup(tree.unlock)
1036
1139
        rev1 = tree.commit('one')
1046
1149
        packs.ensure_loaded()
1047
1150
        return tree, r, packs, [rev1, rev2, rev3]
1048
1151
 
 
1152
    def test__clear_obsolete_packs(self):
 
1153
        packs = self.get_packs()
 
1154
        obsolete_pack_trans = packs.transport.clone('obsolete_packs')
 
1155
        obsolete_pack_trans.put_bytes('a-pack.pack', 'content\n')
 
1156
        obsolete_pack_trans.put_bytes('a-pack.rix', 'content\n')
 
1157
        obsolete_pack_trans.put_bytes('a-pack.iix', 'content\n')
 
1158
        obsolete_pack_trans.put_bytes('another-pack.pack', 'foo\n')
 
1159
        obsolete_pack_trans.put_bytes('not-a-pack.rix', 'foo\n')
 
1160
        res = packs._clear_obsolete_packs()
 
1161
        self.assertEqual(['a-pack', 'another-pack'], sorted(res))
 
1162
        self.assertEqual([], obsolete_pack_trans.list_dir('.'))
 
1163
 
 
1164
    def test__clear_obsolete_packs_preserve(self):
 
1165
        packs = self.get_packs()
 
1166
        obsolete_pack_trans = packs.transport.clone('obsolete_packs')
 
1167
        obsolete_pack_trans.put_bytes('a-pack.pack', 'content\n')
 
1168
        obsolete_pack_trans.put_bytes('a-pack.rix', 'content\n')
 
1169
        obsolete_pack_trans.put_bytes('a-pack.iix', 'content\n')
 
1170
        obsolete_pack_trans.put_bytes('another-pack.pack', 'foo\n')
 
1171
        obsolete_pack_trans.put_bytes('not-a-pack.rix', 'foo\n')
 
1172
        res = packs._clear_obsolete_packs(preserve=set(['a-pack']))
 
1173
        self.assertEqual(['a-pack', 'another-pack'], sorted(res))
 
1174
        self.assertEqual(['a-pack.iix', 'a-pack.pack', 'a-pack.rix'],
 
1175
                         sorted(obsolete_pack_trans.list_dir('.')))
 
1176
 
1049
1177
    def test__max_pack_count(self):
1050
1178
        """The maximum pack count is a function of the number of revisions."""
1051
1179
        # no revisions - one pack, so that we can have a revision free repo
1071
1199
        # check some arbitrary big numbers
1072
1200
        self.assertEqual(25, packs._max_pack_count(112894))
1073
1201
 
 
1202
    def test_repr(self):
 
1203
        packs = self.get_packs()
 
1204
        self.assertContainsRe(repr(packs),
 
1205
            'RepositoryPackCollection(.*Repository(.*))')
 
1206
 
 
1207
    def test__obsolete_packs(self):
 
1208
        tree, r, packs, revs = self.make_packs_and_alt_repo(write_lock=True)
 
1209
        names = packs.names()
 
1210
        pack = packs.get_pack_by_name(names[0])
 
1211
        # Schedule this one for removal
 
1212
        packs._remove_pack_from_memory(pack)
 
1213
        # Simulate a concurrent update by renaming the .pack file and one of
 
1214
        # the indices
 
1215
        packs.transport.rename('packs/%s.pack' % (names[0],),
 
1216
                               'obsolete_packs/%s.pack' % (names[0],))
 
1217
        packs.transport.rename('indices/%s.iix' % (names[0],),
 
1218
                               'obsolete_packs/%s.iix' % (names[0],))
 
1219
        # Now trigger the obsoletion, and ensure that all the remaining files
 
1220
        # are still renamed
 
1221
        packs._obsolete_packs([pack])
 
1222
        self.assertEqual([n + '.pack' for n in names[1:]],
 
1223
                         sorted(packs._pack_transport.list_dir('.')))
 
1224
        # names[0] should not be present in the index anymore
 
1225
        self.assertEqual(names[1:],
 
1226
            sorted(set([osutils.splitext(n)[0] for n in
 
1227
                        packs._index_transport.list_dir('.')])))
 
1228
 
1074
1229
    def test_pack_distribution_zero(self):
1075
1230
        packs = self.get_packs()
1076
1231
        self.assertEqual([0], packs.pack_distribution(0))
1244
1399
        self.assertEqual({revs[-1]:(revs[-2],)}, r.get_parent_map([revs[-1]]))
1245
1400
        self.assertFalse(packs.reload_pack_names())
1246
1401
 
 
1402
    def test_reload_pack_names_preserves_pending(self):
 
1403
        # TODO: Update this to also test for pending-deleted names
 
1404
        tree, r, packs, revs = self.make_packs_and_alt_repo(write_lock=True)
 
1405
        # We will add one pack (via start_write_group + insert_record_stream),
 
1406
        # and remove another pack (via _remove_pack_from_memory)
 
1407
        orig_names = packs.names()
 
1408
        orig_at_load = packs._packs_at_load
 
1409
        to_remove_name = iter(orig_names).next()
 
1410
        r.start_write_group()
 
1411
        self.addCleanup(r.abort_write_group)
 
1412
        r.texts.insert_record_stream([versionedfile.FulltextContentFactory(
 
1413
            ('text', 'rev'), (), None, 'content\n')])
 
1414
        new_pack = packs._new_pack
 
1415
        self.assertTrue(new_pack.data_inserted())
 
1416
        new_pack.finish()
 
1417
        packs.allocate(new_pack)
 
1418
        packs._new_pack = None
 
1419
        removed_pack = packs.get_pack_by_name(to_remove_name)
 
1420
        packs._remove_pack_from_memory(removed_pack)
 
1421
        names = packs.names()
 
1422
        all_nodes, deleted_nodes, new_nodes, _ = packs._diff_pack_names()
 
1423
        new_names = set([x[0][0] for x in new_nodes])
 
1424
        self.assertEqual(names, sorted([x[0][0] for x in all_nodes]))
 
1425
        self.assertEqual(set(names) - set(orig_names), new_names)
 
1426
        self.assertEqual(set([new_pack.name]), new_names)
 
1427
        self.assertEqual([to_remove_name],
 
1428
                         sorted([x[0][0] for x in deleted_nodes]))
 
1429
        packs.reload_pack_names()
 
1430
        reloaded_names = packs.names()
 
1431
        self.assertEqual(orig_at_load, packs._packs_at_load)
 
1432
        self.assertEqual(names, reloaded_names)
 
1433
        all_nodes, deleted_nodes, new_nodes, _ = packs._diff_pack_names()
 
1434
        new_names = set([x[0][0] for x in new_nodes])
 
1435
        self.assertEqual(names, sorted([x[0][0] for x in all_nodes]))
 
1436
        self.assertEqual(set(names) - set(orig_names), new_names)
 
1437
        self.assertEqual(set([new_pack.name]), new_names)
 
1438
        self.assertEqual([to_remove_name],
 
1439
                         sorted([x[0][0] for x in deleted_nodes]))
 
1440
 
 
1441
    def test_autopack_obsoletes_new_pack(self):
 
1442
        tree, r, packs, revs = self.make_packs_and_alt_repo(write_lock=True)
 
1443
        packs._max_pack_count = lambda x: 1
 
1444
        packs.pack_distribution = lambda x: [10]
 
1445
        r.start_write_group()
 
1446
        r.revisions.insert_record_stream([versionedfile.FulltextContentFactory(
 
1447
            ('bogus-rev',), (), None, 'bogus-content\n')])
 
1448
        # This should trigger an autopack, which will combine everything into a
 
1449
        # single pack file.
 
1450
        new_names = r.commit_write_group()
 
1451
        names = packs.names()
 
1452
        self.assertEqual(1, len(names))
 
1453
        self.assertEqual([names[0] + '.pack'],
 
1454
                         packs._pack_transport.list_dir('.'))
 
1455
 
1247
1456
    def test_autopack_reloads_and_stops(self):
1248
1457
        tree, r, packs, revs = self.make_packs_and_alt_repo(write_lock=True)
1249
1458
        # After we have determined what needs to be autopacked, trigger a
1261
1470
        self.assertEqual(tree.branch.repository._pack_collection.names(),
1262
1471
                         packs.names())
1263
1472
 
 
1473
    def test__save_pack_names(self):
 
1474
        tree, r, packs, revs = self.make_packs_and_alt_repo(write_lock=True)
 
1475
        names = packs.names()
 
1476
        pack = packs.get_pack_by_name(names[0])
 
1477
        packs._remove_pack_from_memory(pack)
 
1478
        packs._save_pack_names(obsolete_packs=[pack])
 
1479
        cur_packs = packs._pack_transport.list_dir('.')
 
1480
        self.assertEqual([n + '.pack' for n in names[1:]], sorted(cur_packs))
 
1481
        # obsolete_packs will also have stuff like .rix and .iix present.
 
1482
        obsolete_packs = packs.transport.list_dir('obsolete_packs')
 
1483
        obsolete_names = set([osutils.splitext(n)[0] for n in obsolete_packs])
 
1484
        self.assertEqual([pack.name], sorted(obsolete_names))
 
1485
 
 
1486
    def test__save_pack_names_already_obsoleted(self):
 
1487
        tree, r, packs, revs = self.make_packs_and_alt_repo(write_lock=True)
 
1488
        names = packs.names()
 
1489
        pack = packs.get_pack_by_name(names[0])
 
1490
        packs._remove_pack_from_memory(pack)
 
1491
        # We are going to simulate a concurrent autopack by manually obsoleting
 
1492
        # the pack directly.
 
1493
        packs._obsolete_packs([pack])
 
1494
        packs._save_pack_names(clear_obsolete_packs=True,
 
1495
                               obsolete_packs=[pack])
 
1496
        cur_packs = packs._pack_transport.list_dir('.')
 
1497
        self.assertEqual([n + '.pack' for n in names[1:]], sorted(cur_packs))
 
1498
        # Note that while we set clear_obsolete_packs=True, it should not
 
1499
        # delete a pack file that we have also scheduled for obsoletion.
 
1500
        obsolete_packs = packs.transport.list_dir('obsolete_packs')
 
1501
        obsolete_names = set([osutils.splitext(n)[0] for n in obsolete_packs])
 
1502
        self.assertEqual([pack.name], sorted(obsolete_names))
 
1503
 
 
1504
 
1264
1505
 
1265
1506
class TestPack(TestCaseWithTransport):
1266
1507
    """Tests for the Pack object."""
1330
1571
            index_class=BTreeGraphIndex,
1331
1572
            use_chk_index=False)
1332
1573
        pack = pack_repo.NewPack(collection)
 
1574
        self.addCleanup(pack.abort) # Make sure the write stream gets closed
1333
1575
        self.assertIsInstance(pack.revision_index, BTreeBuilder)
1334
1576
        self.assertIsInstance(pack.inventory_index, BTreeBuilder)
1335
1577
        self.assertIsInstance(pack._hash, type(osutils.md5()))
1346
1588
    """Tests for the packs repository Packer class."""
1347
1589
 
1348
1590
    def test_pack_optimizes_pack_order(self):
1349
 
        builder = self.make_branch_builder('.')
 
1591
        builder = self.make_branch_builder('.', format="1.9")
1350
1592
        builder.start_series()
1351
1593
        builder.build_snapshot('A', None, [
1352
1594
            ('add', ('', 'root-id', 'directory', None)),
1388
1630
        packer = pack_repo.OptimisingPacker(self.get_pack_collection(),
1389
1631
                                            [], '.test')
1390
1632
        new_pack = packer.open_pack()
 
1633
        self.addCleanup(new_pack.abort) # ensure cleanup
1391
1634
        self.assertIsInstance(new_pack, pack_repo.NewPack)
1392
1635
        self.assertTrue(new_pack.revision_index._optimize_for_size)
1393
1636
        self.assertTrue(new_pack.inventory_index._optimize_for_size)