From 0668cdf7862091ba2b31847a6c1c234a920459cd Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Sat, 9 Jul 2016 20:45:26 +0200 Subject: [PATCH] add test for healing --- borg/testsuite/archiver.py | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/borg/testsuite/archiver.py b/borg/testsuite/archiver.py index d52391239..0179a882e 100644 --- a/borg/testsuite/archiver.py +++ b/borg/testsuite/archiver.py @@ -1142,12 +1142,45 @@ def test_missing_file_chunk(self): with repository: for item in archive.iter_items(): if item[b'path'].endswith('testsuite/archiver.py'): - repository.delete(item[b'chunks'][-1][0]) + valid_chunks = item[b'chunks'] + killed_chunk = valid_chunks[-1] + repository.delete(killed_chunk[0]) break + else: + self.assert_true(False) # should not happen repository.commit() self.cmd('check', self.repository_location, exit_code=1) - self.cmd('check', '--repair', self.repository_location, exit_code=0) + output = self.cmd('check', '--repair', self.repository_location, exit_code=0) + self.assert_in('New missing file chunk detected', output) self.cmd('check', self.repository_location, exit_code=0) + # check that the file in the old archives has now a different chunk list without the killed chunk + for archive_name in ('archive1', 'archive2'): + archive, repository = self.open_archive(archive_name) + with repository: + for item in archive.iter_items(): + if item[b'path'].endswith('testsuite/archiver.py'): + self.assert_not_equal(valid_chunks, item[b'chunks']) + self.assert_not_in(killed_chunk, item[b'chunks']) + break + else: + self.assert_true(False) # should not happen + # do a fresh backup (that will include the killed chunk) + with patch.object(ChunkBuffer, 'BUFFER_SIZE', 10): + self.create_src_archive('archive3') + # check should be able to heal the file now: + output = self.cmd('check', '-v', '--repair', self.repository_location, exit_code=0) + self.assert_in('Healed previously missing file chunk', output) + self.assert_in('testsuite/archiver.py: Completely healed previously damaged file!', output) + # check that the file in the old archives has the correct chunks again + for archive_name in ('archive1', 'archive2'): + archive, repository = self.open_archive(archive_name) + with repository: + for item in archive.iter_items(): + if item[b'path'].endswith('testsuite/archiver.py'): + self.assert_equal(valid_chunks, item[b'chunks']) + break + else: + self.assert_true(False) # should not happen def test_missing_archive_item_chunk(self): archive, repository = self.open_archive('archive1')