]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
dirnode deep-check: add tests of cycles, fix failures
authorBrian Warner <warner@allmydata.com>
Thu, 17 Jul 2008 21:37:04 +0000 (14:37 -0700)
committerBrian Warner <warner@allmydata.com>
Thu, 17 Jul 2008 21:37:04 +0000 (14:37 -0700)
src/allmydata/dirnode.py
src/allmydata/test/test_dirnode.py

index 31066b536ae936a276a09947ea28330f88b0dc05..f0c2e5e36f4b994050942def5ff21107d59b3866 100644 (file)
@@ -561,13 +561,13 @@ class NewDirectoryNode:
             def _got_children(children):
                 dl = []
                 for name, (child, metadata) in children.iteritems():
-                    d2 = self._add_deepcheck_from_node(child,
-                                                       results, limiter,
+                    d2 = self._add_deepcheck_from_node(child, results,
+                                                       found, limiter,
                                                        verify, repair)
                     if d2:
-                        dl.append(d1)
+                        dl.append(d2)
                 if dl:
-                    return defer.DeferredList(dl)
+                    return defer.DeferredList(dl, fireOnOneErrback=True)
             d.addCallback(_got_children)
         return d
 
index 044a84851adbb841e83f87d63c493ebc3db97f5d..84d51b0e1ea81f3698865e70831d064c18585a45 100644 (file)
@@ -2,8 +2,9 @@
 import time
 from zope.interface import implements
 from twisted.trial import unittest
+from twisted.internet import defer
 from allmydata import uri, dirnode
-from allmydata.immutable import upload
+from allmydata.immutable import upload, checker
 from allmydata.interfaces import IURI, IClient, IMutableFileNode, \
      INewDirectoryURI, IReadonlyNewDirectoryURI, IFileNode, ExistingChildError
 from allmydata.util import hashutil, testutil
@@ -31,6 +32,12 @@ class Marker:
     def get_verifier(self):
         return self.verifieruri
 
+    def check(self, verify=False, repair=False):
+        r = checker.Results(None)
+        r.healthy = True
+        r.problems = []
+        return defer.succeed(r)
+
 # dirnode requires three methods from the client: upload(),
 # create_node_from_uri(), and create_empty_dirnode(). Of these, upload() is
 # only used by the convenience composite method add_file().
@@ -118,10 +125,22 @@ class Dirnode(unittest.TestCase, testutil.ShouldFailMixin, testutil.StallMixin):
         return d
 
     def _test_deepcheck_create(self):
+        # create a small tree with a loop, and some non-directories
+        #  root/
+        #  root/subdir/
+        #  root/subdir/file1
+        #  root/subdir/link -> root
         d = self.client.create_empty_dirnode()
         def _created_root(rootnode):
             self._rootnode = rootnode
+            return rootnode.create_empty_directory(u"subdir")
         d.addCallback(_created_root)
+        def _created_subdir(subdir):
+            self._subdir = subdir
+            d = subdir.add_file(u"file1", upload.Data("data", None))
+            d.addCallback(lambda res: subdir.set_node(u"link", self._rootnode))
+            return d
+        d.addCallback(_created_subdir)
         def _done(res):
             return self._rootnode
         d.addCallback(_done)
@@ -131,8 +150,8 @@ class Dirnode(unittest.TestCase, testutil.ShouldFailMixin, testutil.StallMixin):
         d = self._test_deepcheck_create()
         d.addCallback(lambda rootnode: rootnode.deep_check())
         def _check_results(r):
-            self.failUnlessEqual(r.count_objects_checked(), 1)
-            self.failUnlessEqual(r.count_objects_healthy(), 1)
+            self.failUnlessEqual(r.count_objects_checked(), 3)
+            self.failUnlessEqual(r.count_objects_healthy(), 3)
             self.failUnlessEqual(r.count_repairs_attempted(), 0)
             self.failUnlessEqual(r.count_repairs_successful(), 0)
             self.failUnlessEqual(len(r.get_server_problems()), 0)