From: Daira Hopwood Date: Tue, 28 Apr 2015 18:46:43 +0000 (+0100) Subject: Fixed move tree test and cleaned up persistence test X-Git-Url: https://git.rkrishnan.org/nxhtml.html?a=commitdiff_plain;h=73889dbdd50f90ed2c9821d4d35b3c034bf66b86;p=tahoe-lafs%2Ftahoe-lafs.git Fixed move tree test and cleaned up persistence test Signed-off-by: Daira Hopwood --- diff --git a/src/allmydata/frontends/drop_upload.py b/src/allmydata/frontends/drop_upload.py index 84d1b9b8..ca900191 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: @@ -157,6 +160,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) @@ -171,7 +175,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) @@ -190,20 +193,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) @@ -246,7 +249,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: @@ -267,6 +269,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 276f2220..92b2a918 100644 --- a/src/allmydata/test/test_drop_upload.py +++ b/src/allmydata/test/test_drop_upload.py @@ -7,6 +7,7 @@ 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 @@ -37,6 +38,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 +93,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 +117,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 +137,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 +150,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 +180,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)