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)
+ 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
- def setup_alice_and_bob(self, clock=reactor):
+ def setup_alice_and_bob(self, alice_clock=reactor, bob_clock=reactor):
self.set_up_grid(num_clients=2)
alice_magic_dir = abspath_expanduser_unicode(u"Alice-magic", base=self.basedir)
d.addCallback(lambda x: self.check_joined_config(0, self.alice_upload_dircap))
d.addCallback(lambda x: self.check_config(0, alice_magic_dir))
def get_Alice_magicfolder(result):
- self.alice_magicfolder = self.init_magicfolder(0, self.alice_upload_dircap, self.alice_collective_dircap, alice_magic_dir, clock)
+ self.alice_magicfolder = self.init_magicfolder(0, self.alice_upload_dircap, self.alice_collective_dircap, alice_magic_dir, alice_clock)
return result
d.addCallback(get_Alice_magicfolder)
d.addCallback(lambda x: self.check_joined_config(1, self.bob_upload_dircap))
d.addCallback(lambda x: self.check_config(1, bob_magic_dir))
def get_Bob_magicfolder(result):
- self.bob_magicfolder = self.init_magicfolder(1, self.bob_upload_dircap, self.bob_collective_dircap, bob_magic_dir, clock)
+ self.bob_magicfolder = self.init_magicfolder(1, self.bob_upload_dircap, self.bob_collective_dircap, bob_magic_dir, bob_clock)
return result
d.addCallback(get_Bob_magicfolder)
import os, sys
from twisted.trial import unittest
-from twisted.internet import defer
+from twisted.internet import defer, task
from allmydata.interfaces import IDirectoryNode
self.failUnlessEqual(version, expected_version)
def test_alice_bob(self):
- d = self.setup_alice_and_bob()
+ alice_clock = task.Clock()
+ bob_clock = task.Clock()
+ d = self.setup_alice_and_bob(alice_clock, bob_clock)
def get_results(result):
# XXX are these used?
(self.alice_collective_dircap, self.alice_upload_dircap, self.alice_magicfolder,
def Alice_wait_for_upload(result):
print "Alice waits for an upload\n"
d2 = self.alice_magicfolder.uploader.set_hook('processed')
+ alice_clock.advance(0)
return d2
d.addCallback(Alice_wait_for_upload)
d.addCallback(lambda ign: self._check_version_in_dmd(self.alice_magicfolder, u"file1", 0))
def Bob_wait_for_download(result):
print "Bob waits for a download\n"
d2 = self.bob_magicfolder.downloader.set_hook('processed')
+ bob_clock.advance(0)
return d2
d.addCallback(Bob_wait_for_download)
d.addCallback(lambda ign: self._check_version_in_local_db(self.bob_magicfolder, u"file1", 0))
print "Alice deletes the file!\n"
os.unlink(self.file_path)
self.notify(to_filepath(self.file_path), self.inotify.IN_DELETE)
-
+ alice_clock.advance(0)
return None
d.addCallback(Alice_delete_file)
d.addCallback(Alice_wait_for_upload)
def Alice_rewrite_file(result):
print "Alice rewrites file\n"
+ self.magicfolder = self.alice_magicfolder
self.file_path = abspath_expanduser_unicode(u"file1", base=self.alice_magicfolder.uploader._local_path_u)
fileutil.write(self.file_path, "Alice suddenly sees the white rabbit running into the forest.")
- self.magicfolder = self.alice_magicfolder
self.notify(to_filepath(self.file_path), self.inotify.IN_CLOSE_WRITE)
d.addCallback(Alice_rewrite_file)
print "cleanup alice bob test\n"
d = defer.succeed(None)
d.addCallback(lambda ign: self.alice_magicfolder.finish())
- d.addCallback(lambda ign: self.bob_magicfolder.finish())
- d.addCallback(lambda ign: result)
+
+ def clean_bob(_):
+ d2 = self.bob_magicfolder.finish()
+ d2.addCallback(lambda ign: result)
+ bob_clock.advance(0)
+ return d2
+ d.addCallback(clean_bob)
+ alice_clock.advance(0)
return d
d.addCallback(cleanup_Alice_and_Bob)
return d