Add cleanup to Alice+Bob test + bug fix
authorDavid Stainton <dstainton415@gmail.com>
Mon, 29 Jun 2015 23:23:18 +0000 (16:23 -0700)
committerDaira Hopwood <daira@jacaranda.org>
Tue, 15 Sep 2015 16:56:00 +0000 (17:56 +0100)
bug fix == don't clobber the alice bob magicfolder instances

src/allmydata/frontends/magic_folder.py
src/allmydata/test/test_cli_magic_folder.py

index 4827b2457d670398bd0289832b86dcde0540531e..8131cad7d9588f0e34d174ffd045b071e1c4acb0 100644 (file)
@@ -304,5 +304,5 @@ class MagicFolder(service.MultiService):
 
     def _log(self, msg):
         self._client.log("drop-upload: " + msg)
-        print "_log %s" % (msg,)
+        #print "_log %s" % (msg,)
         #open("events", "ab+").write(msg)
index 12e5bde9e0c46debcf7273438829c56726925140..407a048cd7088ee6df19e956f3e70e42376ed215 100644 (file)
@@ -111,10 +111,11 @@ class MagicFolderCLITestMixin(CLITestMixin, GridTestMixin):
 
     def init_magicfolder(self, client_num, upload_dircap, collective_dircap, local_magic_dir):
         dbfile = abspath_expanduser_unicode(u"magicfolderdb.sqlite", base=self.get_clientdir(i=client_num))
-        self.magicfolder = MagicFolder(self.get_client(client_num), upload_dircap, collective_dircap, local_magic_dir,
+        magicfolder = MagicFolder(self.get_client(client_num), upload_dircap, collective_dircap, local_magic_dir,
                                        dbfile, inotify=self.inotify, pending_delay=0.2)
-        self.magicfolder.setServiceParent(self.get_client(client_num))
-        self.magicfolder.upload_ready()
+        magicfolder.setServiceParent(self.get_client(client_num))
+        magicfolder.upload_ready()
+        return magicfolder
 
     def setup_alice_and_bob(self):
         self.set_up_grid(num_clients=2)
@@ -126,7 +127,6 @@ class MagicFolderCLITestMixin(CLITestMixin, GridTestMixin):
         self.mkdir_nonascii(bob_dir)
         bob_magic_dir = abspath_expanduser_unicode(u"Bob-magic", base=self.basedir)
         self.mkdir_nonascii(bob_magic_dir)
-
         d = self.create_magic_folder(0)
         d.addCallback(lambda x: self.invite_n(0, x))
         d.addCallback(lambda x: self.join(0, alice_magic_dir, x))
@@ -135,8 +135,10 @@ class MagicFolderCLITestMixin(CLITestMixin, GridTestMixin):
         d.addCallback(get_alice_caps)
         d.addCallback(lambda x: self.check_joined_config(0, alice_upload_dircap))
         d.addCallback(lambda x: self.check_config(0, alice_magic_dir))
-        d.addCallback(lambda x: self.init_magicfolder(0, alice_upload_dircap, alice_collective_dircap, alice_magic_dir))
-
+        def get_Alice_magicfolder(result):
+            self.alice_magicfolder = self.init_magicfolder(0, alice_upload_dircap, alice_collective_dircap, alice_magic_dir)
+            return result
+        d.addCallback(get_Alice_magicfolder)
         d.addCallback(lambda x: self.invite_n(0, u"Bob"))
         d.addCallback(lambda x: self.join(1, bob_magic_dir, x))
         def get_bob_caps(x):
@@ -144,8 +146,18 @@ class MagicFolderCLITestMixin(CLITestMixin, GridTestMixin):
         d.addCallback(get_bob_caps)
         d.addCallback(lambda x: self.check_joined_config(1, bob_upload_dircap))
         d.addCallback(lambda x: self.check_config(1, bob_magic_dir))
-        d.addCallback(lambda x: self.init_magicfolder(1, bob_upload_dircap, bob_collective_dircap, bob_magic_dir))
-
+        def get_Bob_magicfolder(result):
+            self.bob_magicfolder = self.init_magicfolder(1, bob_upload_dircap, bob_collective_dircap, bob_magic_dir)
+            return result
+        d.addCallback(get_Bob_magicfolder)
+
+        def cleanup_Alice_and_Bob(result):
+            d = defer.succeed(None)
+            d.addCallback(lambda ign: self.alice_magicfolder.finish(for_tests=True))
+            d.addCallback(lambda ign: self.bob_magicfolder.finish(for_tests=True))
+            d.addCallback(lambda ign: result)
+            return d
+        d.addCallback(cleanup_Alice_and_Bob)
         return d
 
 class CreateMagicFolder(MagicFolderCLITestMixin, unittest.TestCase):