From b5b0b7b3220334c758eea74a81020d2d933d47e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Borgstr=C3=B6m?= Date: Thu, 10 Oct 2013 22:24:06 +0200 Subject: [PATCH] Add two additional tests. --- attic/testsuite/hashindex.py | 12 ++++++++++++ attic/testsuite/repository.py | 15 +++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/attic/testsuite/hashindex.py b/attic/testsuite/hashindex.py index d323390f1..d14354774 100644 --- a/attic/testsuite/hashindex.py +++ b/attic/testsuite/hashindex.py @@ -63,4 +63,16 @@ class HashIndexTestCase(AtticTestCase): idx.flush() self.assert_equal(initial_size, os.path.getsize(idx_name.name)) + def test_read_only(self): + """Make sure read_only indices work even they contain a lot of tombstones + """ + idx_name = tempfile.NamedTemporaryFile() + idx = NSIndex.create(idx_name.name) + for x in range(100): + idx[bytes('%-0.32d' % x, 'ascii')] = x, x + for x in range(99): + del idx[bytes('%-0.32d' % x, 'ascii')] + idx.flush() + idx2 = NSIndex(idx_name.name, readonly=True) + self.assert_equal(idx2[bytes('%-0.32d' % 99, 'ascii')], (99, 99)) diff --git a/attic/testsuite/repository.py b/attic/testsuite/repository.py index d7b33d1ba..33d0cde28 100644 --- a/attic/testsuite/repository.py +++ b/attic/testsuite/repository.py @@ -1,6 +1,7 @@ import os import shutil import tempfile +from attic.hashindex import NSIndex from attic.helpers import Location from attic.remote import RemoteRepository from attic.repository import Repository @@ -48,6 +49,20 @@ class RepositoryTestCase(AtticTestCase): self.repository.commit() self.assert_equal(self.repository.get(b'00000000000000000000000000000001'), b'bar') + def test_index_rebuild(self): + """Verify that repository index rebuild works properly + """ + def extract_and_unlink_index(): + index_name = [n for n in os.listdir(os.path.join(self.tmppath, 'repository')) if n.startswith('index')][0] + idx = NSIndex(os.path.join(self.tmppath, 'repository', index_name)) + os.unlink(os.path.join(self.tmppath, 'repository', index_name)) + return list(idx.iteritems()) + self.test2() + self.repository.close() + before = extract_and_unlink_index() + self.open() + self.assert_equal(before, extract_and_unlink_index()) + def test_consistency(self): """Test cache consistency """