fix some tests
authorDavid Stainton <dstainton415@gmail.com>
Fri, 3 Jul 2015 01:14:24 +0000 (18:14 -0700)
committerDaira Hopwood <daira@jacaranda.org>
Thu, 1 Oct 2015 00:19:44 +0000 (01:19 +0100)
src/allmydata/frontends/magic_folder.py
src/allmydata/test/test_cli_magic_folder.py
src/allmydata/test/test_magic_folder.py

index 3d005fb7b5a2a08c46716a3f8d3475d9018ab6bf..208b9cbff0ccfd050adc3ad6b6ef6fea09cc8035 100644 (file)
@@ -53,6 +53,7 @@ class MagicFolder(service.MultiService):
         self._download_scan_batch = {}
         self._download_lazy_tail = defer.succeed(None)
         self._download_pending = set()
+        self._collective_dirnode = None
         self._client = client
         self._stats_provider = client.stats_provider
         self._convergence = client.convergence
@@ -114,8 +115,6 @@ class MagicFolder(service.MultiService):
                              recursive=True)
 
 
-        self._scan_remote_collective()
-
     def _should_download(self, path, remote_version):
         """
         _should_download returns a bool indicating whether or not a remote object should be downloaded.
@@ -145,6 +144,8 @@ class MagicFolder(service.MultiService):
         return listing_d
 
     def _scan_remote_collective(self):
+        if self._collective_dirnode is None:
+            return
         upload_readonly_dircap = self._upload_dirnode.get_readonly_uri()
         collective_dirmap_d = self._collective_dirnode.list()
         def do_filter(result):
@@ -271,7 +272,7 @@ class MagicFolder(service.MultiService):
             self._log("magic folder upload deque is now empty")
             self._download_lazy_tail = defer.succeed(None)
             self._download_lazy_tail.addCallback(lambda ign: task.deferLater(reactor, self._remote_scan_delay, self._scan_remote_collective))
-            self._download_lazy_tail.addCallback(lambda ign: task.deferLater(reactor, 0, self._turn_download_deque))
+            #self._download_lazy_tail.addCallback(lambda ign: task.deferLater(reactor, 0, self._turn_download_deque))
             return
         self._download_lazy_tail.addCallback(lambda ign: task.deferLater(reactor, 0, self._download_file, file_path, file_node))
         self._download_lazy_tail.addCallback(lambda ign: task.deferLater(reactor, self._remote_scan_delay, self._turn_download_deque))
index df8b84a619ea88e442c2fbfbaa53741abbf2be2a..f716df3f3725123ca408618d6f7473491f344b32 100644 (file)
@@ -107,7 +107,10 @@ class MagicFolderCLITestMixin(CLITestMixin, GridTestMixin):
     def cleanup(self, res):
         d = defer.succeed(None)
         if self.magicfolder is not None:
+            print "CLEANUP"
             d.addCallback(lambda ign: self.magicfolder.finish(for_tests=True))
+        else:
+            print "cannot CLEANUP self.magicfolder is None"
         d.addCallback(lambda ign: res)
         return d
 
index 3c848e80cb08c3e4549c393c5f6a5bc43d08b6ec..bfd2936222c38fd1e0bd25c509f94bbd27b820c5 100644 (file)
@@ -74,7 +74,7 @@ class MagicFolderTestMixin(MagicFolderCLITestMixin, ShouldFailMixin, ReallyEqual
         db = self._createdb()
 
         path = abspath_expanduser_unicode(u"myFile1", base=self.basedir)
-        db.did_upload_file('URI:LIT:1', path, 0, 0, 33)
+        db.did_upload_file('URI:LIT:1', path, 1, 0, 0, 33)
 
         c = db.cursor
         c.execute("SELECT size,mtime,ctime,fileid"
@@ -92,7 +92,7 @@ class MagicFolderTestMixin(MagicFolderCLITestMixin, ShouldFailMixin, ReallyEqual
         size = s[stat.ST_SIZE]
         ctime = s[stat.ST_CTIME]
         mtime = s[stat.ST_MTIME]
-        db.did_upload_file('URI:LIT:2', path, mtime, ctime, size)
+        db.did_upload_file('URI:LIT:2', path, 1, mtime, ctime, size)
         r = db.check_file(path)
         self.failUnless(r.was_uploaded())
 
@@ -207,9 +207,10 @@ class MagicFolderTestMixin(MagicFolderCLITestMixin, ShouldFailMixin, ReallyEqual
 
         self.client = self.g.clients[0]
         self.stats_provider = self.client.stats_provider
+        self.collective_dircap = ""
+
         d = self.create_invite_join_magic_folder(u"Alice", self.local_dir)
         d.addCallback(self._create_magicfolder)
-
         def create_test_file(result):
             d2 = defer.Deferred()
             self.magicfolder.set_processed_callback(d2.callback, ignore_count=0)
@@ -220,20 +221,22 @@ class MagicFolderTestMixin(MagicFolderCLITestMixin, ShouldFailMixin, ReallyEqual
         d.addCallback(create_test_file)
         d.addCallback(lambda ign: self.failUnlessReallyEqual(self._get_count('magic_folder.objects_succeeded'), 1))
         d.addCallback(lambda ign: self.failUnlessReallyEqual(self._get_count('magic_folder.objects_queued'), 0))
-
-        def _restart(ign):
+        
+        def restart(ignore):
             tahoe_config_file = os.path.join(self.get_clientdir(), "tahoe.cfg")
             tahoe_config = fileutil.read(tahoe_config_file)
+            d3 = defer.succeed(None)
             def write_config(client_node_dir):
                 fileutil.write(os.path.join(client_node_dir, "tahoe.cfg"), tahoe_config)
-            self.set_up_grid(client_config_hooks={0: write_config})
-            self.client = self.g.clients[0]
-            self.stats_provider = self.client.stats_provider
-            d.addCallback(self._create_magicfolder)
-            d.addCallback(lambda x: time.sleep(1))
-
-        d.addCallback(self.cleanup)
-        d.addCallback(_restart)
+            def setup_stats(result):
+                self.set_up_grid(client_config_hooks={0: write_config})
+                self.client = self.g.clients[0]
+                self.stats_provider = self.client.stats_provider
+            d3.addBoth(self.cleanup)
+            d3.addCallback(setup_stats)
+            d3.addCallback(self._create_magicfolder)
+            return d3
+        d.addCallback(restart)
         d.addCallback(lambda ign: self.failUnlessReallyEqual(self._get_count('magic_folder.objects_succeeded'), 0))
         d.addCallback(lambda ign: self.failUnlessReallyEqual(self._get_count('magic_folder.objects_queued'), 0))
         d.addBoth(self.cleanup)
@@ -250,6 +253,7 @@ class MagicFolderTestMixin(MagicFolderCLITestMixin, ShouldFailMixin, ReallyEqual
         d = self.client.create_dirnode()
 
         d.addCallback(self._made_upload_dir)
+        self.collective_dircap = ""
         d.addCallback(self._create_magicfolder)
 
         # Write something short enough for a LIT file.