From: Zooko O'Whielacronx Date: Tue, 10 Feb 2009 03:08:41 +0000 (-0700) Subject: immutable: tests: assert that verifier gives a clean bill of health after corruption... X-Git-Tag: allmydata-tahoe-1.3.0~54 X-Git-Url: https://git.rkrishnan.org/frontends/$top_link?a=commitdiff_plain;h=5738d94ccd8ae5ae32bd6123e5d88c94b6db7d4d;p=tahoe-lafs%2Ftahoe-lafs.git immutable: tests: assert that verifier gives a clean bill of health after corruption and repair (the previous patch mistakenly did this only after deletion and repair), and also test whether deleting seven other shares and then downloading works. Also count the number of shares stored in the local filesystem. --- diff --git a/src/allmydata/test/common.py b/src/allmydata/test/common.py index 10f14b3b..7c54b938 100644 --- a/src/allmydata/test/common.py +++ b/src/allmydata/test/common.py @@ -984,7 +984,7 @@ class ShareManglingMixin(SystemTestMixin): ks = shares.keys() k = random.choice(ks) self._corrupt_a_share(unused, corruptor_func, k[1]) - return corruptor_func + return k[1] def _count_reads(self): sum_of_read_counts = 0 diff --git a/src/allmydata/test/test_repairer.py b/src/allmydata/test/test_repairer.py index ed74e572..e1a84d4d 100644 --- a/src/allmydata/test/test_repairer.py +++ b/src/allmydata/test/test_repairer.py @@ -60,7 +60,7 @@ class Verifier(common.ShareManglingMixin, unittest.TestCase): self.replace_shares(stash[0], storage_index=self.uri.storage_index) return ignored - def _verify_after_corruption(corruptor_func): + def _verify_after_corruption(shnum, corruptor_func): before_check_reads = self._count_reads() d2 = self.filenode.check(Monitor(), verify=True) def _after_check(checkresults): @@ -77,7 +77,7 @@ class Verifier(common.ShareManglingMixin, unittest.TestCase): for corruptor_func in corruptor_funcs: d.addCallback(self._corrupt_a_random_share, corruptor_func) - d.addCallback(_verify_after_corruption) + d.addCallback(_verify_after_corruption, corruptor_func) d.addCallback(_put_it_all_back) return d @@ -496,13 +496,21 @@ class Repairer(common.ShareManglingMixin, unittest.TestCase): shares = self.find_shares() self.failIf(len(shares) < 10) + # Now we assert that the verifier reports the file as healthy. + d3 = self.filenode.check(Monitor(), verify=True) + def _after_verify(verifyresults): + self.failUnless(verifyresults.is_healthy()) + d3.addCallback(_after_verify) + # Now we delete seven random shares, then try to download the # file and assert that it succeeds at downloading and has the # right contents. - for i in range(7): - self._delete_a_share() - - return self._download_and_check_plaintext() + def _then_delete_7_and_try_a_download(unused=None): + for i in range(7): + self._delete_a_share() + return self._download_and_check_plaintext() + d3.addCallback(_then_delete_7_and_try_a_download) + return d3 d2.addCallback(_after_repair) return d2 @@ -522,7 +530,7 @@ class Repairer(common.ShareManglingMixin, unittest.TestCase): self.replace_shares(stash[0], storage_index=self.uri.storage_index) return ignored - def _repair_from_corruption(unused, corruptor_func): + def _repair_from_corruption(shnum, corruptor_func): before_repair_reads = self._count_reads() before_repair_allocates = self._count_writes() @@ -545,7 +553,31 @@ class Repairer(common.ShareManglingMixin, unittest.TestCase): self.failIf(prerepairres.is_healthy(), (prerepairres.data, corruptor_func)) self.failUnless(postrepairres.is_healthy(), (postrepairres.data, corruptor_func)) - return self._download_and_check_plaintext() + # Now we inspect the filesystem to make sure that it has 10 + # shares. + shares = self.find_shares() + self.failIf(len(shares) < 10) + + # Now we assert that the verifier reports the file as healthy. + d3 = self.filenode.check(Monitor(), verify=True) + def _after_verify(verifyresults): + self.failUnless(verifyresults.is_healthy()) + d3.addCallback(_after_verify) + + # Now we delete seven of the other shares, then try to + # download the file and assert that it succeeds at + # downloading and has the right contents. This can't work + # unless it has already repaired the previously-corrupted share. + def _then_delete_7_and_try_a_download(unused=None): + shnums = range(10) + shnums.remove(shnum) + random.shuffle(shnums) + for sharenum in shnums[:7]: + self._delete_a_share(sharenum=sharenum) + + return self._download_and_check_plaintext() + d3.addCallback(_then_delete_7_and_try_a_download) + return d3 d2.addCallback(_after_repair) return d2