]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
improve test coverage on FileNode.check
authorBrian Warner <warner@allmydata.com>
Tue, 4 Dec 2007 22:55:27 +0000 (15:55 -0700)
committerBrian Warner <warner@allmydata.com>
Tue, 4 Dec 2007 22:55:27 +0000 (15:55 -0700)
src/allmydata/checker.py
src/allmydata/test/test_dirnode.py
src/allmydata/test/test_system.py

index 2281191669592aa97d2e7b436e567cf6885540c9..af11ecc30956a11ff82a2ff111c46f56107ec89c 100644 (file)
@@ -228,10 +228,10 @@ class Checker(service.MultiService):
                 self.results = InMemoryCheckerResults()
 
     def check(self, uri_to_check):
-        uri_to_check = IVerifierURI(uri_to_check)
         if uri_to_check is None:
             return defer.succeed(True)
-        elif isinstance(uri_to_check, uri.CHKFileVerifierURI):
+        uri_to_check = IVerifierURI(uri_to_check)
+        if isinstance(uri_to_check, uri.CHKFileVerifierURI):
             peer_getter = self.parent.get_permuted_peers
             c = SimpleCHKFileChecker(peer_getter, uri_to_check)
             d = c.check()
index 76c5a804785cb1b0039c0d20ba71bfacb7cf103b..328f692b87f62db4381f0566ac85bc9fafa2ba4f 100644 (file)
@@ -141,6 +141,7 @@ class Dirnode(unittest.TestCase, testutil.ShouldFailMixin):
                 # end of the string. Flip one of its bits and make sure we
                 # detect the corruption.
                 new_contents = testutil.flip_bit(old_contents, -10)
+                # TODO: also test flipping bits in the other portions
                 filenode.all_contents[si] = new_contents
             d.addCallback(_corrupt)
             def _check2(res):
@@ -300,6 +301,7 @@ class Dirnode(unittest.TestCase, testutil.ShouldFailMixin):
 
         return d
 
+
 netstring = hashutil.netstring
 split_netstring = dirnode.split_netstring
 
index a9016cbdc3fa937e2b2a4bf437b674363cde24d8..9711991406c82c62f11d50393b689424042757a1 100644 (file)
@@ -577,6 +577,11 @@ class SystemTest(testutil.SignalMixin, unittest.TestCase):
         d.addCallback(self._test_web_start)
         d.addCallback(self._test_control)
         d.addCallback(self._test_cli)
+        # P now has four top-level children:
+        # P/personal/sekrit data
+        # P/s2-ro/
+        # P/s2-rw/
+        # P/test_put/  (empty)
         d.addCallback(self._test_checker)
         d.addCallback(self._test_verifier)
         return d
@@ -1196,8 +1201,37 @@ class SystemTest(testutil.SignalMixin, unittest.TestCase):
                 all_results.append(those_results)
             _check_checker_results(all_results)
         d.addCallback(_check_stored_results)
+
+        d.addCallback(self._test_checker_3)
+        return d
+
+    def _test_checker_3(self, res):
+        # check one file, through FileNode.check()
+        d = self._private_node.get_child_at_path("personal/sekrit data")
+        d.addCallback(lambda n: n.check())
+        def _checked(results):
+            # 'sekrit data' is small, and fits in a LiteralFileNode, so
+            # checking it is trivial and always returns True
+            self.failUnlessEqual(results, True)
+        d.addCallback(_checked)
+
+        c0 = self.clients[1]
+        n = c0.create_node_from_uri(self._root_directory_uri)
+        d.addCallback(lambda res: n.get_child_at_path("subdir1/mydata567"))
+        d.addCallback(lambda n: n.check())
+        def _checked2(results):
+            # mydata567 is large and lives in a CHK
+            (needed, total, found, sharemap) = results
+            self.failUnlessEqual(needed, 3)
+            self.failUnlessEqual(total, 10)
+            self.failUnlessEqual(found, 10)
+            self.failUnlessEqual(len(sharemap), 10)
+            for shnum in range(10):
+                self.failUnlessEqual(len(sharemap[shnum]), 1)
+        d.addCallback(_checked2)
         return d
 
+
     def _test_verifier(self, res):
         checker1 = self.clients[1].getServiceNamed("checker")
         d = self._private_node.build_manifest()