From: David Stainton Date: Mon, 20 Apr 2015 20:15:14 +0000 (+0100) Subject: Fixed move tree test and cleaned up persistence test X-Git-Url: https://git.rkrishnan.org/?a=commitdiff_plain;h=81e89f503d804cd3221434282b39205bcbf5fbf4;p=tahoe-lafs%2Ftahoe-lafs.git Fixed move tree test and cleaned up persistence test - the persistence test does not yet work --- diff --git a/src/allmydata/frontends/drop_upload.py b/src/allmydata/frontends/drop_upload.py index 72024238..8c6d0ba9 100644 --- a/src/allmydata/frontends/drop_upload.py +++ b/src/allmydata/frontends/drop_upload.py @@ -114,6 +114,9 @@ class DropUploader(service.MultiService): elif isdir: # recurse on the child directory self._scan(childpath) + must_upload = self._check_db_file(childpath) + if must_upload: + self._append_to_deque(childpath) elif isfile: must_upload = self._check_db_file(childpath) if must_upload: @@ -152,6 +155,7 @@ class DropUploader(service.MultiService): def _append_to_deque(self, path): self._upload_deque.append(path) self._pending.add(path) + self._stats_provider.count('drop_upload.objects_queued', 1) if self.is_upload_ready: reactor.callLater(0, self._turn_deque) @@ -166,7 +170,6 @@ class DropUploader(service.MultiService): def _notify(self, opaque, path, events_mask): self._log("inotify event %r, %r, %r\n" % (opaque, path, ', '.join(self._inotify.humanReadableMask(events_mask)))) - self._stats_provider.count('drop_upload.objects_queued', 1) if path.path not in self._pending: self._append_to_deque(path.path) @@ -185,20 +188,20 @@ class DropUploader(service.MultiService): return self._parent.add_file(name, u) def _add_dir(ignore): - print "_add_dir %s" % (path,) self._pending.remove(path) name = os.path.basename(path) dirname = path # on Windows the name is already Unicode if sys.platform != "win32": name = name.decode(get_filesystem_encoding()) - dirname = path.decode(get_filesystem_encoding()) + # XXX + #dirname = path.decode(get_filesystem_encoding()) + dirname = path reactor.callLater(0, self._scan, dirname) return self._parent.create_subdirectory(name) def _maybe_upload(val): - print "in _maybe_upload" if not os.path.exists(path): self._log("uploader: not uploading non-existent file.") self._stats_provider.count('drop_upload.objects_disappeared', 1) @@ -241,7 +244,6 @@ class DropUploader(service.MultiService): return d def _do_upload_callback(self, res): - print "in _do_upload_callback" if self._ignore_count == 0: self._uploaded_callback(res) else: @@ -262,6 +264,9 @@ class DropUploader(service.MultiService): else: return defer.succeed(None) + def remove_service(self): + return service.MultiService.disownServiceParent(self) + def _log(self, msg): self._client.log(msg) #open("events", "ab+").write(msg) diff --git a/src/allmydata/test/no_network.py b/src/allmydata/test/no_network.py index 8dd9a2f9..ee7a049a 100644 --- a/src/allmydata/test/no_network.py +++ b/src/allmydata/test/no_network.py @@ -174,6 +174,9 @@ class NoNetworkStorageBroker: return None class NoNetworkClient(Client): + + def disownParentService(self): + pass def create_tub(self): pass def init_introducer_client(self): diff --git a/src/allmydata/test/test_drop_upload.py b/src/allmydata/test/test_drop_upload.py index 505e2347..4ab434f2 100644 --- a/src/allmydata/test/test_drop_upload.py +++ b/src/allmydata/test/test_drop_upload.py @@ -7,9 +7,9 @@ from twisted.trial import unittest from twisted.python import runtime from twisted.python.filepath import FilePath from twisted.internet import defer +from twisted.application import service from allmydata.interfaces import IDirectoryNode, NoSuchChildError - from allmydata.util import fileutil, fake_inotify from allmydata.util.encodingutil import get_filesystem_encoding from allmydata.util.consumer import download_to_data @@ -37,6 +37,10 @@ class DropUploadTestMixin(GridTestMixin, ShouldFailMixin, ReallyEqualMixin, NonA return bdb def _made_upload_dir(self, n): + if self.dir_node == None: + self.dir_node = n + else: + n = self.dir_node self.failUnless(IDirectoryNode.providedBy(n)) self.upload_dirnode = n self.upload_dircap = n.get_uri() @@ -88,21 +92,18 @@ class DropUploadTestMixin(GridTestMixin, ShouldFailMixin, ReallyEqualMixin, NonA d.addCallback(self._made_upload_dir) def testMoveEmptyTree(res): - print "moving tree into %s" % self.local_dir - tree_dir = os.path.join(self.basedir, 'apple_tree') - tree_dir_fp = FilePath(tree_dir) + tree_name = 'empty_tree' + tree_dir = os.path.join(self.basedir, tree_name) + os.mkdir(tree_dir) + d2 = defer.Deferred() self.uploader.set_uploaded_callback(d2.callback, ignore_count=0) - os.mkdir(tree_dir) - self.notify_close_write(tree_dir_fp) - os.rename(tree_dir, os.path.join(self.local_dir, 'apple_tree')) - self.notify_close_write(tree_dir_fp) + new_tree_dir = os.path.join(self.local_dir, tree_name) + os.rename(tree_dir, new_tree_dir) + self.notify_close_write(FilePath(new_tree_dir)) return d2 d.addCallback(testMoveEmptyTree) - def _print(ign): - print "in _print" - d.addCallback(_print) d.addCallback(lambda ign: self.failUnlessReallyEqual(self._get_count('drop_upload.objects_uploaded'), 1)) d.addCallback(lambda ign: self.failUnlessReallyEqual(self._get_count('drop_upload.files_uploaded'), 0)) d.addCallback(lambda ign: self.failUnlessReallyEqual(self._get_count('drop_upload.objects_queued'), 0)) @@ -115,8 +116,14 @@ class DropUploadTestMixin(GridTestMixin, ShouldFailMixin, ReallyEqualMixin, NonA f = open(os.path.join(tree_dir, 'what'), "wb") f.write("meow") f.close() - os.rename(tree_dir, os.path.join(self.local_dir, tree_name)) - return res + + d2 = defer.Deferred() + self.uploader.set_uploaded_callback(d2.callback, ignore_count=1) + + new_tree_dir = os.path.join(self.local_dir, tree_name) + os.rename(tree_dir, new_tree_dir) + self.notify_close_write(FilePath(new_tree_dir)) + return d2 d.addCallback(testMoveSmallTree) d.addCallback(lambda ign: self.failUnlessReallyEqual(self._get_count('drop_upload.objects_uploaded'), 3)) @@ -129,6 +136,8 @@ class DropUploadTestMixin(GridTestMixin, ShouldFailMixin, ReallyEqualMixin, NonA def _test_persistence(self): self.uploader = None + self.dir_node = None + self.set_up_grid() self.local_dir = os.path.join(self.basedir, u"test_persistence") self.mkdir_nonascii(self.local_dir) @@ -140,14 +149,22 @@ class DropUploadTestMixin(GridTestMixin, ShouldFailMixin, ReallyEqualMixin, NonA d.addCallback(self._made_upload_dir) d.addCallback(lambda ign: self.uploader.Pause()) d.addCallback(lambda ign: self.failUnlessReallyEqual(self._get_count('drop_upload.objects_uploaded'), 0)) + d.addCallback(lambda ign: self.failUnlessReallyEqual(self._get_count('drop_upload.objects_queued'), 0)) def create_file(val): - print "creating file..." myFile = os.path.join(self.local_dir, "what") f = open(myFile, "wb") f.write("meow") f.close() + # XXX + #self.notify_close_write(FilePath(myFile)) return None d.addCallback(create_file) + d.addCallback(self._cleanup) + #d.addCallback(lambda ign: self.client.stopService()) + #d.addCallback(lambda ign: self.client.disownParentService(self)) + #d.addCallback(lambda ign: self.client.startService()) + d.addCallback(self._made_upload_dir) + def resume_uploader(val): self.uploader.Resume() d = defer.Deferred() @@ -162,6 +179,7 @@ class DropUploadTestMixin(GridTestMixin, ShouldFailMixin, ReallyEqualMixin, NonA def _test(self): self.uploader = None + self.dir_node = None self.set_up_grid() self.local_dir = os.path.join(self.basedir, self.unicode_or_fallback(u"loc\u0101l_dir", u"local_dir")) self.mkdir_nonascii(self.local_dir)