]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
fix check-memory test, with new new (safe) control-port methods
authorBrian Warner <warner@lothar.com>
Tue, 21 Apr 2015 20:04:47 +0000 (13:04 -0700)
committerBrian Warner <warner@lothar.com>
Tue, 21 Apr 2015 20:05:58 +0000 (13:05 -0700)
src/allmydata/control.py
src/allmydata/interfaces.py
src/allmydata/test/check_memory.py

index c29d5572fd6d3dd39f7aae9f7855f8fc32616978..a78daf62fe3f391f7c31d4ba2e00b73ebd8376a0 100644 (file)
@@ -1,5 +1,5 @@
 
-import os, time
+import os, time, tempfile
 from zope.interface import implements
 from twisted.application import service
 from twisted.internet import defer
@@ -60,6 +60,40 @@ class ControlServer(Referenceable, service.Service):
     def remote_wait_for_client_connections(self, num_clients):
         return self.parent.debug_wait_for_client_connections(num_clients)
 
+    def remote_upload_random_data_from_file(self, size, convergence):
+        filename = tempfile.NamedTemporaryFile(delete=False).name
+        f = open(filename, "wb")
+        block = "a" * 8192
+        while size > 0:
+            l = min(size, 8192)
+            f.write(block[:l])
+            size -= l
+        f.close()
+        uploader = self.parent.getServiceNamed("uploader")
+        u = upload.FileName(filename, convergence=convergence)
+        d = uploader.upload(u)
+        d.addCallback(lambda results: results.get_uri())
+        def _done(uri):
+            os.remove(filename)
+            return uri
+        d.addCallback(_done)
+        return d
+
+    def remote_download_to_tempfile_and_delete(self, uri):
+        tempdir = tempfile.mkdtemp()
+        filename = os.path.join(tempdir, "data")
+        filenode = self.parent.create_node_from_uri(uri, name=filename)
+        if not IFileNode.providedBy(filenode):
+            raise AssertionError("The URI does not reference a file.")
+        c = FileWritingConsumer(filename)
+        d = filenode.read(c)
+        def _done(res):
+            os.remove(filename)
+            os.rmdir(tempdir)
+            return None
+        d.addCallback(_done)
+        return d
+
     def remote_speed_test(self, count, size, mutable):
         assert size > 8
         log.msg("speed_test: count=%d, size=%d, mutable=%s" % (count, size,
index d0f5b187c1a9b3ab2010a4916e9b8662551c2fa6..4ec5a0e6ce5deef32c00c0bae1dc7f394f0297d9 100644 (file)
@@ -2631,6 +2631,12 @@ class RIControlClient(RemoteInterface):
 
     # debug stuff
 
+    def upload_random_data_from_file(size=int, convergence=str):
+        return str
+
+    def download_to_tempfile_and_delete(uri=str):
+        return None
+
     def get_memory_usage():
         """Return a dict describes the amount of memory currently in use. The
         keys are 'VmPeak', 'VmSize', and 'VmData'. The values are integers,
index 8ee18c73f68f1013376a45f93413921baf22900e..1b727017ffa9420c9f89c41db2e9fce82f617c80 100644 (file)
@@ -378,15 +378,9 @@ this file are ignored.
         print
         print "uploading %s" % name
         if self.mode in ("upload", "upload-self"):
-            files[name] = self.create_data(name, size)
-            d = self.control_rref.callRemote("upload_from_file_to_uri",
-                                             files[name].encode("utf-8"),
+            d = self.control_rref.callRemote("upload_random_data_from_file",
+                                             size,
                                              convergence="check-memory")
-            def _done(uri):
-                os.remove(files[name])
-                del files[name]
-                return uri
-            d.addCallback(_done)
         elif self.mode == "upload-POST":
             data = "a" * size
             url = "/uri"
@@ -425,8 +419,8 @@ this file are ignored.
         uri = uris[name]
 
         if self.mode == "download":
-            d = self.control_rref.callRemote("download_from_uri_to_file",
-                                             uri, "dummy.out")
+            d = self.control_rref.callRemote("download_to_tempfile_and_delete",
+                                             uri)
         elif self.mode == "download-GET":
             url = "/uri/%s" % uri
             d = self.GET_discard(urllib.quote(url), stall=False)