]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
make the system test work
authorBrian Warner <warner@lothar.com>
Sun, 3 Dec 2006 07:56:27 +0000 (00:56 -0700)
committerBrian Warner <warner@lothar.com>
Sun, 3 Dec 2006 07:56:27 +0000 (00:56 -0700)
allmydata/test/test_system.py
allmydata/upload.py

index 7b7ad7b93908559064742dffe562e049ac81dd7c..e04ce620db553d35ef43f237fd43afa7ef628b2c 100644 (file)
@@ -14,51 +14,64 @@ class SystemTest(unittest.TestCase):
     def tearDown(self):
         d = self.sparent.stopService()
         d.addCallback(lambda res: flushEventualQueue())
+        def _done(res):
+            d1 = defer.Deferred()
+            reactor.callLater(0.1, d1.callback, None)
+            return d1
+        d.addCallback(_done)
         return d
 
-    def addService(self, s):
+    def add_service(self, s):
         s.setServiceParent(self.sparent)
         return s
 
-    def setUpNodes(self, NUMCLIENTS=5):
+    def set_up_nodes(self, NUMCLIENTS=5):
+        self.numclients = NUMCLIENTS
         if not os.path.isdir("queen"):
             os.mkdir("queen")
-        q = self.queen = self.addService(queen.Queen(basedir="queen"))
-        queen_pburl = q.urls["roster"]
-        clients = self.clients = []
-
+        q = self.queen = self.add_service(queen.Queen(basedir="queen"))
+        self.queen_pburl = q.urls["roster"]
+        self.clients = []
         for i in range(NUMCLIENTS):
             basedir = "client%d" % i
             if not os.path.isdir(basedir):
                 os.mkdir(basedir)
-            c = self.addService(client.Client(basedir=basedir))
-            c.set_queen_pburl(queen_pburl)
-            clients.append(c)
+            c = self.add_service(client.Client(basedir=basedir))
+            c.set_queen_pburl(self.queen_pburl)
+            self.clients.append(c)
+        log.msg("STARTING")
+        return self.wait_for_connections()
 
-
-    def waitForConnections(self):
-        # the cheap way: time
-        d = defer.Deferred()
-        reactor.callLater(1, d.callback, None)
-        return d
+    def wait_for_connections(self, ignored=None):
+        for c in self.clients:
+            if len(c.connections) != self.numclients - 1:
+                d = defer.Deferred()
+                d.addCallback(self.wait_for_connections)
+                reactor.callLater(0.05, d.callback, None)
+                return d
+        return defer.succeed(None)
 
     def test_connections(self):
-        self.setUpNodes()
-        d = self.waitForConnections()
+        d = self.set_up_nodes()
         def _check(res):
-            log.msg("CHECKING")
             for c in self.clients:
                 self.failUnlessEqual(len(c.connections), 4)
         d.addCallback(_check)
         return d
+    test_connections.timeout = 20
 
     def test_upload(self):
-        self.setUpNodes()
-        d = self.waitForConnections()
+        d = self.set_up_nodes()
         def _upload(res):
-            log.msg("DONE")
+            log.msg("UPLOADING")
             u = self.clients[0].getServiceNamed("uploader")
-            d1 = u.upload_data("Some data to upload")
+            d1 = u.upload_data("Some data to upload\n")
             return d1
         d.addCallback(_upload)
+        def _done(res):
+            log.msg("DONE")
+            print "upload finished"
+        d.addCallback(_done)
         return d
+    test_upload.timeout = 20
+
index 222c89988a21f5397a32648e88ea06645eb315aa..3205367e23fc0a326eecf6efd961a4a00b26df60 100644 (file)
@@ -33,8 +33,8 @@ class FileUploader:
         filehandle.seek(0)
 
     def make_encoder(self):
-        self._encoder = encode.Encoder(self._filehandle, 4)
         self._shares = 4
+        self._encoder = encode.Encoder(self._filehandle, self._shares)
         self._share_size = self._size
 
     def set_verifierid(self, vid):