~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_branch.py

(vila) Backport fix for a random test failure (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
    def test_branch_broken_pack(self):
65
65
        """branching with a corrupted pack file."""
66
66
        self.example_branch('a')
67
 
        #now add some random corruption
68
 
        fname = 'a/.bzr/repository/packs/' + os.listdir('a/.bzr/repository/packs')[0]
 
67
        # add some corruption
 
68
        packs_dir = 'a/.bzr/repository/packs/'
 
69
        fname = packs_dir + os.listdir(packs_dir)[0]
69
70
        with open(fname, 'rb+') as f:
70
 
            f.seek(750)
71
 
            f.write("\xff")
 
71
            # Start from the end of the file to avoid choosing a place bigger
 
72
            # than the file itself.
 
73
            f.seek(-5, os.SEEK_END)
 
74
            c = f.read(1)
 
75
            f.seek(-5, os.SEEK_END)
 
76
            # Make sure we inject a value different than the one we just read
 
77
            if c == '\xFF':
 
78
                corrupt = '\x00'
 
79
            else:
 
80
                corrupt = '\xFF'
 
81
            f.write(corrupt) # make sure we corrupt something
72
82
        self.run_bzr_error(['Corruption while decompressing repository file'], 
73
83
                            'branch a b', retcode=3)
74
84