From: Brian Warner Date: Tue, 21 Apr 2015 20:04:47 +0000 (-0700) Subject: fix check-memory test, with new new (safe) control-port methods X-Git-Tag: allmydata-tahoe-1.10.1a1~35 X-Git-Url: https://git.rkrishnan.org/components/com_hotproperty/css/flags?a=commitdiff_plain;h=f0e783e20e356a1255ec43b8d97fde60315c31ce;p=tahoe-lafs%2Ftahoe-lafs.git fix check-memory test, with new new (safe) control-port methods --- diff --git a/src/allmydata/control.py b/src/allmydata/control.py index c29d5572..a78daf62 100644 --- a/src/allmydata/control.py +++ b/src/allmydata/control.py @@ -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, diff --git a/src/allmydata/interfaces.py b/src/allmydata/interfaces.py index d0f5b187..4ec5a0e6 100644 --- a/src/allmydata/interfaces.py +++ b/src/allmydata/interfaces.py @@ -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, diff --git a/src/allmydata/test/check_memory.py b/src/allmydata/test/check_memory.py index 8ee18c73..1b727017 100644 --- a/src/allmydata/test/check_memory.py +++ b/src/allmydata/test/check_memory.py @@ -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)