Rev 3366: Add test that out of order insertion fails with a clean error/does not fail. in http://people.ubuntu.com/~robertc/baz2.0/versioned_files

Robert Collins robertc at robertcollins.net
Wed Apr 30 02:48:08 BST 2008


At http://people.ubuntu.com/~robertc/baz2.0/versioned_files

------------------------------------------------------------
revno: 3366
revision-id: robertc at robertcollins.net-20080430014801-td3qtpnf46amdsy5
parent: robertc at robertcollins.net-20080429230836-s6m93kss4mcbtc2t
committer: Robert Collins <robertc at robertcollins.net>
branch nick: data_stream_revamp
timestamp: Wed 2008-04-30 11:48:01 +1000
message:
  Add test that out of order insertion fails with a clean error/does not fail.
modified:
  bzrlib/knit.py                 knit.py-20051212171256-f056ac8f0fbe1bd9
  bzrlib/tests/test_versionedfile.py test_versionedfile.py-20060222045249-db45c9ed14a1c2e5
=== modified file 'bzrlib/knit.py'
--- a/bzrlib/knit.py	2008-04-29 23:08:36 +0000
+++ b/bzrlib/knit.py	2008-04-30 01:48:01 +0000
@@ -1369,6 +1369,19 @@
 
     def check(self, progress_bar=None):
         """See VersionedFile.check()."""
+        # This doesn't actually test extraction of everything, but that will
+        # impact 'bzr check' substantially, and needs to be integrated with
+        # care. However, it does check for the obvious problem of a delta with
+        # no basis.
+        versions = self.versions()
+        parent_map = self.get_parent_map(versions)
+        for version in versions:
+            if self.get_method(version) != 'fulltext':
+                compression_parent = parent_map[version][0]
+                if compression_parent not in parent_map:
+                    raise errors.KnitCorrupt(self,
+                        "Missing basis parent %s for %s" % (
+                        compression_parent, version))
 
     def get_lines(self, version_id):
         """See VersionedFile.get_lines()."""

=== modified file 'bzrlib/tests/test_versionedfile.py'
--- a/bzrlib/tests/test_versionedfile.py	2008-04-29 23:08:36 +0000
+++ b/bzrlib/tests/test_versionedfile.py	2008-04-30 01:48:01 +0000
@@ -21,6 +21,7 @@
 # TODO: might be nice to create a versionedfile with some type of corruption
 # considered typical and check that it can be detected/corrected.
 
+from itertools import chain
 from StringIO import StringIO
 
 import bzrlib
@@ -340,6 +341,24 @@
         self.assertRaises(errors.RevisionNotPresent, f.insert_record_stream,
             stream)
 
+    def test_insert_record_stream_out_of_order(self):
+        """An out of order stream can either error or work."""
+        f, parents = get_diamond_vf(self.get_file())
+        origin_entries = f.get_record_stream(['origin'], 'unordered', False)
+        end_entries = f.get_record_stream(['merged', 'left'],
+            'topological', False)
+        start_entries = f.get_record_stream(['right', 'base'],
+            'topological', False)
+        entries = chain(origin_entries, end_entries, start_entries)
+        target = self.get_file('target')
+        try:
+            target.insert_record_stream(entries)
+        except RevisionNotPresent:
+            # Must not have corrupted the file.
+            target.check()
+        else:
+            self.assertIdenticalVersionedFile(f, target)
+
     def test_adds_with_parent_texts(self):
         f = self.get_file()
         parent_texts = {}




More information about the bazaar-commits mailing list