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.'))
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):
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."
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)
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