]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
Add _advance_clock callback and remove 'immediate' attribute. 2553.refactor.1
authorDaira Hopwood <daira@jacaranda.org>
Tue, 3 Nov 2015 15:38:55 +0000 (15:38 +0000)
committerDaira Hopwood <daira@jacaranda.org>
Tue, 3 Nov 2015 15:38:55 +0000 (15:38 +0000)
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
src/allmydata/frontends/magic_folder.py
src/allmydata/test/test_cli_magic_folder.py

index 532d2de8c6f4eb78e57018bb2175403171d98879..026f7de28f1da07cc10558b25af7a8eab8f80903 100644 (file)
@@ -51,7 +51,6 @@ class MagicFolder(service.MultiService):
 
         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:
@@ -64,7 +63,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, immediate)
+        self.uploader = Uploader(client, local_path_u, db, upload_dirnode, pending_delay, clock)
         self.downloader = Downloader(client, local_path_u, db, collective_dirnode, upload_dirnode.get_readonly_uri(), clock)
 
     def startService(self):
@@ -165,12 +164,11 @@ class QueueMixin(HookMixin):
 
 
 class Uploader(QueueMixin):
-    def __init__(self, client, local_path_u, db, upload_dirnode, pending_delay, clock,
-                 immediate=False):
+    def __init__(self, client, local_path_u, db, upload_dirnode, pending_delay, clock):
         QueueMixin.__init__(self, client, local_path_u, db, 'uploader', 0, clock)
 
         self.is_ready = False
-        self._immediate = immediate
+        self._advance_clock = lambda: None
 
         if not IDirectoryNode.providedBy(upload_dirnode):
             raise AssertionError("The URI in '%s' does not refer to a directory."
@@ -282,15 +280,10 @@ class Uploader(QueueMixin):
             self._deque.append(relpath_u)
             self._count('objects_queued')
             if self.is_ready:
-                if self._immediate:  # for tests
-                    self._turn_deque()
-                else:
-                    self._clock.callLater(0, self._turn_deque)
+                self._clock.callLater(0, self._turn_deque)
+                self._advance_clock()
 
-        if self._immediate:
-            _do_append()
-        else:
-            self._clock.callLater(self._pending_delay, _do_append)
+        self._clock.callLater(self._pending_delay, _do_append)
 
     def _when_queue_is_empty(self):
         return defer.succeed(None)
index e7f2c511c3a22afce945db8ec1b63ed0b78406bb..7a85fc814d279462f35785673286592f85677a72 100644 (file)
@@ -112,7 +112,9 @@ class MagicFolderCLITestMixin(CLITestMixin, GridTestMixin):
     def init_magicfolder(self, client_num, upload_dircap, collective_dircap, local_magic_dir, clock):
         dbfile = abspath_expanduser_unicode(u"magicfolderdb.sqlite", base=self.get_clientdir(i=client_num))
         magicfolder = MagicFolder(self.get_client(client_num), upload_dircap, collective_dircap, local_magic_dir,
-                                       dbfile, pending_delay=0.2, clock=clock)
+                                  dbfile, pending_delay=0.2, clock=clock)
+
+        magicfolder.uploader._advance_clock = lambda: clock.advance(0)
 
         magicfolder.setServiceParent(self.get_client(client_num))
         magicfolder.ready()