Workaround.
authorDaira Hopwood <daira@jacaranda.org>
Tue, 3 Nov 2015 02:53:57 +0000 (02:53 +0000)
committerDaira Hopwood <daira@jacaranda.org>
Mon, 28 Dec 2015 15:32:36 +0000 (15:32 +0000)
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
src/allmydata/frontends/magic_folder.py
src/allmydata/test/test_cli_magic_folder.py

index 0a5211aefe30552cb2a97eecf214b3e09e111438..8150246749bf9d005e8b681b78b48400c41c6eb0 100644 (file)
@@ -46,11 +46,13 @@ class MagicFolder(service.MultiService):
     name = 'magic-folder'
 
     def __init__(self, client, upload_dircap, collective_dircap, local_path_u, dbfile,
-                 pending_delay=1.0, clock=reactor):
+                 pending_delay=1.0, clock=None):
         precondition_abspath(local_path_u)
 
         service.MultiService.__init__(self)
 
+        immediate = clock is not None
+        clock = clock or reactor
         db = magicfolderdb.get_magicfolderdb(dbfile, create_version=(magicfolderdb.SCHEMA_v1, 1))
         if db is None:
             return Failure(Exception('ERROR: Unable to load magic folder db.'))
@@ -62,7 +64,7 @@ class MagicFolder(service.MultiService):
         upload_dirnode = self._client.create_node_from_uri(upload_dircap)
         collective_dirnode = self._client.create_node_from_uri(collective_dircap)
 
-        self.uploader = Uploader(client, local_path_u, db, upload_dirnode, pending_delay, clock)
+        self.uploader = Uploader(client, local_path_u, db, upload_dirnode, pending_delay, clock, immediate)
         self.downloader = Downloader(client, local_path_u, db, collective_dirnode, upload_dirnode.get_readonly_uri(), clock)
 
     def startService(self):
@@ -163,10 +165,12 @@ class QueueMixin(HookMixin):
 
 
 class Uploader(QueueMixin):
-    def __init__(self, client, local_path_u, db, upload_dirnode, pending_delay, clock):
+    def __init__(self, client, local_path_u, db, upload_dirnode, pending_delay, clock,
+                 immediate=False):
         QueueMixin.__init__(self, client, local_path_u, db, 'uploader', clock)
 
         self.is_ready = False
+        self._immediate = immediate
 
         if not IDirectoryNode.providedBy(upload_dirnode):
             raise AssertionError("The URI in '%s' does not refer to a directory."
@@ -288,7 +292,10 @@ class Uploader(QueueMixin):
         self._pending.add(relpath_u)
         self._count('objects_queued')
         if self.is_ready:
-            self._clock.callLater(0, self._turn_deque)
+            if self._immediate:  # for tests
+                self._turn_deque()
+            else:
+                self._clock.callLater(0, self._turn_deque)
 
     def _when_queue_is_empty(self):
         return defer.succeed(None)
index 960b031bd32c842b46eb5171a842c3fc0d197d1d..866958e84f0b3b2c33cf02d5932558ff4a476f5d 100644 (file)
@@ -115,15 +115,6 @@ class MagicFolderCLITestMixin(CLITestMixin, GridTestMixin):
                                        dbfile, pending_delay=0.2, clock=clock)
         magicfolder.downloader._turn_delay = 0
 
-        orig = magicfolder.uploader._append_to_deque
-        # the _append_to_deque method queues a _turn_deque, so we
-        # immediately trigger it by wrapping _append_to_deque
-        def wrap(*args, **kw):
-            x = orig(*args, **kw)
-            clock.advance(0)  # _turn_delay is always 0 for the tests
-            return x
-        magicfolder.uploader._append_to_deque = wrap
-
         magicfolder.setServiceParent(self.get_client(client_num))
         magicfolder.ready()
         return magicfolder