]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
Teach magic-folder to use passed in clock instead of global reactor
authorDavid Stainton <dstainton415@gmail.com>
Thu, 17 Sep 2015 06:59:02 +0000 (08:59 +0200)
committerDaira Hopwood <daira@jacaranda.org>
Thu, 1 Oct 2015 00:19:49 +0000 (01:19 +0100)
src/allmydata/frontends/magic_folder.py

index 11590d569fc5a77204938168e55699c70473005c..c0482e9ab96284b2b209678705aa3a947fab1493 100644 (file)
@@ -46,7 +46,7 @@ class MagicFolder(service.MultiService):
     name = 'magic-folder'
 
     def __init__(self, client, upload_dircap, collective_dircap, local_path_u, dbfile,
-                 pending_delay=1.0):
+                 pending_delay=1.0, clock=reactor):
         precondition_abspath(local_path_u)
 
         service.MultiService.__init__(self)
@@ -61,8 +61,8 @@ class MagicFolder(service.MultiService):
 
         self.is_ready = False
 
-        self.uploader = Uploader(client, local_path_u, db, upload_dircap, pending_delay)
-        self.downloader = Downloader(client, local_path_u, db, collective_dircap)
+        self.uploader = Uploader(client, local_path_u, db, upload_dircap, pending_delay, clock)
+        self.downloader = Downloader(client, local_path_u, db, collective_dircap, clock)
 
     def startService(self):
         # TODO: why is this being called more than once?
@@ -94,12 +94,13 @@ class MagicFolder(service.MultiService):
 
 
 class QueueMixin(HookMixin):
-    def __init__(self, client, local_path_u, db, name):
+    def __init__(self, client, local_path_u, db, name, clock):
         self._client = client
         self._local_path_u = local_path_u
         self._local_filepath = to_filepath(local_path_u)
         self._db = db
         self._name = name
+        self._clock = clock
         self._hooks = {'processed': None, 'started': None}
         self.started_d = self.set_hook('started')
 
@@ -146,7 +147,7 @@ class QueueMixin(HookMixin):
         self._pending.add(relpath_u)
         self._count('objects_queued')
         if self.is_ready:
-            reactor.callLater(0, self._turn_deque)
+            self._clock.callLater(0, self._turn_deque)
 
     def _turn_deque(self):
         if self._stopped:
@@ -161,12 +162,12 @@ class QueueMixin(HookMixin):
             self._lazy_tail.addCallback(lambda ign: self._process(item))
             self._lazy_tail.addBoth(self._call_hook, 'processed')
             self._lazy_tail.addErrback(log.err)
-            self._lazy_tail.addCallback(lambda ign: task.deferLater(reactor, self._turn_delay, self._turn_deque))
+            self._lazy_tail.addCallback(lambda ign: task.deferLater(self._clock, self._turn_delay, self._turn_deque))
 
 
 class Uploader(QueueMixin):
-    def __init__(self, client, local_path_u, db, upload_dircap, pending_delay):
-        QueueMixin.__init__(self, client, local_path_u, db, 'uploader')
+    def __init__(self, client, local_path_u, db, upload_dircap, pending_delay, clock):
+        QueueMixin.__init__(self, client, local_path_u, db, 'uploader', clock)
 
         self.is_ready = False
 
@@ -382,8 +383,8 @@ class Uploader(QueueMixin):
 
 
 class Downloader(QueueMixin):
-    def __init__(self, client, local_path_u, db, collective_dircap):
-        QueueMixin.__init__(self, client, local_path_u, db, 'downloader')
+    def __init__(self, client, local_path_u, db, collective_dircap, clock):
+        QueueMixin.__init__(self, client, local_path_u, db, 'downloader', clock)
 
         # TODO: allow a path rather than a cap URI.
         self._collective_dirnode = self._client.create_node_from_uri(collective_dircap)
@@ -529,7 +530,7 @@ class Downloader(QueueMixin):
         return extension
 
     def _when_queue_is_empty(self):
-        d = task.deferLater(reactor, self._turn_delay, self._scan_remote_collective)
+        d = task.deferLater(self._clock, self._turn_delay, self._scan_remote_collective)
         d.addCallback(lambda ign: self._turn_deque())
         return d