Rev 6159: Fix random test failure by making the test not random in file:///home/vila/src/bzr/bugs/807032-broken-pack-failure/

Vincent Ladeuil v.ladeuil+lp at free.fr
Thu Sep 22 16:33:49 UTC 2011


At file:///home/vila/src/bzr/bugs/807032-broken-pack-failure/

------------------------------------------------------------
revno: 6159
revision-id: v.ladeuil+lp at free.fr-20110922163349-n6o4zltw9zreskgl
parent: pqm at pqm.ubuntu.com-20110922141218-86s4uu6nqvourw4f
fixes bug: https://launchpad.net/bugs/807032
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 807032-broken-pack-failure
timestamp: Thu 2011-09-22 18:33:49 +0200
message:
  Fix random test failure by making the test not random
-------------- next part --------------
=== modified file 'bzrlib/tests/blackbox/test_branch.py'
--- a/bzrlib/tests/blackbox/test_branch.py	2011-09-16 15:37:58 +0000
+++ b/bzrlib/tests/blackbox/test_branch.py	2011-09-22 16:33:49 +0000
@@ -66,11 +66,21 @@
     def test_branch_broken_pack(self):
         """branching with a corrupted pack file."""
         self.example_branch('a')
-        #now add some random corruption
-        fname = 'a/.bzr/repository/packs/' + os.listdir('a/.bzr/repository/packs')[0]
+        # add some corruption
+        packs_dir = 'a/.bzr/repository/packs/'
+        fname = packs_dir + os.listdir(packs_dir)[0]
         with open(fname, 'rb+') as f:
-            f.seek(750)
-            f.write("\xff")
+            # Start from the end of the file to avoid choosing a place bigger
+            # than the file itself.
+            f.seek(-5, os.SEEK_END)
+            c = f.read(1)
+            f.seek(-5, os.SEEK_END)
+            # Make sure we inject a value different than the one we just read
+            if c == '\xFF':
+                corrupt = '\x00'
+            else:
+                corrupt = '\xFF'
+            f.write(corrupt) # make sure we corrupt something
         self.run_bzr_error(['Corruption while decompressing repository file'], 
                             'branch a b', retcode=3)
 

=== modified file 'doc/en/release-notes/bzr-2.5.txt'
--- a/doc/en/release-notes/bzr-2.5.txt	2011-09-22 12:13:12 +0000
+++ b/doc/en/release-notes/bzr-2.5.txt	2011-09-22 16:33:49 +0000
@@ -67,6 +67,9 @@
    suite.  This can include new facilities for writing tests, fixes to 
    spurious test failures and changes to the way things should be tested.
 
+* Really corrupt the pack file without depending on a special length or value.
+  (Vincent Ladeuil, #807032)
+
 
 bzr 2.5b1
 #########



More information about the bazaar-commits mailing list